Provide default inerval and timeout via config

This commit is contained in:
Volodymyr Zotov
2025-08-26 16:31:07 -05:00
parent 24edff22d4
commit 0c3caf88b6
5 changed files with 22 additions and 17 deletions

View File

@@ -12,13 +12,11 @@ import (
appsv1 "k8s.io/api/apps/v1" appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1" corev1 "k8s.io/api/core/v1"
"sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client"
"github.com/1Password/onepassword-operator/pkg/testhelper/defaults"
) )
type Deployment struct { type Deployment struct {
client client.Client client client.Client
config *ClusterConfig config *Config
name string name string
} }
@@ -128,5 +126,5 @@ func (d *Deployment) WaitDeploymentRolledOut(ctx context.Context) {
g.Expect(newDeployment.Status.Replicas).To(Equal(desired)) g.Expect(newDeployment.Status.Replicas).To(Equal(desired))
return nil return nil
}, defaults.E2ETimeout, defaults.E2EInterval).Should(Succeed()) }, d.config.TestConfig.Timeout, d.config.TestConfig.Interval).Should(Succeed())
} }

View File

@@ -23,17 +23,23 @@ import (
apiv1 "github.com/1Password/onepassword-operator/api/v1" apiv1 "github.com/1Password/onepassword-operator/api/v1"
) )
type ClusterConfig struct { type TestConfig struct {
Timeout time.Duration
Interval time.Duration
}
type Config struct {
Namespace string Namespace string
ManifestsDir string ManifestsDir string
TestConfig *TestConfig
} }
type Kube struct { type Kube struct {
Config *ClusterConfig Config *Config
Client client.Client Client client.Client
} }
func NewKubeClient(clusterConfig *ClusterConfig) *Kube { func NewKubeClient(config *Config) *Kube {
By("Creating a kubernetes client") By("Creating a kubernetes client")
kubeconfig := os.Getenv("KUBECONFIG") kubeconfig := os.Getenv("KUBECONFIG")
if kubeconfig == "" { if kubeconfig == "" {
@@ -62,12 +68,12 @@ func NewKubeClient(clusterConfig *ClusterConfig) *Kube {
ctx, ok := cfg.Contexts[currentContext] ctx, ok := cfg.Contexts[currentContext]
Expect(ok).To(BeTrue(), fmt.Sprintf("current context %q not found in kubeconfig", currentContext)) Expect(ok).To(BeTrue(), fmt.Sprintf("current context %q not found in kubeconfig", currentContext))
ctx.Namespace = clusterConfig.Namespace ctx.Namespace = config.Namespace
err = clientcmd.ModifyConfig(pathOpts, *cfg, true) err = clientcmd.ModifyConfig(pathOpts, *cfg, true)
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
return &Kube{ return &Kube{
Config: clusterConfig, Config: config,
Client: kubernetesClient, Client: kubernetesClient,
} }
} }

View File

@@ -11,13 +11,11 @@ import (
corev1 "k8s.io/api/core/v1" corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/labels"
"sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client"
"github.com/1Password/onepassword-operator/pkg/testhelper/defaults"
) )
type Pod struct { type Pod struct {
client client.Client client client.Client
config *ClusterConfig config *Config
selector map[string]string selector map[string]string
} }
@@ -45,5 +43,5 @@ func (p *Pod) WaitingForRunningPod(ctx context.Context) {
} }
} }
g.Expect(foundRunning).To(BeTrue(), "pod not Running yet") g.Expect(foundRunning).To(BeTrue(), "pod not Running yet")
}, defaults.E2ETimeout, defaults.E2EInterval).Should(Succeed()) }, p.config.TestConfig.Timeout, p.config.TestConfig.Interval).Should(Succeed())
} }

View File

@@ -15,13 +15,12 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client"
"github.com/1Password/onepassword-operator/pkg/testhelper/defaults"
"github.com/1Password/onepassword-operator/pkg/testhelper/system" "github.com/1Password/onepassword-operator/pkg/testhelper/system"
) )
type Secret struct { type Secret struct {
client client.Client client client.Client
config *ClusterConfig config *Config
name string name string
} }
@@ -138,5 +137,5 @@ func (s *Secret) CheckIfExists(ctx context.Context) {
secret := &corev1.Secret{} secret := &corev1.Secret{}
err := s.client.Get(attemptCtx, client.ObjectKey{Name: s.name, Namespace: s.config.Namespace}, secret) err := s.client.Get(attemptCtx, client.ObjectKey{Name: s.name, Namespace: s.config.Namespace}, secret)
g.Expect(err).NotTo(HaveOccurred()) g.Expect(err).NotTo(HaveOccurred())
}, defaults.E2ETimeout, defaults.E2EInterval).Should(Succeed()) }, s.config.TestConfig.Timeout, s.config.TestConfig.Interval).Should(Succeed())
} }

View File

@@ -30,9 +30,13 @@ var _ = Describe("Onepassword Operator e2e", Ordered, func() {
ctx := context.Background() ctx := context.Background()
BeforeAll(func() { BeforeAll(func() {
kubeClient = kube.NewKubeClient(&kube.ClusterConfig{ kubeClient = kube.NewKubeClient(&kube.Config{
Namespace: "default", Namespace: "default",
ManifestsDir: filepath.Join("manifests"), ManifestsDir: filepath.Join("manifests"),
TestConfig: &kube.TestConfig{
Timeout: defaults.E2ETimeout,
Interval: defaults.E2EInterval,
},
}) })
operator.BuildOperatorImage() operator.BuildOperatorImage()