@@ -34,6 +34,7 @@ import (
34
34
"sigs.k8s.io/controller-runtime/pkg/source"
35
35
36
36
operatorv1alpha1 "github.com/IBM/operand-deployment-lifecycle-manager/api/v1alpha1"
37
+ "github.com/IBM/operand-deployment-lifecycle-manager/controllers/constant"
37
38
deploy "github.com/IBM/operand-deployment-lifecycle-manager/controllers/operator"
38
39
)
39
40
@@ -73,19 +74,25 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu
73
74
operand := u
74
75
operator := registry .GetOperator (operand .Name )
75
76
if operator .OperatorConfig == "" {
76
- break
77
+ continue
77
78
}
78
79
79
80
var sub * olmv1alpha1.Subscription
80
81
sub , err = r .GetSubscription (ctx , operator .Name , operator .Namespace , registry .Namespace , operator .PackageName )
81
82
if err != nil {
82
83
return ctrl.Result {}, err
84
+ } else if sub == nil {
85
+ klog .Infof ("Subscription for Operator %s/%s not found" , operator .Name , operator .PackageName )
86
+ return ctrl.Result {RequeueAfter : constant .DefaultRequeueDuration }, nil
83
87
}
84
88
85
89
var csv * olmv1alpha1.ClusterServiceVersion
86
90
csv , err = r .GetClusterServiceVersion (ctx , sub )
87
91
if err != nil {
88
92
return ctrl.Result {}, err
93
+ } else if csv == nil {
94
+ klog .Infof ("ClusterServiceVersion for Operator %s/%s not found" , operator .Name , operator .PackageName )
95
+ return ctrl.Result {RequeueAfter : constant .DefaultRequeueDuration }, nil
89
96
}
90
97
91
98
klog .Infof ("Fetching OperatorConfig: %s" , operator .OperatorConfig )
@@ -94,12 +101,16 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu
94
101
Name : operator .OperatorConfig ,
95
102
Namespace : registry .Namespace ,
96
103
}, config ); err != nil {
97
- return ctrl.Result {}, client .IgnoreNotFound (err )
104
+ if client .IgnoreNotFound (err ) != nil {
105
+ return ctrl.Result {}, err
106
+ }
107
+ klog .Infof ("OperatorConfig %s/%s does not exist for operand %s in request %s, %s" , registry .Namespace , operator .OperatorConfig , operator .Name , instance .Namespace , instance .Name )
108
+ continue
98
109
}
99
110
serviceConfig := config .GetConfigForOperator (operator .Name )
100
111
if serviceConfig == nil {
101
112
klog .Infof ("OperatorConfig: %s, does not have configuration for operator: %s" , operator .OperatorConfig , operator .Name )
102
- return ctrl. Result {}, nil
113
+ continue
103
114
}
104
115
105
116
copyToCast , err := deepcopy .Anything (csv )
@@ -108,13 +119,17 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu
108
119
}
109
120
csvToUpdate := copyToCast .(* olmv1alpha1.ClusterServiceVersion )
110
121
klog .Infof ("Applying OperatorConfig: %s to Operator: %s via CSV: %s, %s" , operator .OperatorConfig , operator .Name , csv .Name , csv .Namespace )
111
- return r .configCsv (ctx , csvToUpdate , serviceConfig )
122
+ if err := r .configCsv (ctx , csvToUpdate , serviceConfig ); err != nil {
123
+ klog .Errorf ("Failed to apply OperatorConfig %s/%s to Operator: %s via CSV: %s, %s" , registry .Namespace , operator .OperatorConfig , operator .Name , csv .Namespace , csv .Name )
124
+ return ctrl.Result {}, err
125
+ }
112
126
}
113
127
}
114
- return ctrl.Result {}, nil
128
+ klog .Infof ("Finished reconciling OperatorConfig for request: %s, %s" , instance .Namespace , instance .Name )
129
+ return ctrl.Result {RequeueAfter : constant .DefaultSyncPeriod }, nil
115
130
}
116
131
117
- func (r * Reconciler ) configCsv (ctx context.Context , csv * olmv1alpha1.ClusterServiceVersion , config * operatorv1alpha1.ServiceOperatorConfig ) (ctrl. Result , error ) {
132
+ func (r * Reconciler ) configCsv (ctx context.Context , csv * olmv1alpha1.ClusterServiceVersion , config * operatorv1alpha1.ServiceOperatorConfig ) error {
118
133
if config .Replicas != nil {
119
134
csv .Spec .InstallStrategy .StrategySpec .DeploymentSpecs [0 ].Spec .Replicas = config .Replicas
120
135
}
@@ -125,9 +140,9 @@ func (r *Reconciler) configCsv(ctx context.Context, csv *olmv1alpha1.ClusterServ
125
140
csv .Spec .InstallStrategy .StrategySpec .DeploymentSpecs [0 ].Spec .Template .Spec .TopologySpreadConstraints = config .TopologySpreadConstraints
126
141
}
127
142
if err := r .Client .Update (ctx , csv ); err != nil {
128
- return ctrl. Result {}, err
143
+ return err
129
144
}
130
- return ctrl. Result {}, nil
145
+ return nil
131
146
}
132
147
133
148
func (r * Reconciler ) requestsFromMapFunc (ctx context.Context ) handler.MapFunc {
0 commit comments