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

[Feature][Add] Added imagePullsecrets support #38

Merged
merged 1 commit into from
Feb 15, 2022
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
2 changes: 1 addition & 1 deletion .azure-pipelines/pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ extends:
QuayImageName: opstree/mongodb-operator
GithubImageName: ot-container-kit/mongodb-operator/mongodb-operator
BuildDocs: false
AppVersion: "0.1.0"
AppVersion: "0.2.0"
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the manager binary
FROM golang:1.16 as builder
FROM golang:1.17 as builder

WORKDIR /workspace
# Copy the Go Modules manifests
Expand Down
8 changes: 4 additions & 4 deletions api/v1alpha1/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (

// KubernetesConfig will be the JSON struct for Basic MongoDB Config
type KubernetesConfig struct {
Image string `json:"image"`
ImagePullPolicy corev1.PullPolicy `json:"imagePullPolicy,omitempty"`
Resources *corev1.ResourceRequirements `json:"resources,omitempty"`
ImagePullSecrets *[]corev1.LocalObjectReference `json:"imagePullSecrets,omitempty"`
Image string `json:"image"`
ImagePullPolicy corev1.PullPolicy `json:"imagePullPolicy,omitempty"`
Resources *corev1.ResourceRequirements `json:"resources,omitempty"`
ImagePullSecret *string `json:"imagePullSecret,omitempty"`
}

// MongoDBSecurity is the JSON struct for MongoDB security configuration
Expand Down
27 changes: 4 additions & 23 deletions config/crd/bases/opstreelabs.in_mongodbclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,8 @@ spec:
description: PullPolicy describes a policy for if/when to pull
a container image
type: string
imagePullSecrets:
items:
description: LocalObjectReference contains enough information
to let you locate the referenced object inside the same namespace.
properties:
name:
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
TODO: Add other useful fields. apiVersion, kind, uid?'
type: string
type: object
type: array
imagePullSecret:
type: string
resources:
description: ResourceRequirements describes the compute resource
requirements.
Expand Down Expand Up @@ -191,18 +182,8 @@ spec:
description: PullPolicy describes a policy for if/when to
pull a container image
type: string
imagePullSecrets:
items:
description: LocalObjectReference contains enough information
to let you locate the referenced object inside the same
namespace.
properties:
name:
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
TODO: Add other useful fields. apiVersion, kind, uid?'
type: string
type: object
type: array
imagePullSecret:
type: string
resources:
description: ResourceRequirements describes the compute resource
requirements.
Expand Down
27 changes: 4 additions & 23 deletions config/crd/bases/opstreelabs.in_mongodbs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,8 @@ spec:
description: PullPolicy describes a policy for if/when to pull
a container image
type: string
imagePullSecrets:
items:
description: LocalObjectReference contains enough information
to let you locate the referenced object inside the same namespace.
properties:
name:
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
TODO: Add other useful fields. apiVersion, kind, uid?'
type: string
type: object
type: array
imagePullSecret:
type: string
resources:
description: ResourceRequirements describes the compute resource
requirements.
Expand Down Expand Up @@ -180,18 +171,8 @@ spec:
description: PullPolicy describes a policy for if/when to
pull a container image
type: string
imagePullSecrets:
items:
description: LocalObjectReference contains enough information
to let you locate the referenced object inside the same
namespace.
properties:
name:
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
TODO: Add other useful fields. apiVersion, kind, uid?'
type: string
type: object
type: array
imagePullSecret:
type: string
resources:
description: ResourceRequirements describes the compute resource
requirements.
Expand Down
20 changes: 20 additions & 0 deletions examples/private_registry/clusterd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
apiVersion: opstreelabs.in/v1alpha1
kind: MongoDBCluster
metadata:
name: mongodb
spec:
clusterSize: 3
kubernetesConfig:
image: quay.io/opstree/mongo:v5.0
imagePullPolicy: IfNotPresent
imagePullSecret: regcred
storage:
accessModes: ["ReadWriteOnce"]
storageSize: 1Gi
storageClass: csi-cephfs-sc
mongoDBSecurity:
mongoDBAdminUser: admin
secretRef:
name: mongodb-secret
key: password
19 changes: 19 additions & 0 deletions examples/private_registry/standalone.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
apiVersion: opstreelabs.in/v1alpha1
kind: MongoDB
metadata:
name: mongodb
spec:
kubernetesConfig:
image: quay.io/opstree/mongo:v5.0
imagePullPolicy: IfNotPresent
imagePullSecret: regcred
storage:
accessModes: ["ReadWriteOnce"]
storageSize: 1Gi
storageClass: csi-cephfs-sc
mongoDBSecurity:
mongoDBAdminUser: admin
secretRef:
name: mongodb-secret
key: password
4 changes: 4 additions & 0 deletions k8sgo/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ func getMongoDBClusterParams(cr *opstreelabsinv1alpha1.MongoDBCluster) statefulS
Annotations: generateAnnotations(),
}

if cr.Spec.KubernetesConfig.ImagePullSecret != nil {
params.ImagePullSecret = cr.Spec.KubernetesConfig.ImagePullSecret
}

if cr.Spec.MongoDBSecurity != nil {
params.ContainerParams.MongoDBUser = &cr.Spec.MongoDBSecurity.MongoDBAdminUser
params.ContainerParams.SecretName = cr.Spec.MongoDBSecurity.SecretRef.Name
Expand Down
3 changes: 3 additions & 0 deletions k8sgo/standalone.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ func getMongoDBStandaloneParams(cr *opstreelabsinv1alpha1.MongoDB) statefulSetPa
Annotations: generateAnnotations(),
}

if cr.Spec.KubernetesConfig.ImagePullSecret != nil {
params.ImagePullSecret = cr.Spec.KubernetesConfig.ImagePullSecret
}
if cr.Spec.MongoDBSecurity != nil {
params.ContainerParams.MongoDBUser = &cr.Spec.MongoDBSecurity.MongoDBAdminUser
params.ContainerParams.SecretName = cr.Spec.MongoDBSecurity.SecretRef.Name
Expand Down
5 changes: 5 additions & 0 deletions k8sgo/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type statefulSetParameters struct {
Replicas *int32
PVCParameters pvcParameters
ExtraVolumes *[]corev1.Volume
ImagePullSecret *string
}

// pvcParameters is the structure for MongoDB PVC
Expand Down Expand Up @@ -149,6 +150,9 @@ func generateStatefulSetDef(params statefulSetParameters) *appsv1.StatefulSet {
if params.ExtraVolumes != nil {
statefulset.Spec.Template.Spec.Volumes = *params.ExtraVolumes
}
if params.ImagePullSecret != nil {
statefulset.Spec.Template.Spec.ImagePullSecrets = []corev1.LocalObjectReference{{Name: *params.ImagePullSecret}}
}
AddOwnerRefToObject(statefulset, params.OwnerDef)
return statefulset
}
Expand All @@ -165,6 +169,7 @@ func generatePersistentVolumeTemplate(params pvcParameters) corev1.PersistentVol
corev1.ResourceName(corev1.ResourceStorage): resource.MustParse(params.StorageSize),
},
},
StorageClassName: params.StorageClassName,
},
}
}
Expand Down