diff --git a/pkg/framework/operators/baseoperator.go b/pkg/framework/operators/baseoperator.go index f6ea485..17a3d41 100644 --- a/pkg/framework/operators/baseoperator.go +++ b/pkg/framework/operators/baseoperator.go @@ -35,6 +35,7 @@ type BaseOperatorBuilder struct { customCommand string finalized bool crdsPrepared bool + envVariables map[string]string } type BaseOperator struct { @@ -62,6 +63,7 @@ type BaseOperator struct { crds []apiextv1b1.CustomResourceDefinition keepCRD bool crdsPrepared bool + envVariables map[string]string } type DefinitionStruct struct { @@ -77,6 +79,11 @@ func (b *BaseOperatorBuilder) NewBuilder(restConfig *rest.Config, rawConfig *cli return b } +func (b *BaseOperatorBuilder) AddEnvVariable(name string, value string) OperatorSetupBuilder { + b.envVariables[name] = value + return b +} + func (b *BaseOperatorBuilder) WithNamespace(namespace string) OperatorSetupBuilder { if !b.finalized { b.namespace = namespace @@ -202,12 +209,15 @@ func (b *BaseOperatorBuilder) Build() (OperatorSetup, error) { baseOperator.keepCRD = b.keepCdrs baseOperator.customCommand = b.customCommand baseOperator.crdsPrepared = b.crdsPrepared + baseOperator.envVariables = b.envVariables if err := baseOperator.Setup(); err != nil { return nil, fmt.Errorf("failed to set up operator %s: %v", baseOperator.operatorName, err) } return baseOperator, nil } + + func (b *BaseOperator) InitFromBaseOperatorBuilder(builder *BaseOperatorBuilder) error { b.restConfig = builder.restConfig b.image = builder.image @@ -418,11 +428,24 @@ func (b *BaseOperator) setupDeployment(jsonItem []byte) { if b.customCommand != "" { b.deploymentConfig.Spec.Template.Spec.Containers[0].Command = []string{b.customCommand} } + if len(b.envVariables)>0 { + for name, value := range b.envVariables { + envVar := corev1.EnvVar{name, value,nil} + b.deploymentConfig. + Spec. + Template. + Spec. + Containers[0]. + Env = append(b.deploymentConfig.Spec.Template.Spec.Containers[0].Env, envVar) + } + } + if _, err := b.kubeClient.AppsV1().Deployments(b.namespace).Create(&b.deploymentConfig); err != nil { b.errorItemCreate("deployment", err) } } + func (b *BaseOperator) Namespace() string { return b.namespace } @@ -511,3 +534,4 @@ func (b *BaseOperator) TeardownSuite() error { return nil } } + diff --git a/pkg/framework/operators/operator.go b/pkg/framework/operators/operator.go index 47f8f38..ff38140 100644 --- a/pkg/framework/operators/operator.go +++ b/pkg/framework/operators/operator.go @@ -18,6 +18,7 @@ type OperatorSetupBuilder interface { SetOperatorName(operatorName string) OperatorSetupBuilder WithApiVersion(apiVersion string) OperatorSetupBuilder WithYamls(yamls [][]byte) OperatorSetupBuilder + AddEnvVariable(name string, value string) OperatorSetupBuilder Build() (OperatorSetup, error) OperatorType() OperatorType }