Skip to content

Commit

Permalink
Fix runasuser kgcarr (#255)
Browse files Browse the repository at this point in the history
* Trigger build with new base image

* Bump up version

* Trigger build with new base image

* Update version.go

* Update manager.yaml

* Update ibm-mongodb-operator.clusterserviceversion.yaml

* Update ibm-mongodb-operator.clusterserviceversion.yaml

* Trigger build with new base image

* first test

* code format

* update logic

Co-authored-by: Travis CI User <travis@example.org>
Co-authored-by: Ashwini Palankar <Ashwini.Palankar@ibm.com>
Co-authored-by: ash007-ibm <81858297+ash007-ibm@users.noreply.github.com>
  • Loading branch information
4 people committed Nov 26, 2021
1 parent fc04d52 commit 7861e11
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ spec:
- get
- list
- watch
serviceAccountName: ibm-mongodb-operator
serviceAccountName: ibm-mongodb-operator
deployments:
- name: ibm-mongodb-operator
spec:
Expand Down
16 changes: 16 additions & 0 deletions controllers/mongodb_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ type mongoDBStatefulSetData struct {
StsLabels map[string]string
PodLabels map[string]string
PVCSize string
UserId int
}

// +kubebuilder:rbac:groups=mongodb.operator.ibm.com,namespace=ibm-common-services,resources=mongodbs,verbs=get;list;watch;create;update;patch;delete
Expand Down Expand Up @@ -319,6 +320,20 @@ func (r *MongoDBReconciler) Reconcile(request ctrl.Request) (ctrl.Result, error)
}
}

// Select User to use
cppConfig := &corev1.ConfigMap{}
err = r.Client.Get(context.TODO(), types.NamespacedName{Name: "ibm-cpp-config", Namespace: instance.Namespace}, cppConfig)
if err != nil {
return reconcile.Result{}, err
}

uid := 0
if clusterType, exists := cppConfig.Data["kubernetes_cluster_type"]; exists {
if clusterType != "ocp" {
uid = 1000
}
}

// Check if statefulset already exists
sts := &appsv1.StatefulSet{}
var stsLabels map[string]string
Expand Down Expand Up @@ -389,6 +404,7 @@ func (r *MongoDBReconciler) Reconcile(request ctrl.Request) (ctrl.Result, error)
StsLabels: stsLabels,
PodLabels: podLabels,
PVCSize: PVCSizeRequest,
UserId: uid,
}

var stsYaml bytes.Buffer
Expand Down
4 changes: 3 additions & 1 deletion controllers/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ spec:
clusterhealth.ibm.com/dependencies: {{ .NamespaceName }}.cert-manager
spec:
serviceAccountName: ibm-mongodb-operand
{{ if eq .UserId 1000 }}
securityContext:
runAsUser: 1000
runAsUser: {{ .UserId }}
{{ end }}
terminationGracePeriodSeconds: 30
hostNetwork: false
hostPID: false
Expand Down

1 comment on commit 7861e11

@ash007-ibm
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.