@@ -58,6 +58,10 @@ func Add(ctx context.Context, mgr manager.Manager, sharedAgentImage, sharedAgent
58
58
return err
59
59
}
60
60
61
+ if sharedAgentImage == "" {
62
+ return errors .New ("missing shared agent image" )
63
+ }
64
+
61
65
// initialize a new Reconciler
62
66
reconciler := ClusterReconciler {
63
67
DiscoveryClient : discoveryClient ,
@@ -109,7 +113,19 @@ func (c *ClusterReconciler) Reconcile(ctx context.Context, req reconcile.Request
109
113
}
110
114
}
111
115
112
- return reconcile.Result {}, reconcilerErr
116
+ // if there was an error during the reconciliation, return
117
+ if reconcilerErr != nil {
118
+ return reconcile.Result {}, reconcilerErr
119
+ }
120
+
121
+ // update Cluster if needed
122
+ if ! reflect .DeepEqual (orig .Spec , cluster .Spec ) {
123
+ if err := c .Client .Update (ctx , & cluster ); err != nil {
124
+ return reconcile.Result {}, err
125
+ }
126
+ }
127
+
128
+ return reconcile.Result {}, nil
113
129
}
114
130
115
131
func (c * ClusterReconciler ) reconcileCluster (ctx context.Context , cluster * v1alpha1.Cluster ) error {
@@ -118,7 +134,7 @@ func (c *ClusterReconciler) reconcileCluster(ctx context.Context, cluster *v1alp
118
134
// if the Version is not specified we will try to use the same Kubernetes version of the host.
119
135
// This version is stored in the Status object, and it will not be updated if already set.
120
136
if cluster .Spec .Version == "" && cluster .Status .HostVersion == "" {
121
- log .V ( 1 ). Info ("cluster version not set" )
137
+ log .Info ("cluster version not set" )
122
138
123
139
hostVersion , err := c .DiscoveryClient .ServerVersion ()
124
140
if err != nil {
@@ -130,6 +146,7 @@ func (c *ClusterReconciler) reconcileCluster(ctx context.Context, cluster *v1alp
130
146
cluster .Status .HostVersion = k8sVersion + "-k3s1"
131
147
}
132
148
149
+ // TODO: update status?
133
150
if err := c .validate (cluster ); err != nil {
134
151
log .Error (err , "invalid change" )
135
152
return nil
@@ -161,6 +178,7 @@ func (c *ClusterReconciler) reconcileCluster(ctx context.Context, cluster *v1alp
161
178
}
162
179
163
180
log .Info ("creating cluster service" )
181
+
164
182
serviceIP , err := c .createClusterService (ctx , cluster , s )
165
183
if err != nil {
166
184
return err
@@ -209,7 +227,7 @@ func (c *ClusterReconciler) reconcileCluster(ctx context.Context, cluster *v1alp
209
227
return err
210
228
}
211
229
212
- return c . Client . Update ( ctx , cluster )
230
+ return nil
213
231
}
214
232
215
233
func (c * ClusterReconciler ) createClusterConfigs (ctx context.Context , cluster * v1alpha1.Cluster , server * server.Server , serviceIP string ) error {
0 commit comments