Fix lint issues and CheckSecretExists function

This commit is contained in:
Volodymyr Zotov
2025-08-21 10:38:19 -05:00
parent 7187f41ef1
commit 2003d13788
5 changed files with 41 additions and 27 deletions

View File

@@ -2,7 +2,6 @@ package e2e
import (
"path/filepath"
"time"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
@@ -15,8 +14,6 @@ import (
const (
operatorImageName = "1password/onepassword-operator:latest"
defaultInterval = 1 * time.Second
defaultTimeout = 1 * time.Minute
)
var _ = Describe("Onepassword Operator e2e", Ordered, func() {
@@ -30,25 +27,19 @@ var _ = Describe("Onepassword Operator e2e", Ordered, func() {
kube.CreateOpCredentialsSecret()
By("Checking Connect 'op-credentials' secret is created")
Eventually(func() {
kube.CheckSecretExists("op-credentials")
}, defaultTimeout, defaultInterval).Should(Succeed())
kube.CheckSecretExists("op-credentials")
By("Create 'onepassword-token' secret")
kube.CreateSecretFromEnvVar("OP_CONNECT_TOKEN", "onepassword-token")
By("Checking 'onepassword-token' secret is created")
Eventually(func() {
kube.CheckSecretExists("onepassword-token")
}, defaultTimeout, defaultInterval).Should(Succeed())
kube.CheckSecretExists("onepassword-token")
By("Create 'onepassword-service-account-token' secret")
kube.CreateSecretFromEnvVar("OP_SERVICE_ACCOUNT_TOKEN", "onepassword-service-account-token")
By("Checking 'onepassword-service-account-token' secret is created")
Eventually(func() {
kube.CheckSecretExists("onepassword-service-account-token")
}, defaultTimeout, defaultInterval).Should(Succeed())
kube.CheckSecretExists("onepassword-service-account-token")
operator.DeployOperator()
operator.WaitingForOperatorPod()
@@ -81,9 +72,7 @@ func runCommonTestCases() {
yamlPath := filepath.Join(root, "test", "e2e", "manifests", "secret.yaml")
kube.Apply(yamlPath)
By("Waiting for secret to be created")
Eventually(func() {
kube.CheckSecretExists("login")
}, defaultTimeout, defaultInterval).Should(Succeed())
By("Checking for secret to be created")
kube.CheckSecretExists("login")
})
}

View File

@@ -0,0 +1,8 @@
package defaults
import "time"
const (
E2EInterval = 1 * time.Second
E2ETimeout = 1 * time.Minute
)

View File

@@ -3,7 +3,9 @@ package kind
import (
"os"
//nolint:staticcheck // ST1001
. "github.com/onsi/ginkgo/v2"
//nolint:staticcheck // ST1001
. "github.com/onsi/gomega"
"github.com/1Password/onepassword-operator/test/testhelper/system"

View File

@@ -6,9 +6,12 @@ import (
"path/filepath"
"time"
//nolint:staticcheck // ST1001
. "github.com/onsi/ginkgo/v2"
//nolint:staticcheck // ST1001
. "github.com/onsi/gomega"
"github.com/1Password/onepassword-operator/test/testhelper/defaults"
"github.com/1Password/onepassword-operator/test/testhelper/system"
)
@@ -49,9 +52,11 @@ func DeleteSecret(name string) {
}
func CheckSecretExists(name string) {
output, err := system.Run("kubectl", "get", "secret", name, "-o", "jsonpath={.metadata.name}")
Expect(err).NotTo(HaveOccurred())
Expect(output).To(Equal(name))
Eventually(func(g Gomega) {
output, err := system.Run("kubectl", "get", "secret", name, "-o", "jsonpath={.metadata.name}")
g.Expect(err).NotTo(HaveOccurred())
g.Expect(output).To(Equal(name))
}, defaults.E2ETimeout, defaults.E2EInterval).Should(Succeed())
}
func Apply(yamlPath string) {
@@ -72,14 +77,22 @@ var PatchOperatorToUseServiceAccount = WithOperatorRestart(func() {
"kubectl", "patch", "deployment", "onepassword-connect-operator",
"--type=json",
`-p=[{"op":"replace","path":"/spec/template/spec/containers/0/env","value":[
{"name":"OPERATOR_NAME","value":"onepassword-connect-operator"},
{"name":"POD_NAME","valueFrom":{"fieldRef":{"fieldPath":"metadata.name"}}},
{"name":"WATCH_NAMESPACE","value":"default"},
{"name":"POLLING_INTERVAL","value":"10"},
{"name":"AUTO_RESTART","value":"false"},
{"name":"OP_SERVICE_ACCOUNT_TOKEN","valueFrom":{"secretKeyRef":{"name":"onepassword-service-account-token","key":"token"}}},
{"name":"MANAGE_CONNECT","value":"false"}
]}]`,
{"name":"OPERATOR_NAME","value":"onepassword-connect-operator"},
{"name":"POD_NAME","valueFrom":{"fieldRef":{"fieldPath":"metadata.name"}}},
{"name":"WATCH_NAMESPACE","value":"default"},
{"name":"POLLING_INTERVAL","value":"10"},
{"name":"AUTO_RESTART","value":"false"},
{
"name":"OP_SERVICE_ACCOUNT_TOKEN",
"valueFrom":{
"secretKeyRef":{
"name":"onepassword-service-account-token",
"key":"token",
},
},
},
{"name":"MANAGE_CONNECT","value":"false"}
]}]`,
)
Expect(err).NotTo(HaveOccurred())
})

View File

@@ -3,7 +3,9 @@ package operator
import (
"time"
//nolint:staticcheck // ST1001
. "github.com/onsi/ginkgo/v2"
//nolint:staticcheck // ST1001
. "github.com/onsi/gomega"
"github.com/1Password/onepassword-operator/test/testhelper/system"