@@ -27,7 +27,7 @@ import (
27
27
28
28
apv1b2 "github.com/k0sproject/k0s/pkg/apis/autopilot/v1beta2"
29
29
k0shelm "github.com/k0sproject/k0s/pkg/apis/helm/v1beta1"
30
- "github.com/replicatedhq/embedded-cluster/kinds/apis/v1beta1"
30
+ ecv1beta1 "github.com/replicatedhq/embedded-cluster/kinds/apis/v1beta1"
31
31
"github.com/replicatedhq/embedded-cluster/operator/pkg/metrics"
32
32
"github.com/replicatedhq/embedded-cluster/operator/pkg/openebs"
33
33
"github.com/replicatedhq/embedded-cluster/operator/pkg/util"
@@ -67,8 +67,8 @@ var copyHostPreflightResultsJob = &batchv1.Job{
67
67
Namespace : ecNamespace ,
68
68
},
69
69
Spec : batchv1.JobSpec {
70
- BackoffLimit : ptr.To [ int32 ]( 2 ),
71
- TTLSecondsAfterFinished : ptr.To [ int32 ]( 0 ) , // we don't want to keep the job around. Delete immediately after it finishes.
70
+ BackoffLimit : ptr .To ( int32 ( 2 ) ),
71
+ TTLSecondsAfterFinished : ptr .To ( int32 ( 1 * 60 )) , // we don't want to keep the job around. Delete it shortly after it finishes.
72
72
Template : corev1.PodTemplateSpec {
73
73
Spec : corev1.PodSpec {
74
74
ServiceAccountName : "embedded-cluster-operator" ,
@@ -77,16 +77,25 @@ var copyHostPreflightResultsJob = &batchv1.Job{
77
77
Name : "host" ,
78
78
VolumeSource : corev1.VolumeSource {
79
79
HostPath : & corev1.HostPathVolumeSource {
80
- Path : v1beta1 .DefaultDataDir ,
81
- Type : ptr.To [corev1.HostPathType ]("Directory" ),
80
+ Path : ecv1beta1 .DefaultDataDir ,
81
+ Type : ptr .To (corev1 .HostPathDirectory ),
82
+ },
83
+ },
84
+ },
85
+ {
86
+ Name : "k0s" ,
87
+ VolumeSource : corev1.VolumeSource {
88
+ HostPath : & corev1.HostPathVolumeSource {
89
+ Path : runtimeconfig .K0sBinaryPath ,
90
+ Type : ptr .To (corev1 .HostPathFile ),
82
91
},
83
92
},
84
93
},
85
94
},
86
95
RestartPolicy : corev1 .RestartPolicyNever ,
87
96
Containers : []corev1.Container {
88
97
{
89
- Name : "embedded-cluster-updater " ,
98
+ Name : "copy-host-preflight-results " ,
90
99
Image : "busybox:latest" ,
91
100
Command : []string {
92
101
"/bin/sh" ,
@@ -104,12 +113,23 @@ var copyHostPreflightResultsJob = &batchv1.Job{
104
113
"echo '/embedded-cluster/support/host-preflight-results.json does not exist'; " +
105
114
"fi" ,
106
115
},
116
+ Env : []corev1.EnvVar {
117
+ {
118
+ Name : "KUBECONFIG" ,
119
+ Value : "" , // make k0s kubectl not use admin.conf
120
+ },
121
+ },
107
122
VolumeMounts : []corev1.VolumeMount {
108
123
{
109
124
Name : "host" ,
110
125
MountPath : "/embedded-cluster" ,
111
126
ReadOnly : false ,
112
127
},
128
+ {
129
+ Name : "k0s" ,
130
+ MountPath : runtimeconfig .K0sBinaryPath ,
131
+ ReadOnly : true ,
132
+ },
113
133
},
114
134
},
115
135
},
@@ -139,7 +159,7 @@ type InstallationReconciler struct {
139
159
// NodeHasChanged returns true if the node configuration has changed when compared to
140
160
// the node information we keep in the installation status. Returns a bool indicating
141
161
// if a change was detected and a bool indicating if the node is new (not seen yet).
142
- func (r * InstallationReconciler ) NodeHasChanged (in * v1beta1 .Installation , ev metrics.NodeEvent ) (bool , bool , error ) {
162
+ func (r * InstallationReconciler ) NodeHasChanged (in * ecv1beta1 .Installation , ev metrics.NodeEvent ) (bool , bool , error ) {
143
163
for _ , nodeStatus := range in .Status .NodesStatus {
144
164
if nodeStatus .Name != ev .NodeName {
145
165
continue
@@ -154,7 +174,7 @@ func (r *InstallationReconciler) NodeHasChanged(in *v1beta1.Installation, ev met
154
174
}
155
175
156
176
// UpdateNodeStatus updates the node status in the Installation object status.
157
- func (r * InstallationReconciler ) UpdateNodeStatus (in * v1beta1 .Installation , ev metrics.NodeEvent ) error {
177
+ func (r * InstallationReconciler ) UpdateNodeStatus (in * ecv1beta1 .Installation , ev metrics.NodeEvent ) error {
158
178
hash , err := ev .Hash ()
159
179
if err != nil {
160
180
return err
@@ -166,15 +186,15 @@ func (r *InstallationReconciler) UpdateNodeStatus(in *v1beta1.Installation, ev m
166
186
in .Status .NodesStatus [i ].Hash = hash
167
187
return nil
168
188
}
169
- in .Status .NodesStatus = append (in .Status .NodesStatus , v1beta1 .NodeStatus {Name : ev .NodeName , Hash : hash })
189
+ in .Status .NodesStatus = append (in .Status .NodesStatus , ecv1beta1 .NodeStatus {Name : ev .NodeName , Hash : hash })
170
190
return nil
171
191
}
172
192
173
193
// ReconcileNodeStatuses reconciles the node statuses in the Installation object status. Installation
174
194
// is not updated remotely but only in the memory representation of the object (aka caller must save
175
195
// the object after the call). This function returns a batch of events that need to be sent back to
176
196
// the metrics endpoint, these events represent changes in the node statuses.
177
- func (r * InstallationReconciler ) ReconcileNodeStatuses (ctx context.Context , in * v1beta1 .Installation ) (* NodeEventsBatch , error ) {
197
+ func (r * InstallationReconciler ) ReconcileNodeStatuses (ctx context.Context , in * ecv1beta1 .Installation ) (* NodeEventsBatch , error ) {
178
198
var nodes corev1.NodeList
179
199
if err := r .List (ctx , & nodes ); err != nil {
180
200
return nil , fmt .Errorf ("failed to list nodes: %w" , err )
@@ -206,7 +226,7 @@ func (r *InstallationReconciler) ReconcileNodeStatuses(ctx context.Context, in *
206
226
r .Recorder .Eventf (in , corev1 .EventTypeNormal , "NodeUpdated" , "Node %s has been updated" , node .Name )
207
227
batch .NodesUpdated = append (batch .NodesUpdated , event )
208
228
}
209
- trimmed := []v1beta1 .NodeStatus {}
229
+ trimmed := []ecv1beta1 .NodeStatus {}
210
230
for _ , nodeStatus := range in .Status .NodesStatus {
211
231
if _ , ok := seen [nodeStatus .Name ]; ok {
212
232
trimmed = append (trimmed , nodeStatus )
@@ -224,7 +244,7 @@ func (r *InstallationReconciler) ReconcileNodeStatuses(ctx context.Context, in *
224
244
}
225
245
226
246
// ReportNodesChanges reports node changes to the metrics endpoint.
227
- func (r * InstallationReconciler ) ReportNodesChanges (ctx context.Context , in * v1beta1 .Installation , batch * NodeEventsBatch ) {
247
+ func (r * InstallationReconciler ) ReportNodesChanges (ctx context.Context , in * ecv1beta1 .Installation , batch * NodeEventsBatch ) {
228
248
for _ , ev := range batch .NodesAdded {
229
249
if err := metrics .NotifyNodeAdded (ctx , in .Spec .MetricsBaseURL , ev ); err != nil {
230
250
ctrl .LoggerFrom (ctx ).Error (err , "failed to notify node added" )
@@ -242,7 +262,7 @@ func (r *InstallationReconciler) ReportNodesChanges(ctx context.Context, in *v1b
242
262
}
243
263
}
244
264
245
- func (r * InstallationReconciler ) ReconcileOpenebs (ctx context.Context , in * v1beta1 .Installation ) error {
265
+ func (r * InstallationReconciler ) ReconcileOpenebs (ctx context.Context , in * ecv1beta1 .Installation ) error {
246
266
log := ctrl .LoggerFrom (ctx )
247
267
248
268
err := openebs .CleanupStatefulPods (ctx , r .Client )
@@ -261,8 +281,8 @@ func (r *InstallationReconciler) ReconcileOpenebs(ctx context.Context, in *v1bet
261
281
// status of the newest one is coherent with whole cluster status. Returns the newest
262
282
// installation object.
263
283
func (r * InstallationReconciler ) CoalesceInstallations (
264
- ctx context.Context , items []v1beta1 .Installation ,
265
- ) * v1beta1 .Installation {
284
+ ctx context.Context , items []ecv1beta1 .Installation ,
285
+ ) * ecv1beta1 .Installation {
266
286
sort .SliceStable (items , func (i , j int ) bool {
267
287
return items [j ].Name < items [i ].Name
268
288
})
@@ -281,7 +301,7 @@ func (r *InstallationReconciler) CoalesceInstallations(
281
301
282
302
// ReadClusterConfigSpecFromSecret reads the cluster config from the secret pointed by spec.ConfigSecret
283
303
// if it is set. This overrides the default configuration from spec.Config.
284
- func (r * InstallationReconciler ) ReadClusterConfigSpecFromSecret (ctx context.Context , in * v1beta1 .Installation ) error {
304
+ func (r * InstallationReconciler ) ReadClusterConfigSpecFromSecret (ctx context.Context , in * ecv1beta1 .Installation ) error {
285
305
if in .Spec .ConfigSecret == nil {
286
306
return nil
287
307
}
@@ -298,7 +318,7 @@ func (r *InstallationReconciler) ReadClusterConfigSpecFromSecret(ctx context.Con
298
318
299
319
// CopyHostPreflightResultsFromNodes copies the preflight results from any new node that is added to the cluster
300
320
// A job is scheduled on the new node and the results copied from a host path
301
- func (r * InstallationReconciler ) CopyHostPreflightResultsFromNodes (ctx context.Context , in * v1beta1 .Installation , events * NodeEventsBatch ) error {
321
+ func (r * InstallationReconciler ) CopyHostPreflightResultsFromNodes (ctx context.Context , in * ecv1beta1 .Installation , events * NodeEventsBatch ) error {
302
322
log := ctrl .LoggerFrom (ctx )
303
323
304
324
if len (events .NodesAdded ) == 0 {
@@ -328,7 +348,7 @@ func (r *InstallationReconciler) CopyHostPreflightResultsFromNodes(ctx context.C
328
348
return nil
329
349
}
330
350
331
- func constructHostPreflightResultsJob (rc runtimeconfig.RuntimeConfig , in * v1beta1 .Installation , nodeName string ) * batchv1.Job {
351
+ func constructHostPreflightResultsJob (rc runtimeconfig.RuntimeConfig , in * ecv1beta1 .Installation , nodeName string ) * batchv1.Job {
332
352
labels := map [string ]string {
333
353
"embedded-cluster/node-name" : nodeName ,
334
354
"embedded-cluster/installation" : in .Name ,
@@ -370,9 +390,9 @@ func (r *InstallationReconciler) Reconcile(ctx context.Context, req ctrl.Request
370
390
if err != nil {
371
391
return ctrl.Result {}, fmt .Errorf ("failed to list installations: %w" , err )
372
392
}
373
- var items []v1beta1 .Installation
393
+ var items []ecv1beta1 .Installation
374
394
for _ , in := range installs {
375
- if in .Status .State == v1beta1 .InstallationStateObsolete {
395
+ if in .Status .State == ecv1beta1 .InstallationStateObsolete {
376
396
continue
377
397
}
378
398
items = append (items , in )
@@ -472,7 +492,7 @@ func (r *InstallationReconciler) reconcileHostCABundle(ctx context.Context) erro
472
492
// SetupWithManager sets up the controller with the Manager.
473
493
func (r * InstallationReconciler ) SetupWithManager (mgr ctrl.Manager ) error {
474
494
return ctrl .NewControllerManagedBy (mgr ).
475
- For (& v1beta1 .Installation {}).
495
+ For (& ecv1beta1 .Installation {}).
476
496
Watches (& corev1.Node {}, & handler.EnqueueRequestForObject {}).
477
497
Watches (& apv1b2.Plan {}, & handler.EnqueueRequestForObject {}).
478
498
Watches (& k0shelm.Chart {}, & handler.EnqueueRequestForObject {}).
0 commit comments