Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions pkg/framework/operators/baseoperator.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type BaseOperatorBuilder struct {
customCommand string
finalized bool
crdsPrepared bool
envVariables map[string]string
}

type BaseOperator struct {
Expand Down Expand Up @@ -62,6 +63,7 @@ type BaseOperator struct {
crds []apiextv1b1.CustomResourceDefinition
keepCRD bool
crdsPrepared bool
envVariables map[string]string
}

type DefinitionStruct struct {
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -511,3 +534,4 @@ func (b *BaseOperator) TeardownSuite() error {
return nil
}
}

1 change: 1 addition & 0 deletions pkg/framework/operators/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down