54
54
// certificationRuns maps a certificationRun to a pod name
55
55
certificationRuns map [certificationRun ]string
56
56
// Holds an autoincremental CNF Cert Suite pod id
57
- cnfRunPodId int
57
+ cnfRunPodID int
58
58
)
59
59
60
+ const multiplier = 5
61
+
60
62
// +kubebuilder:rbac:groups="*",resources="*",verbs="*"
61
63
// +kubebuilder:rbac:urls="*",verbs="*"
62
64
@@ -69,10 +71,13 @@ func ignoreUpdatePredicate() predicate.Predicate {
69
71
}
70
72
}
71
73
72
- // Updates CnfCertificationSuiteRun.Status.Phase correspomding to a given status
74
+ // Updates CnfCertificationSuiteRun.Status.Phase corresponding to a given status
73
75
func (r * CnfCertificationSuiteRunReconciler ) updateJobStatus (cnfrun * cnfcertificationsv1alpha1.CnfCertificationSuiteRun , status string ) {
74
76
cnfrun .Status .Phase = status
75
- r .Status ().Update (context .Background (), cnfrun )
77
+ err := r .Status ().Update (context .Background (), cnfrun )
78
+ if err != nil {
79
+ logrus .Errorf ("Error found while updating CnfCertificationSuiteRun's status: %s" , err )
80
+ }
76
81
}
77
82
78
83
func (r * CnfCertificationSuiteRunReconciler ) waitForCnfCertJobPodToComplete (ctx context.Context , namespace string , cnfCertJobPod * corev1.Pod ) {
@@ -91,7 +96,7 @@ func (r *CnfCertificationSuiteRunReconciler) waitForCnfCertJobPodToComplete(ctx
91
96
return
92
97
default :
93
98
logrus .Info ("Cnf job pod is running. Current status: " , cnfCertJobPod .Status .Phase )
94
- time .Sleep (5 * time .Second )
99
+ time .Sleep (multiplier * time .Second )
95
100
}
96
101
err := r .Get (ctx , cnfCertJobNamespacedName , cnfCertJobPod )
97
102
if err != nil {
@@ -101,7 +106,8 @@ func (r *CnfCertificationSuiteRunReconciler) waitForCnfCertJobPodToComplete(ctx
101
106
}
102
107
103
108
func (r * CnfCertificationSuiteRunReconciler ) getCertSuiteContainerExitStatus (cnfCertJobPod * corev1.Pod ) int32 {
104
- for _ , containerStatus := range cnfCertJobPod .Status .ContainerStatuses {
109
+ for i := range cnfCertJobPod .Status .ContainerStatuses {
110
+ containerStatus := & cnfCertJobPod .Status .ContainerStatuses [i ]
105
111
if containerStatus .Name == definitions .CnfCertSuiteContainerName {
106
112
return containerStatus .State .Terminated .ExitCode
107
113
}
@@ -119,9 +125,8 @@ func (r *CnfCertificationSuiteRunReconciler) verifyCnfCertSuiteOutput(ctx contex
119
125
logrus .Info ("CNF Cert job has finished running." )
120
126
} else {
121
127
r .updateJobStatus (cnfrun , "CertSuiteError" )
122
- logrus .Info ("CNF Cert job encoutered an error. Exit status: " , certSuiteExitStatus )
128
+ logrus .Info ("CNF Cert job encountered an error. Exit status: " , certSuiteExitStatus )
123
129
}
124
-
125
130
}
126
131
127
132
// Reconcile is part of the main kubernetes reconciliation loop which aims to
@@ -135,30 +140,22 @@ func (r *CnfCertificationSuiteRunReconciler) verifyCnfCertSuiteOutput(ctx contex
135
140
// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.14.1/pkg/reconcile
136
141
func (r * CnfCertificationSuiteRunReconciler ) Reconcile (ctx context.Context , req ctrl.Request ) (ctrl.Result , error ) {
137
142
_ = log .FromContext (ctx )
138
-
139
143
logrus .Infof ("Reconciling CnfCertificationSuiteRun CRD." )
140
144
141
- reqCertificationRun := certificationRun {
142
- name : req .Name ,
143
- namespace : req .Namespace ,
144
- }
145
+ reqCertificationRun := certificationRun {name : req .Name , namespace : req .Namespace }
145
146
146
147
var cnfrun cnfcertificationsv1alpha1.CnfCertificationSuiteRun
147
- if err := r .Get (ctx , req .NamespacedName , & cnfrun ); err != nil {
148
+ if getErr := r .Get (ctx , req .NamespacedName , & cnfrun ); getErr != nil {
148
149
logrus .Infof ("CnfCertificationSuiteRun CR %s (ns %s) not found." , req .Name , req .NamespacedName )
149
-
150
150
if podName , exist := certificationRuns [reqCertificationRun ]; exist {
151
151
logrus .Infof ("CnfCertificationSuiteRun has been deleted. Removing the associated CNF Cert job pod %v" , podName )
152
-
153
- err := r .Delete (context .TODO (), & corev1.Pod {ObjectMeta : metav1.ObjectMeta {Name : podName , Namespace : req .Namespace }})
154
- if err != nil {
155
- logrus .Errorf ("Failed to remove CNF Cert Job pod %s in namespace %s: %v" , req .Name , req .Namespace , err )
152
+ deleteErr := r .Delete (context .TODO (), & corev1.Pod {ObjectMeta : metav1.ObjectMeta {Name : podName , Namespace : req .Namespace }})
153
+ if deleteErr != nil {
154
+ logrus .Errorf ("Failed to remove CNF Cert Job pod %s in namespace %s: %v" , req .Name , req .Namespace , deleteErr )
156
155
}
157
-
158
156
delete (certificationRuns , reqCertificationRun )
159
157
}
160
-
161
- return ctrl.Result {}, client .IgnoreNotFound (err )
158
+ return ctrl.Result {}, client .IgnoreNotFound (getErr )
162
159
}
163
160
164
161
if podName , exist := certificationRuns [reqCertificationRun ]; exist {
@@ -168,14 +165,14 @@ func (r *CnfCertificationSuiteRunReconciler) Reconcile(ctx context.Context, req
168
165
169
166
logrus .Infof ("New CNF Certification Job run requested: %v" , reqCertificationRun )
170
167
171
- cnfRunPodId ++
172
- podName := fmt .Sprintf ("%s-%d" , definitions .CnfCertPodNamePrefix , cnfRunPodId )
168
+ cnfRunPodID ++
169
+ podName := fmt .Sprintf ("%s-%d" , definitions .CnfCertPodNamePrefix , cnfRunPodID )
173
170
174
171
// Store the new run & associated CNF Cert pod name
175
172
certificationRuns [reqCertificationRun ] = podName
176
173
177
174
logrus .Infof ("Running CNF Certification Suite container (job id=%d) with labels %q, log level %q and timeout: %q" ,
178
- cnfRunPodId , cnfrun .Spec .LabelsFilter , cnfrun .Spec .LogLevel , cnfrun .Spec .TimeOut )
175
+ cnfRunPodID , cnfrun .Spec .LabelsFilter , cnfrun .Spec .LogLevel , cnfrun .Spec .TimeOut )
179
176
180
177
// Launch the pod with the CNF Cert Suite container plus the sidecar container to fetch the results.
181
178
r .updateJobStatus (& cnfrun , "CreatingCertSuiteJob" )
@@ -197,8 +194,7 @@ func (r *CnfCertificationSuiteRunReconciler) Reconcile(ctx context.Context, req
197
194
return ctrl.Result {}, nil
198
195
}
199
196
r .updateJobStatus (& cnfrun , "RunningCertSuite" )
200
- logrus .Info ("Runnning CNF Cert job" )
201
-
197
+ logrus .Info ("Running CNF Cert job" )
202
198
go r .verifyCnfCertSuiteOutput (ctx , req .NamespacedName .Namespace , cnfCertJobPod , & cnfrun )
203
199
return ctrl.Result {}, nil
204
200
}
0 commit comments