mirror of
https://github.com/1Password/onepassword-operator.git
synced 2025-10-22 07:28:06 +00:00
Add e2e tests using Service Accounts
This commit is contained in:
29
test/cmd/cmd.go
Normal file
29
test/cmd/cmd.go
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Run executes the provided command within this context
|
||||||
|
func Run(name string, args ...string) (string, error) {
|
||||||
|
cmd := exec.Command(name, args...)
|
||||||
|
|
||||||
|
wd, err := os.Getwd()
|
||||||
|
if err != nil {
|
||||||
|
return wd, err
|
||||||
|
}
|
||||||
|
wd = strings.Replace(wd, "/test/e2e", "", -1)
|
||||||
|
// Command will run from project root
|
||||||
|
cmd.Dir = wd
|
||||||
|
|
||||||
|
command := strings.Join(cmd.Args, " ")
|
||||||
|
output, err := cmd.CombinedOutput()
|
||||||
|
if err != nil {
|
||||||
|
return string(output), fmt.Errorf("%s failed with error: (%v) %s", command, err, string(output))
|
||||||
|
}
|
||||||
|
|
||||||
|
return string(output), nil
|
||||||
|
}
|
@@ -1 +1,67 @@
|
|||||||
package e2e
|
package e2e
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
. "github.com/onsi/ginkgo/v2"
|
||||||
|
. "github.com/onsi/gomega"
|
||||||
|
|
||||||
|
"github.com/1Password/onepassword-operator/test/cmd"
|
||||||
|
"github.com/1Password/onepassword-operator/test/kind"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
operatorImage = "1password/onepassword-operator:latest"
|
||||||
|
e2eInterval = 500 * time.Millisecond
|
||||||
|
)
|
||||||
|
|
||||||
|
var _ = Describe("Onepassword Operator e2e", Ordered, func() {
|
||||||
|
BeforeAll(func() {
|
||||||
|
By("building the operator image")
|
||||||
|
_, err := cmd.Run("make", "docker-build")
|
||||||
|
ExpectWithOffset(1, err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
|
By("loading the operator image on Kind")
|
||||||
|
err = kind.LoadImageToKind(operatorImage)
|
||||||
|
ExpectWithOffset(1, err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
|
By("create onepassword-service-account-token secret")
|
||||||
|
serviceAccountTokenToken, _ := os.LookupEnv("OP_SERVICE_ACCOUNT_TOKEN")
|
||||||
|
Expect(serviceAccountTokenToken).NotTo(BeEmpty())
|
||||||
|
_, err = cmd.Run("kubectl", "create", "secret", "generic", "onepassword-service-account-token", "--from-literal=token="+serviceAccountTokenToken)
|
||||||
|
ExpectWithOffset(1, err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
|
By("deploying the operator")
|
||||||
|
_, err = cmd.Run("make", "deploy")
|
||||||
|
ExpectWithOffset(1, err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
|
By("waiting for the operator pod to be 'Running'")
|
||||||
|
Eventually(func(g Gomega) {
|
||||||
|
output, err := cmd.Run("kubectl", "get", "pods",
|
||||||
|
"-l", "name=onepassword-connect-operator",
|
||||||
|
"-o", "jsonpath={.items[0].status.phase}")
|
||||||
|
g.Expect(err).NotTo(HaveOccurred())
|
||||||
|
g.Expect(output).To(ContainSubstring("Running"))
|
||||||
|
}, 30*time.Second, 1*time.Second).Should(Succeed())
|
||||||
|
})
|
||||||
|
|
||||||
|
Describe("Deployment annotations", func() {
|
||||||
|
It("Should create secret from manifest file", func() {
|
||||||
|
By("creating secret")
|
||||||
|
wd, err := os.Getwd()
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
yamlPath := filepath.Join(wd, "manifests", "secret.yaml")
|
||||||
|
_, err = cmd.Run("kubectl", "apply", "-f", yamlPath)
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
|
By("waiting for secret to be created")
|
||||||
|
Eventually(func(g Gomega) {
|
||||||
|
output, err := cmd.Run("kubectl", "get", "secret", "login", "-o", "jsonpath={.metadata.name}")
|
||||||
|
g.Expect(err).NotTo(HaveOccurred())
|
||||||
|
g.Expect(output).To(Equal("login"))
|
||||||
|
}, 5*time.Second, e2eInterval).Should(Succeed())
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
6
test/e2e/manifests/secret.yaml
Normal file
6
test/e2e/manifests/secret.yaml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
apiVersion: onepassword.com/v1
|
||||||
|
kind: OnePasswordItem
|
||||||
|
metadata:
|
||||||
|
name: login
|
||||||
|
spec:
|
||||||
|
itemPath: "vaults/h4l46uopmjps2cgmpeysnvscum/items/sg2gfcren47mzbx2bcgumc7ekm"
|
16
test/kind/kind.go
Normal file
16
test/kind/kind.go
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
package kind
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/1Password/onepassword-operator/test/cmd"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
// LoadImageToKind loads a local docker image to the Kind cluster
|
||||||
|
func LoadImageToKind(imageName string) error {
|
||||||
|
clusterName := "kind"
|
||||||
|
if value, ok := os.LookupEnv("KIND_CLUSTER"); ok {
|
||||||
|
clusterName = value
|
||||||
|
}
|
||||||
|
_, err := cmd.Run("kind", "load", "docker-image", imageName, "--name", clusterName)
|
||||||
|
return err
|
||||||
|
}
|
Reference in New Issue
Block a user