Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(k8s): add support for ImagePullSecret in NFS Server Pods #114

Merged
merged 2 commits into from
Sep 22, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions deploy/helm/charts/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ spec:
- name: OPENEBS_IO_NFS_SERVER_NS
value: {{ .Values.nfsProvisioner.nfsServerNamespace }}
{{- end }}
{{- if .Values.nfsServer.imagePullSecret }}
g-linville marked this conversation as resolved.
Show resolved Hide resolved
- name: OPENEBS_IO_NFS_SERVER_IMAGE_PULL_SECRET
value: {{ .Values.nfsServer.imagePullSecret }}
{{- end }}
# OPENEBS_IO_NFS_SERVER_NODE_AFFINITY defines the node affinity rules to place NFS Server
# instance. It accepts affinity rules in multiple ways:
# - If NFS Server needs to be placed on storage nodes as well as only in
Expand Down
1 change: 1 addition & 0 deletions deploy/helm/charts/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ nfsStorageClass:

nfsServer:
useClusterIP: "true"
imagePullSecret: ""

analytics:
enabled: "true"
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