Skip to content
Merged
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
14 changes: 14 additions & 0 deletions pkg/kubernetes/api/core/v1/podtemplatespec/podtemplatespec.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,20 @@ func (b *Builder) WithServiceAccountName(serviceAccountnNme string) *Builder {
return b
}

// WithImagePullSecret adds a new secret to the ImagePullSecrets field of podtemplatespec
func (b *Builder) WithImagePullSecret(imagePullSecretName string) *Builder {
if len(imagePullSecretName) != 0 {
b.podtemplatespec.Object.Spec.ImagePullSecrets = append(
b.podtemplatespec.Object.Spec.ImagePullSecrets,
corev1.LocalObjectReference{
Name: imagePullSecretName,
},
)
}

return b
}

// WithAffinity sets the affinity field of podtemplatespec
func (b *Builder) WithAffinity(affinity *corev1.Affinity) *Builder {
if affinity == nil {
Expand Down
35 changes: 35 additions & 0 deletions pkg/kubernetes/api/core/v1/podtemplatespec/podtemplatespec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,3 +419,38 @@ func TestBuilderWithTolerationsNew(t *testing.T) {
})
}
}

func TestBuildWithImagePullSecret(t *testing.T) {
tests := map[string]struct {
imagePullSecret string
builder *Builder
expectErr bool
}{
"Test Builder with image pull secret": {
imagePullSecret: "mysecret",
builder: &Builder{podtemplatespec: &PodTemplateSpec{
Object: &corev1.PodTemplateSpec{},
}},
expectErr: false,
},
"Test Builder without image pull secret": {
imagePullSecret: "",
builder: &Builder{podtemplatespec: &PodTemplateSpec{
Object: &corev1.PodTemplateSpec{},
}},
expectErr: false,
},
}
for name, mock := range tests {
name, mock := name, mock
t.Run(name, func(t *testing.T) {
b := mock.builder.WithImagePullSecret(mock.imagePullSecret)
if mock.expectErr && len(b.errs) == 0 {
t.Fatalf("Test %q failed: expected error not to be nil", name)
}
if !mock.expectErr && len(b.errs) > 0 {
t.Fatalf("Test %q failed: expected error to be nil", name)
}
})
}
}
7 changes: 7 additions & 0 deletions provisioner/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ const (

// NFSBackendPvcTimeout defines env name to store BackendPvcBoundTimeout value
NFSBackendPvcTimeout menv.ENVKey = "OPENEBS_IO_NFS_SERVER_BACKEND_PVC_TIMEOUT"

// NFSServerImagePullSecret defines the env name to store the name of the image pull secret
NFSServerImagePullSecret menv.ENVKey = "OPENEBS_IO_NFS_SERVER_IMAGE_PULL_SECRET"
)

var (
Expand Down Expand Up @@ -101,3 +104,7 @@ func getNfsServerNodeAffinity() string {
func getBackendPvcTimeout() string {
return menv.Get(NFSBackendPvcTimeout)
}

func getNfsServerImagePullSecret() string {
return menv.GetOrDefault(NFSServerImagePullSecret, "")
}
1 change: 1 addition & 0 deletions provisioner/helper_kernel_nfs_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ func (p *Provisioner) createDeployment(nfsServerOpts *KernelNFSServerOptions) er
FSGroup: nfsServerOpts.fsGroup,
}).
WithNodeAffinityMatchExpressions(p.nodeAffinity.MatchExpressions).
WithImagePullSecret(getNfsServerImagePullSecret()).
WithContainerBuildersNew(
container.NewBuilder().
WithName("nfs-server").
Expand Down