Skip to content

Commit 7c7848c

Browse files
committed
Introduce common controller
To remove duplicate code across the test-operator controllers, this patch introduces a common controller. This change should make fixing controller bugs easier and prepare the test-operator for new resource addition, if it is needed in the future. Assisted-by: Claude AI
1 parent dcca8a2 commit 7c7848c

File tree

7 files changed

+470
-317
lines changed

7 files changed

+470
-317
lines changed

api/v1beta1/tempest_types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,3 +522,8 @@ func (instance Tempest) RbacNamespace() string {
522522
func (instance Tempest) RbacResourceName() string {
523523
return instance.Name
524524
}
525+
526+
// GetConditions - return the conditions from the status
527+
func (instance *Tempest) GetConditions() *condition.Conditions {
528+
return &instance.Status.Conditions
529+
}

controllers/ansibletest_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ func (r *AnsibleTestReconciler) Reconcile(ctx context.Context, req ctrl.Request)
206206

207207
// Create a new pod
208208
mountCerts := r.CheckSecretExists(ctx, instance, "combined-ca-bundle")
209-
podName := r.GetPodName(instance, nextWorkflowStep)
209+
podName := GetPodName(instance, nextWorkflowStep)
210210
envVars := r.PrepareAnsibleEnv(instance)
211211
logsPVCName := r.GetPVCLogsName(instance, 0)
212212
containerImage, err := r.GetContainerImage(ctx, instance)

controllers/common.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,6 @@ func (r *Reconciler) GetContainerImage(
300300
// GetPodName returns the name of the pod for the given instance and workflow step
301301
func (r *Reconciler) GetPodName(instance interface{}, stepNum int) string {
302302
v := reflect.ValueOf(instance)
303-
304303
name := GetStringField(v, "Name")
305304
spec, err := SafetyCheck(v, "Spec")
306305
if err != nil {
@@ -415,7 +414,7 @@ func (r *Reconciler) GetScheme() *runtime.Scheme {
415414
}
416415

417416
// GetDefaultInt returns the string representation of an integer value with optional default value
418-
func (r *Reconciler) GetDefaultInt(variable int64, defaultValue ...string) string {
417+
func GetDefaultInt(variable int64, defaultValue ...string) string {
419418
if variable != 0 {
420419
return strconv.FormatInt(variable, 10)
421420
} else if len(defaultValue) > 0 {
@@ -520,7 +519,7 @@ func (r *Reconciler) ReleaseLock(ctx context.Context, instance client.Object) (b
520519
// PodExists checks if a pod exists for the given instance and workflow step
521520
func (r *Reconciler) PodExists(ctx context.Context, instance client.Object, workflowStepNum int) bool {
522521
pod := &corev1.Pod{}
523-
podName := r.GetPodName(instance, workflowStepNum)
522+
podName := GetPodName(instance, workflowStepNum)
524523
objectKey := client.ObjectKey{Namespace: instance.GetNamespace(), Name: podName}
525524
err := r.Client.Get(ctx, objectKey, pod)
526525
if err != nil && k8s_errors.IsNotFound(err) {

0 commit comments

Comments
 (0)