mirror of
https://github.com/1Password/onepassword-operator.git
synced 2025-10-21 23:18:06 +00:00
Move cmd
package to testhelper
and rename to be system
This commit is contained in:
@@ -8,10 +8,10 @@ import (
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
|
||||
"github.com/1Password/onepassword-operator/test/cmd"
|
||||
"github.com/1Password/onepassword-operator/test/testhelper/kind"
|
||||
"github.com/1Password/onepassword-operator/test/testhelper/kube"
|
||||
"github.com/1Password/onepassword-operator/test/testhelper/operator"
|
||||
"github.com/1Password/onepassword-operator/test/testhelper/system"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -61,12 +61,12 @@ func runCommonTestCases() {
|
||||
wd, err := os.Getwd()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
yamlPath := filepath.Join(wd, "manifests", "secret.yaml")
|
||||
_, err = cmd.Run("kubectl", "apply", "-f", yamlPath)
|
||||
_, err = system.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}")
|
||||
output, err := system.Run("kubectl", "get", "secret", "login", "-o", "jsonpath={.metadata.name}")
|
||||
g.Expect(err).NotTo(HaveOccurred())
|
||||
g.Expect(output).To(Equal("login"))
|
||||
}, defaultTimeout, defaultInterval).Should(Succeed())
|
||||
|
@@ -6,7 +6,7 @@ import (
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
|
||||
"github.com/1Password/onepassword-operator/test/cmd"
|
||||
"github.com/1Password/onepassword-operator/test/testhelper/system"
|
||||
)
|
||||
|
||||
// LoadImageToKind loads a local docker image to the Kind cluster
|
||||
@@ -16,6 +16,6 @@ func LoadImageToKind(imageName string) {
|
||||
if value, ok := os.LookupEnv("KIND_CLUSTER"); ok {
|
||||
clusterName = value
|
||||
}
|
||||
_, err := cmd.Run("kind", "load", "docker-image", imageName, "--name", clusterName)
|
||||
_, err := system.Run("kind", "load", "docker-image", imageName, "--name", clusterName)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
}
|
||||
|
@@ -9,24 +9,24 @@ import (
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
|
||||
"github.com/1Password/onepassword-operator/test/cmd"
|
||||
"github.com/1Password/onepassword-operator/test/testhelper/system"
|
||||
)
|
||||
|
||||
func CreateSecretFromEnvVar(envVar, secretName string) {
|
||||
value, _ := os.LookupEnv(envVar)
|
||||
Expect(value).NotTo(BeEmpty())
|
||||
|
||||
_, err := cmd.Run("kubectl", "create", "secret", "generic", secretName, "--from-literal=token="+value)
|
||||
_, err := system.Run("kubectl", "create", "secret", "generic", secretName, "--from-literal=token="+value)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
}
|
||||
|
||||
func CreateSecretFromFile(fileName, secretName string) {
|
||||
_, err := cmd.Run("kubectl", "create", "secret", "generic", secretName, "--from-file="+fileName)
|
||||
_, err := system.Run("kubectl", "create", "secret", "generic", secretName, "--from-file="+fileName)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
}
|
||||
|
||||
func CreateOpCredentialsSecret() {
|
||||
rootDir, err := cmd.GetProjectRoot()
|
||||
rootDir, err := system.GetProjectRoot()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
credentialsFilePath := filepath.Join(rootDir, "1password-credentials.json")
|
||||
@@ -44,14 +44,14 @@ func CreateOpCredentialsSecret() {
|
||||
}
|
||||
|
||||
func DeleteSecret(name string) {
|
||||
_, err := cmd.Run("kubectl", "delete", "secret", name, "--ignore-not-found=true")
|
||||
_, err := system.Run("kubectl", "delete", "secret", name, "--ignore-not-found=true")
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
}
|
||||
|
||||
// PatchOperatorToUseServiceAccount sets `OP_SERVICE_ACCOUNT_TOKEN` env variable
|
||||
var PatchOperatorToUseServiceAccount = WithOperatorRestart(func() {
|
||||
By("patching the operator deployment with service account token")
|
||||
_, err := cmd.Run(
|
||||
_, err := system.Run(
|
||||
"kubectl", "patch", "deployment", "onepassword-connect-operator",
|
||||
"--type=json",
|
||||
`-p=[{"op":"replace","path":"/spec/template/spec/containers/0/env","value":[
|
||||
@@ -70,7 +70,7 @@ var PatchOperatorToUseServiceAccount = WithOperatorRestart(func() {
|
||||
// PatchOperatorManageConnect sets env variable `MANAGE_CONNECT: true` and restarts the operator.
|
||||
var PatchOperatorManageConnect = WithOperatorRestart(func() {
|
||||
By("patching the operator deployment with to manage Connect")
|
||||
_, err := cmd.Run(
|
||||
_, err := system.Run(
|
||||
"kubectl", "patch", "deployment", "onepassword-connect-operator",
|
||||
"--type=json",
|
||||
`-p=[{"op":"replace","path":"/spec/template/spec/containers/0/env","value":[
|
||||
@@ -91,13 +91,13 @@ func WithOperatorRestart(operation func()) func() {
|
||||
return func() {
|
||||
operation()
|
||||
|
||||
_, err := cmd.Run("kubectl", "rollout", "status",
|
||||
_, err := system.Run("kubectl", "rollout", "status",
|
||||
"deployment/onepassword-connect-operator", "-n", "default", "--timeout=120s")
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("waiting for the operator pod to be 'Running'")
|
||||
Eventually(func(g Gomega) {
|
||||
output, err := cmd.Run("kubectl", "get", "pods",
|
||||
output, err := system.Run("kubectl", "get", "pods",
|
||||
"-l", "name=onepassword-connect-operator",
|
||||
"-o", "jsonpath={.items[0].status.phase}")
|
||||
g.Expect(err).NotTo(HaveOccurred())
|
||||
|
@@ -6,12 +6,12 @@ import (
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
|
||||
"github.com/1Password/onepassword-operator/test/cmd"
|
||||
"github.com/1Password/onepassword-operator/test/testhelper/system"
|
||||
)
|
||||
|
||||
func BuildOperatorImage() {
|
||||
By("building the operator image")
|
||||
_, err := cmd.Run("make", "docker-build")
|
||||
_, err := system.Run("make", "docker-build")
|
||||
ExpectWithOffset(1, err).NotTo(HaveOccurred())
|
||||
}
|
||||
|
||||
@@ -21,12 +21,12 @@ func BuildOperatorImage() {
|
||||
// To make the operator use Connect or Service Accounts, patch `config/manager/manager.yaml`
|
||||
func DeployOperator() {
|
||||
By("deploying the operator")
|
||||
_, err := cmd.Run("make", "deploy")
|
||||
_, err := system.Run("make", "deploy")
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
By("waiting for the operator pod to be 'Running'")
|
||||
Eventually(func(g Gomega) {
|
||||
output, err := cmd.Run("kubectl", "get", "pods",
|
||||
output, err := system.Run("kubectl", "get", "pods",
|
||||
"-l", "name=onepassword-connect-operator",
|
||||
"-o", "jsonpath={.items[0].status.phase}")
|
||||
g.Expect(err).NotTo(HaveOccurred())
|
||||
|
@@ -1,4 +1,4 @@
|
||||
package cmd
|
||||
package system
|
||||
|
||||
import (
|
||||
"fmt"
|
Reference in New Issue
Block a user