Skip to content

Commit 70df8a1

Browse files
synaretemergify[bot]
authored andcommitted
resources: reconcile openshift elems by smbshare
When deploying over OpenShift cluster, samba-operator should deploy the SeviceAccount, Role and RoleBinding which link the SmbShare pod to samba-SCC within the namespace of the SmbShare itself (unlike previous code, which deploy them once with the namespace of the operator). In addition, starting of OpenShift 4.12 certain annotations needs to be associated with the namespace on which the SmbShare pod runs in order to elevate its privileges. The patch is a refactoring to the existing code. The creation of the relevant objects is done from within the reconcile loop of the SmbShare itself. It assumes that the user already deployed a well known SCC with the name 'samba' on the cluster. Signed-off-by: Shachar Sharon <[email protected]>
1 parent 5903b74 commit 70df8a1

File tree

6 files changed

+198
-222
lines changed

6 files changed

+198
-222
lines changed

controllers/smbcommonconfig_controller.go

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,12 @@ import (
2424
"sigs.k8s.io/controller-runtime/pkg/client"
2525

2626
sambaoperatorv1alpha1 "github.com/samba-in-kubernetes/samba-operator/api/v1alpha1"
27-
"github.com/samba-in-kubernetes/samba-operator/internal/conf"
28-
"github.com/samba-in-kubernetes/samba-operator/internal/resources"
2927
)
3028

3129
// SmbCommonConfigReconciler reconciles a SmbCommonConfig object
3230
type SmbCommonConfigReconciler struct {
3331
client.Client
34-
Log logr.Logger
35-
ClusterType string
32+
Log logr.Logger
3633
}
3734

3835
//revive:disable kubebuilder directives
@@ -43,43 +40,18 @@ type SmbCommonConfigReconciler struct {
4340
// +kubebuilder:rbac:groups=core,resources=serviceaccounts,verbs=get;list;watch;create;update;patch;delete
4441
// +kubebuilder:rbac:groups=core,resources=pods;endpoints;services;namespaces,verbs=get;list;watch;update
4542
// +kubebuilder:rbac:groups=rbac.authorization.k8s.io,resources=roles;rolebindings,verbs=get;list;watch;create;update;delete
46-
// +kubebuilder:rbac:groups=security.openshift.io,resources=securitycontextconstraints,verbs=get;list;use
47-
// +kubebuilder:rbac:groups=security.openshift.io,resourceNames=samba,resources=securitycontextconstraints,verbs=get;list;create;update
4843
// +kubebuilder:rbac:groups=coordination.k8s.io,resources=leases,verbs=get;list;create;update
4944
// +kubebuilder:rbac:groups=monitoring.coreos.com,resources=servicemonitors;prometheusrules,verbs=get;list;watch;create;update
5045

5146
//revive:enable
5247

5348
// Reconcile SmbCommonConfig resources.
5449
func (r *SmbCommonConfigReconciler) Reconcile(
55-
ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
50+
_ context.Context, req ctrl.Request) (ctrl.Result, error) {
5651
// ---
5752
log := r.Log.WithValues("smbcommonconfig", req.NamespacedName)
58-
59-
// Process OpenShift logic in one of two states:
60-
// 1) Unknown cluster type due to first-time reconcile
61-
// 2) Known to be running over OpenShift by in-memory cached state from
62-
// previous reconcile loop.
63-
if r.ClusterType != "" && r.ClusterType != conf.ClusterTypeOpenShift {
64-
return ctrl.Result{}, nil
65-
}
66-
67-
mgr := resources.NewOpenShiftManager(r.Client, log, conf.Get())
68-
res := mgr.Process(ctx, req.NamespacedName)
69-
err := res.Err()
70-
if res.Requeue() {
71-
return ctrl.Result{Requeue: true}, err
72-
}
73-
74-
// Cache in-memory cluster-type to avoid extra network round-trips in next
75-
// reconcile phase.
76-
if r.ClusterType == "" {
77-
r.Log.Info("Saving discovered cluster type",
78-
"ClusterType", mgr.ClusterType)
79-
r.ClusterType = mgr.ClusterType
80-
}
81-
82-
return ctrl.Result{}, err
53+
log.Info("Reconcile SmbCommonConfig")
54+
return ctrl.Result{}, nil
8355
}
8456

8557
// SetupWithManager sets up resource management.

controllers/smbshare_controller.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ type SmbShareReconciler struct {
5252
// +kubebuilder:rbac:groups=core,resources=services,verbs=get;list;watch;create;update;patch;delete
5353
// +kubebuilder:rbac:groups=core,resources=events,verbs=create
5454
// +kubebuilder:rbac:groups=coordination.k8s.io,resources=leases,verbs=get;list;watch;create;update;delete
55+
// +kubebuilder:rbac:groups=security.openshift.io,resources=securitycontextconstraints,verbs=get;list;use
56+
// +kubebuilder:rbac:groups=security.openshift.io,resourceNames=samba,resources=securitycontextconstraints,verbs=get;list;create;update
57+
// +kubebuilder:rbac:groups=monitoring.coreos.com,resources=servicemonitors;prometheusrules,verbs=get;list;watch;create;update
5558

5659
//revive:enable
5760

internal/resources/deployments.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ func buildDeployment(cfg *conf.OperatorConfig,
4242
Name: planner.InstanceName(),
4343
Namespace: ns,
4444
Labels: labels,
45+
Annotations: map[string]string{
46+
"openshift.io/scc": sambaSccName,
47+
},
4548
},
4649
Spec: appsv1.DeploymentSpec{
4750
Replicas: &size,
@@ -91,6 +94,7 @@ func annotationsForSmbPod(cfg *conf.OperatorConfig) map[string]string {
9194
annotations := map[string]string{
9295
"kubectl.kubernetes.io/default-logs-container": name,
9396
"kubectl.kubernetes.io/default-container": name,
97+
"openshift.io/scc": sambaSccName,
9498
}
9599
if withMetricsExporter(cfg) {
96100
for k, v := range annotationsForSmbMetricsPod() {

0 commit comments

Comments
 (0)