Skip to content

Commit bdfa3bb

Browse files
committed
minor optimisations
Signed-off-by: Ashima-Ashima1 <[email protected]>
1 parent 63ebb3b commit bdfa3bb

File tree

4 files changed

+46
-77
lines changed

4 files changed

+46
-77
lines changed

controllers/ibmobjectcsi_controller.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,6 @@ func (r *IBMObjectCSIReconciler) Reconcile(ctx context.Context, req ctrl.Request
116116
//This ensures that the CR has all the required fields with default values before further processing or reconciliation by the operator.
117117
r.Scheme.Default(instance.Unwrap())
118118
changed := instance.SetDefaults()
119-
if err := instance.Validate(); err != nil {
120-
err = fmt.Errorf("wrong IBMObjectCSI options: %v", err)
121-
return reconcile.Result{RequeueAfter: ReconcileTime}, err
122-
}
123119
// update CR if there was changes after defaulting
124120
if changed {
125121
err = r.Update(context.TODO(), instance.Unwrap())

controllers/internal/crutils/static_resource_generator.go

Lines changed: 23 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,6 @@ import (
99
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1010
)
1111

12-
const (
13-
securityOpenshiftApiGroup string = "security.openshift.io"
14-
rbacAuthorizationApiGroup string = "rbac.authorization.k8s.io"
15-
storageClassesResource string = "storageclasses"
16-
persistentVolumesResource string = "persistentvolumes"
17-
persistentVolumeClaimsResource string = "persistentvolumeclaims"
18-
persistentVolumeClaimsStatusResource string = "persistentvolumeclaims/status"
19-
persistentVolumeClaimsFinalizersResource string = "persistentvolumeclaims/finalizers"
20-
podsResource string = "pods"
21-
eventsResource string = "events"
22-
nodesResource string = "nodes"
23-
csiNodesResource string = "csinodes"
24-
secretsResource string = "secrets"
25-
securityContextConstraintsResource string = "securitycontextconstraints"
26-
verbGet string = "get"
27-
verbList string = "list"
28-
verbWatch string = "watch"
29-
verbCreate string = "create"
30-
verbUpdate string = "update"
31-
verbPatch string = "patch"
32-
verbDelete string = "delete"
33-
)
34-
3512
func (c *IBMObjectCSI) GenerateCSIDriver() *storagev1.CSIDriver {
3613
defaultFSGroupPolicy := storagev1.FileFSGroupPolicy
3714
return &storagev1.CSIDriver{
@@ -75,38 +52,38 @@ func (c *IBMObjectCSI) GenerateExternalProvisionerClusterRole() *rbacv1.ClusterR
7552
Rules: []rbacv1.PolicyRule{
7653
{
7754
APIGroups: []string{""},
78-
Resources: []string{secretsResource},
79-
Verbs: []string{verbGet, verbList},
55+
Resources: []string{config.SecretsResource},
56+
Verbs: []string{config.VerbGet, config.VerbList},
8057
},
8158
{
8259
APIGroups: []string{""},
83-
Resources: []string{persistentVolumesResource},
84-
Verbs: []string{verbGet, verbList, verbWatch, verbCreate, verbDelete},
60+
Resources: []string{config.PersistentVolumesResource},
61+
Verbs: []string{config.VerbGet, config.VerbList, config.VerbWatch, config.VerbCreate, config.VerbDelete},
8562
},
8663
{
8764
APIGroups: []string{""},
88-
Resources: []string{persistentVolumeClaimsResource},
89-
Verbs: []string{verbGet, verbList, verbWatch, verbUpdate},
65+
Resources: []string{config.PersistentVolumeClaimsResource},
66+
Verbs: []string{config.VerbGet, config.VerbList, config.VerbWatch, config.VerbUpdate},
9067
},
9168
{
9269
APIGroups: []string{config.StorageApiGroup},
93-
Resources: []string{storageClassesResource},
94-
Verbs: []string{verbGet, verbList, verbWatch},
70+
Resources: []string{config.StorageClassesResource},
71+
Verbs: []string{config.VerbGet, config.VerbList, config.VerbWatch},
9572
},
9673
{
9774
APIGroups: []string{""},
98-
Resources: []string{eventsResource},
99-
Verbs: []string{verbList, verbWatch, verbCreate, verbUpdate, verbPatch},
75+
Resources: []string{config.EventsResource},
76+
Verbs: []string{config.VerbList, config.VerbWatch, config.VerbCreate, config.VerbUpdate, config.VerbPatch},
10077
},
10178
{
10279
APIGroups: []string{config.StorageApiGroup},
103-
Resources: []string{csiNodesResource},
104-
Verbs: []string{verbGet, verbList, verbWatch},
80+
Resources: []string{config.CsiNodesResource},
81+
Verbs: []string{config.VerbGet, config.VerbList, config.VerbWatch},
10582
},
10683
{
10784
APIGroups: []string{""},
108-
Resources: []string{nodesResource},
109-
Verbs: []string{verbGet, verbList, verbWatch},
85+
Resources: []string{config.NodesResource},
86+
Verbs: []string{config.VerbGet, config.VerbList, config.VerbWatch},
11087
},
11188
},
11289
}
@@ -127,7 +104,7 @@ func (c *IBMObjectCSI) GenerateExternalProvisionerClusterRoleBinding() *rbacv1.C
127104
RoleRef: rbacv1.RoleRef{
128105
Kind: "ClusterRole",
129106
Name: config.GetNameForResource(config.ExternalProvisionerClusterRole, c.Name),
130-
APIGroup: rbacAuthorizationApiGroup,
107+
APIGroup: config.RbacAuthorizationApiGroup,
131108
},
132109
}
133110
}
@@ -139,8 +116,8 @@ func (c *IBMObjectCSI) GenerateSCCForControllerClusterRole() *rbacv1.ClusterRole
139116
},
140117
Rules: []rbacv1.PolicyRule{
141118
{
142-
APIGroups: []string{securityOpenshiftApiGroup},
143-
Resources: []string{securityContextConstraintsResource},
119+
APIGroups: []string{config.SecurityOpenshiftApiGroup},
120+
Resources: []string{config.SecurityContextConstraintsResource},
144121
ResourceNames: []string{"anyuid"},
145122
Verbs: []string{"use"},
146123
},
@@ -163,7 +140,7 @@ func (c *IBMObjectCSI) GenerateSCCForControllerClusterRoleBinding() *rbacv1.Clus
163140
RoleRef: rbacv1.RoleRef{
164141
Kind: "ClusterRole",
165142
Name: config.GetNameForResource(config.CSIControllerSCCClusterRole, c.Name),
166-
APIGroup: rbacAuthorizationApiGroup,
143+
APIGroup: config.RbacAuthorizationApiGroup,
167144
},
168145
}
169146
}
@@ -175,15 +152,15 @@ func (c *IBMObjectCSI) GenerateSCCForNodeClusterRole() *rbacv1.ClusterRole {
175152
},
176153
Rules: []rbacv1.PolicyRule{
177154
{
178-
APIGroups: []string{securityOpenshiftApiGroup},
179-
Resources: []string{securityContextConstraintsResource},
155+
APIGroups: []string{config.SecurityOpenshiftApiGroup},
156+
Resources: []string{config.SecurityContextConstraintsResource},
180157
ResourceNames: []string{"privileged"},
181158
Verbs: []string{"use"},
182159
},
183160
{
184161
APIGroups: []string{""},
185-
Resources: []string{nodesResource},
186-
Verbs: []string{verbGet},
162+
Resources: []string{config.NodesResource},
163+
Verbs: []string{config.VerbGet},
187164
},
188165
},
189166
}
@@ -204,7 +181,7 @@ func (c *IBMObjectCSI) GenerateSCCForNodeClusterRoleBinding() *rbacv1.ClusterRol
204181
RoleRef: rbacv1.RoleRef{
205182
Kind: "ClusterRole",
206183
Name: config.GetNameForResource(config.CSINodeSCCClusterRole, c.Name),
207-
APIGroup: rbacAuthorizationApiGroup,
184+
APIGroup: config.RbacAuthorizationApiGroup,
208185
},
209186
}
210187
}

controllers/internal/crutils/validator.go

Lines changed: 0 additions & 8 deletions
This file was deleted.

pkg/config/constants.go

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,32 @@ package config
22

33
// Add a field here if it never changes, if it changes over time, put it to settings.go
44
const (
5-
APIGroup = "csi.ibm.com"
6-
APIVersion = "v1"
7-
Name = "ibm-object-csi-operator"
8-
DriverName = "cos.s3.csi.ibm.io"
9-
ProductName = "ibm-object-csi-driver"
5+
APIGroup = "csi.ibm.com"
6+
APIVersion = "v1"
7+
Name = "ibm-object-csi-operator"
8+
DriverName = "cos.s3.csi.ibm.io"
9+
ProductName = "ibm-object-csi-driver"
10+
1011
RbacAuthorizationApiGroup = "rbac.authorization.k8s.io"
11-
CsiNodesResource = "csinodes"
12-
SecretsResource = "secrets"
13-
PodsResource = "pods"
14-
VerbGet = "get"
15-
VerbList = "list"
16-
VerbWatch = "watch"
17-
VerbCreate = "create"
18-
VerbPatch = "patch"
12+
SecurityOpenshiftApiGroup = "security.openshift.io"
1913
StorageApiGroup = "storage.k8s.io"
20-
AppsApiGroup = "apps"
21-
StorageClassesResource = "storageclasses"
22-
EventsResource = "events"
23-
NodesResource = "nodes"
24-
DaemonSetResource = "daemonsets"
2514

26-
ENVKubeVersion = "KUBE_VERSION"
15+
CsiNodesResource = "csinodes"
16+
SecretsResource = "secrets"
17+
SecurityContextConstraintsResource = "securitycontextconstraints"
18+
StorageClassesResource = "storageclasses"
19+
EventsResource = "events"
20+
NodesResource = "nodes"
21+
PersistentVolumesResource = "persistentvolumes"
22+
PersistentVolumeClaimsResource = "persistentvolumeclaims"
23+
24+
VerbGet = "get"
25+
VerbList = "list"
26+
VerbWatch = "watch"
27+
VerbCreate = "create"
28+
VerbUpdate = "update"
29+
VerbPatch = "patch"
30+
VerbDelete = "delete"
2731

2832
CSINodeDriverRegistrar = "csi-node-driver-registrar"
2933
CSIProvisioner = "csi-provisioner"

0 commit comments

Comments
 (0)