/
reconciler.go
599 lines (542 loc) · 22.9 KB
/
reconciler.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
package controlplane
import (
"context"
"fmt"
"path"
"reflect"
"strings"
"time"
"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
utilerrors "k8s.io/apimachinery/pkg/util/errors"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/helm/pkg/manifest"
"k8s.io/helm/pkg/releaseutil"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/yaml"
"github.com/maistra/istio-operator/pkg/apis/maistra/conversion"
"github.com/maistra/istio-operator/pkg/apis/maistra/status"
v1 "github.com/maistra/istio-operator/pkg/apis/maistra/v1"
v2 "github.com/maistra/istio-operator/pkg/apis/maistra/v2"
"github.com/maistra/istio-operator/pkg/bootstrap"
"github.com/maistra/istio-operator/pkg/controller/common"
"github.com/maistra/istio-operator/pkg/controller/common/cni"
"github.com/maistra/istio-operator/pkg/controller/hacks"
"github.com/maistra/istio-operator/pkg/controller/versions"
buildinfo "github.com/maistra/istio-operator/pkg/version"
)
type controlPlaneInstanceReconciler struct {
common.ControllerResources
Instance *v2.ServiceMeshControlPlane
Status *v2.ControlPlaneStatus
ownerRefs []metav1.OwnerReference
meshGeneration string
chartVersion string
renderings map[string][]manifest.Manifest
waitForComponents sets.String
cniConfig cni.Config
}
// ensure controlPlaneInstanceReconciler implements ControlPlaneInstanceReconciler
var _ ControlPlaneInstanceReconciler = &controlPlaneInstanceReconciler{}
const (
// Event reasons
eventReasonInstalling = "Installing"
eventReasonPausingInstall = "PausingInstall"
eventReasonPausingUpdate = "PausingUpdate"
eventReasonInstalled = "Installed"
eventReasonUpdating = "Updating"
eventReasonUpdated = "Updated"
eventReasonDeleting = "Deleting"
eventReasonDeleted = "Deleted"
eventReasonPruning = "Pruning"
eventReasonFailedRemovingFinalizer = "FailedRemovingFinalizer"
eventReasonFailedDeletingResources = "FailedDeletingResources"
eventReasonNotReady = "NotReady"
eventReasonReady = "Ready"
patchKialiRequeueInterval = 1 * time.Minute
)
func NewControlPlaneInstanceReconciler(controllerResources common.ControllerResources,
newInstance *v2.ServiceMeshControlPlane, cniConfig cni.Config,
) ControlPlaneInstanceReconciler {
return &controlPlaneInstanceReconciler{
ControllerResources: controllerResources,
Instance: newInstance,
Status: newInstance.Status.DeepCopy(),
cniConfig: cniConfig,
}
}
func (r *controlPlaneInstanceReconciler) Reconcile(ctx context.Context) (result reconcile.Result, err error) {
log := common.LogFromContext(ctx)
log.Info("Reconciling ServiceMeshControlPlane", "Status", r.Instance.Status.StatusType)
earliestSmcp, err := getEarliestSMCPInNamespace(ctx, r.Client, r.Instance.Namespace)
if err != nil {
return reconcile.Result{}, err
}
if earliestSmcp != nil && r.Instance.UID != earliestSmcp.UID {
return reconcile.Result{}, r.postReconciliationStatus(ctx, status.ConditionReasonMultipleSMCPs,
"reconciliation skipped",
fmt.Errorf("multiple ServiceMeshControlPlane resources exist in the namespace"))
}
if r.Status.GetCondition(status.ConditionTypeReconciled).Status != status.ConditionStatusFalse {
r.initializeReconcileStatus()
err := r.PostStatus(ctx)
// ensure that the new reconcile status is posted immediately.
// Reconciliation will resume when the status update comes back into the operator
return reconcile.Result{}, err
}
// make sure status gets updated on exit
reconciledCondition := r.Status.GetCondition(status.ConditionTypeReconciled)
reconciliationMessage := reconciledCondition.Message
reconciliationReason := reconciledCondition.Reason
defer func() {
// this ensures we're updating status (if necessary) and recording events on exit
if statusErr := r.postReconciliationStatus(ctx, reconciliationReason, reconciliationMessage, err); statusErr != nil {
if err == nil {
err = statusErr
} else {
log.Error(statusErr, "Error posting reconciliation status")
}
}
}()
var version versions.Version
version, err = versions.ParseVersion(r.Instance.Spec.Version)
if err != nil {
log.Error(err, "invalid version specified")
return
}
if r.renderings == nil {
// error handling
defer func() {
if err != nil {
r.waitForComponents = sets.NewString()
updateControlPlaneConditions(r.Status, err)
}
}()
r.Status.SetAnnotation(statusAnnotationAlwaysReadyComponents, "")
conversionError, exists, err2 := r.Instance.Spec.TechPreview.GetString(conversion.TechPreviewErroredMessage)
if err2 != nil {
log.Error(err2, "could not read conversion error message")
err = err2
return
}
if exists {
reconciliationReason = status.ConditionReasonValidationError
reconciliationMessage = "Reconciliation skipped due to presence of a conversion error"
err = fmt.Errorf("conversion error: %s", conversionError)
return
}
// Render the templates
r.renderings, err = version.Strategy().Render(ctx, &r.ControllerResources, r.cniConfig, r.Instance)
// always set these, especially if rendering failed, as these are useful for debugging
r.Instance.Status.AppliedValues.DeepCopyInto(&r.Status.AppliedValues)
r.Instance.Status.AppliedSpec.DeepCopyInto(&r.Status.AppliedSpec)
if err != nil {
// we can't progress here
if versions.IsValidationError(err) {
reconciliationReason = status.ConditionReasonValidationError
reconciliationMessage = "Spec is invalid"
} else if versions.IsDependencyMissingError(err) {
reconciliationReason = status.ConditionReasonDependencyMissingError
reconciliationMessage = fmt.Sprintf("Dependency %q is missing", versions.GetMissingDependency(err))
} else {
reconciliationReason = status.ConditionReasonReconcileError
reconciliationMessage = "Error rendering helm charts"
}
err = errors.Wrap(err, reconciliationMessage)
return
}
// install istio
// set the auto-injection flag
// update injection label on namespace
// XXX: this should probably only be done when installing a control plane
// e.g. spec.pilot.enabled || spec.mixer.enabled || spec.galley.enabled || spec.sidecarInjectorWebhook.enabled || ....
// which is all we're supporting atm. if the scope expands to allow
// installing custom gateways, etc., we should revisit this.
err = addNamespaceLabels(ctx, r.Client, r.Instance.Namespace, version)
if err != nil {
// bail if there was an error updating the namespace
r.renderings = nil
reconciliationReason = status.ConditionReasonReconcileError
reconciliationMessage = "Error updating labels on mesh namespace"
err = errors.Wrap(err, reconciliationMessage)
return
}
// initialize new Status
componentStatuses := make([]status.ComponentStatus, 0, len(r.Status.ComponentStatus))
for _, charts := range r.getChartsInInstallationOrder(version.Strategy().GetChartInstallOrder()) {
for _, chartName := range charts {
componentName := componentFromChartName(chartName)
componentStatus := r.Status.FindComponentByName(componentName)
if componentStatus == nil {
componentStatus = status.NewComponentStatus()
componentStatus.Resource = componentName
}
componentStatus.SetCondition(status.Condition{
Type: status.ConditionTypeReconciled,
Status: status.ConditionStatusFalse,
})
componentStatuses = append(componentStatuses, *componentStatus)
}
}
r.Status.ComponentStatus = componentStatuses
// initialize common data
owner := metav1.NewControllerRef(r.Instance, v2.SchemeGroupVersion.WithKind("ServiceMeshControlPlane"))
r.ownerRefs = []metav1.OwnerReference{*owner}
r.meshGeneration = status.CurrentReconciledVersion(r.Instance.GetGeneration())
// Ensure CRDs are installed
chartsDir := version.GetChartsDir()
if err = bootstrap.InstallCRDs(common.NewContextWithLog(ctx, log.WithValues("version", r.Instance.Spec.Version)), r.Client, chartsDir); err != nil {
reconciliationReason = status.ConditionReasonReconcileError
reconciliationMessage = "Failed to install/update Istio CRDs"
log.Error(err, reconciliationMessage)
return
}
// Ensure Istio CNI is installed
if r.cniConfig.Enabled {
if err = bootstrap.InstallCNI(ctx, r.Client, r.cniConfig, r.DiscoveryClient, version); err != nil {
reconciliationReason = status.ConditionReasonReconcileError
reconciliationMessage = "Failed to install/update Istio CNI"
log.Error(err, reconciliationMessage)
return
}
}
if err = r.reconcileRBAC(ctx); err != nil {
reconciliationReason = status.ConditionReasonReconcileError
reconciliationMessage = "Failed to install/update Maistra RBAC resources"
log.Error(err, reconciliationMessage)
return
}
} else if r.waitForComponents.Len() > 0 {
// if we've already begun reconciling, make sure we weren't waiting for
// the last component to become ready
readyComponents, _, readinessErr := r.calculateComponentReadiness(ctx)
if readinessErr != nil {
// error calculating readiness
reconciliationReason = status.ConditionReasonProbeError
reconciliationMessage = "Error checking component readiness"
err = errors.Wrap(readinessErr, reconciliationMessage)
log.Error(err, reconciliationMessage)
return
}
r.waitForComponents.Delete(readyComponents.List()...)
if r.waitForComponents.Len() > 0 {
reconciliationReason, reconciliationMessage = r.pauseReconciliation(ctx)
return
}
}
// validate generated manifests
// this has to be done always before applying because the memberroll might have changed
err = r.validateManifests(ctx)
if err != nil {
reconciliationReason = status.ConditionReasonReconcileError
reconciliationMessage = "Error validating generated manifests"
err = errors.Wrap(err, reconciliationMessage)
return
}
// create components
for _, charts := range r.getChartsInInstallationOrder(version.Strategy().GetChartInstallOrder()) {
var madeChanges bool
r.waitForComponents = sets.NewString()
for _, chart := range charts {
component := componentFromChartName(chart)
var changes bool
changes, err = r.processComponentManifests(ctx, chart)
madeChanges = madeChanges || changes
if err != nil {
reconciliationReason = status.ConditionReasonReconcileError
reconciliationMessage = fmt.Sprintf("Error processing component %s", component)
return
}
if r.anyComponentHasReadiness(chart) {
r.waitForComponents.Insert(component)
} else {
alwaysReadyComponents := r.Status.GetAnnotation(statusAnnotationAlwaysReadyComponents)
if alwaysReadyComponents == "" {
alwaysReadyComponents = component
} else {
alwaysReadyComponents = fmt.Sprintf("%s,%s", alwaysReadyComponents, component)
}
r.Status.SetAnnotation(statusAnnotationAlwaysReadyComponents, alwaysReadyComponents)
}
// if we get here, the component has been successfully installed
delete(r.renderings, chart)
}
if r.waitForComponents.Len() > 0 {
if madeChanges {
// We have to stop the reconcile here and then wait until all the watch events for all the object
// changes that we've made are received by the operator before we calculate readiness. Otherwise
// we'd calculate readiness with a stale object state that will show the object as ready when it isn't.
hacks.SkipReconciliationUntilCacheSynced(ctx, common.ToNamespacedName(r.Instance))
return
}
readyComponents, _, readyErr := r.calculateComponentReadiness(ctx)
if readyErr != nil {
reconciliationReason, reconciliationMessage = r.pauseReconciliation(ctx)
return
}
r.waitForComponents.Delete(readyComponents.List()...)
if r.waitForComponents.Len() > 0 {
reconciliationReason, reconciliationMessage = r.pauseReconciliation(ctx)
return
}
}
}
// we still need to prune if this is the first generation, e.g. if the operator was updated during the install,
// it's possible that some resources in the original version may not be present in the new version.
// delete unseen components
reconciliationMessage = "Pruning obsolete resources"
r.EventRecorder.Event(r.Instance, corev1.EventTypeNormal, eventReasonPruning, reconciliationMessage)
log.Info(reconciliationMessage)
err = r.prune(ctx, r.meshGeneration)
if err != nil {
reconciliationReason = status.ConditionReasonReconcileError
reconciliationMessage = "Error pruning obsolete resources"
err = errors.Wrap(err, reconciliationMessage)
return
}
if r.isUpdating() {
reconciliationReason = status.ConditionReasonUpdateSuccessful
reconciliationMessage = fmt.Sprintf("Successfully updated from version %s to version %s", r.Status.GetReconciledVersion(), r.meshGeneration)
r.EventRecorder.Event(r.Instance, corev1.EventTypeNormal, eventReasonUpdated, reconciliationMessage)
} else {
reconciliationReason = status.ConditionReasonInstallSuccessful
reconciliationMessage = fmt.Sprintf("Successfully installed version %s", r.meshGeneration)
r.EventRecorder.Event(r.Instance, corev1.EventTypeNormal, eventReasonInstalled, reconciliationMessage)
}
r.Status.ObservedGeneration = r.Instance.GetGeneration()
r.Status.OperatorVersion = buildinfo.Info.Version
r.Status.ChartVersion = r.chartVersion
updateControlPlaneConditions(r.Status, nil)
hacks.SkipReconciliationUntilCacheSynced(ctx, common.ToNamespacedName(r.Instance))
log.Info("Completed ServiceMeshControlPlane reconciliation")
return
}
// finds the first SMCP in the given namespace by creationTimestamp
func getEarliestSMCPInNamespace(ctx context.Context, cl client.Client, ns string) (*v2.ServiceMeshControlPlane, error) {
smcpList := &v2.ServiceMeshControlPlaneList{}
if err := cl.List(ctx, smcpList, client.InNamespace(ns)); err != nil {
return nil, err
}
var earliest *v2.ServiceMeshControlPlane
for _, smcp := range smcpList.Items {
if earliest == nil ||
smcp.CreationTimestamp.Before(&earliest.CreationTimestamp) ||
(smcp.CreationTimestamp == earliest.CreationTimestamp && smcp.Name < earliest.Name) {
// We can't just do `earliest = &smcp`, because of how for loops are implemented in Go.
// Instead, we must create a new variable and store its address in `earliest`.
// See discussion at https://github.com/golang/go/discussions/56010
goPitfallWorkaround := smcp
earliest = &goPitfallWorkaround
}
}
return earliest, nil
}
func (r *controlPlaneInstanceReconciler) pauseReconciliation(ctx context.Context) (status.ConditionReason, string) {
log := common.LogFromContext(ctx)
var eventReason string
var conditionReason status.ConditionReason
if r.isUpdating() {
eventReason = eventReasonPausingUpdate
conditionReason = status.ConditionReasonPausingUpdate
} else {
eventReason = eventReasonPausingInstall
conditionReason = status.ConditionReasonPausingInstall
}
reconciliationMessage := fmt.Sprintf("Paused until the following components become ready: %v", r.waitForComponents.List())
r.EventRecorder.Event(r.Instance, corev1.EventTypeNormal, eventReason, reconciliationMessage)
log.Info(reconciliationMessage)
return conditionReason, reconciliationMessage
}
func (r *controlPlaneInstanceReconciler) isUpdating() bool {
return r.Instance.Status.ObservedGeneration != 0
}
func (r *controlPlaneInstanceReconciler) validateSMCPSpec(spec v1.ControlPlaneSpec, basePath string) error {
if spec.Istio == nil {
return fmt.Errorf("serviceMeshControlPlane missing %s.istio section", basePath)
}
if _, ok, _ := spec.Istio.GetMap("global"); !ok {
return fmt.Errorf("serviceMeshControlPlane missing %s.istio.global section", basePath)
}
return nil
}
func (r *controlPlaneInstanceReconciler) validateManifests(ctx context.Context) error {
log := common.LogFromContext(ctx)
allErrors := []error{}
// validate resource namespaces
smmr := &v1.ServiceMeshMemberRoll{}
smmrRetrievalError := r.Client.Get(context.TODO(), client.ObjectKey{Namespace: r.Instance.GetNamespace(), Name: common.MemberRollName}, smmr)
if smmrRetrievalError != nil {
if !apierrors.IsNotFound(smmrRetrievalError) {
// log error, but don't fail validation just yet: we'll just assume that the control plane namespace is the only namespace for now
// if we end up failing validation because of this assumption, we'll return this error
log.Error(smmrRetrievalError, "failed to retrieve SMMR for SMCP")
smmr = nil
}
}
meshNamespaces := common.GetMeshNamespaces(r.Instance.GetNamespace(), smmr)
for _, manifestList := range r.renderings {
for _, manifestBundle := range manifestList {
manifests := releaseutil.SplitManifests(manifestBundle.Content)
for _, manifest := range manifests {
obj := &unstructured.Unstructured{
Object: make(map[string]interface{}),
}
err := yaml.Unmarshal([]byte(manifest), &obj.Object)
if err != nil || obj.GetNamespace() == "" {
continue
}
if !meshNamespaces.Has(obj.GetNamespace()) {
allErrors = append(allErrors, fmt.Errorf("%s: namespace of manifest %s/%s not in mesh", manifestBundle.Name, obj.GetNamespace(), obj.GetName()))
}
}
}
}
if len(allErrors) > 0 {
// if validation fails because we couldn't Get() the SMMR, return that error
if smmrRetrievalError != nil {
return smmrRetrievalError
}
return utilerrors.NewAggregate(allErrors)
}
return nil
}
func (r *controlPlaneInstanceReconciler) PostStatus(ctx context.Context) error {
// we should only post status if it has changed
if reflect.DeepEqual(r.Status, &r.Instance.Status) {
return nil
}
log := common.LogFromContext(ctx)
instance := &v2.ServiceMeshControlPlane{}
log.Info("Posting status update", "conditions", r.Status.Conditions)
if err := r.Client.Get(ctx, client.ObjectKey{Name: r.Instance.Name, Namespace: r.Instance.Namespace}, instance); err == nil {
instance.Status = *r.Status.DeepCopy()
if err = r.Client.Status().Patch(ctx, instance, common.NewStatusPatch(instance.Status)); err != nil && !apierrors.IsNotFound(err) {
return errors.Wrap(err, "error updating ServiceMeshControlPlane status")
}
// null values may have been removed during patching, which means the
// status we've been caching will not match the status on the instance
// on the next reconcile, which will lead to a cycle of status updates
// while waiting for components to become available.
r.Status = instance.Status.DeepCopy()
} else if !apierrors.IsNotFound(err) {
return errors.Wrap(err, "error getting ServiceMeshControlPlane prior to updating status")
}
return nil
}
func (r *controlPlaneInstanceReconciler) postReconciliationStatus(ctx context.Context,
reconciliationReason status.ConditionReason, reconciliationMessage string, processingErr error,
) error {
var reason string
if r.isUpdating() {
reason = eventReasonUpdating
} else {
reason = eventReasonInstalling
}
reconciledCondition := r.Status.GetCondition(status.ConditionTypeReconciled)
reconciledCondition.Reason = reconciliationReason
if processingErr == nil {
reconciledCondition.Message = reconciliationMessage
} else {
// grab the cause, as it's likely the error includes the reconciliation message
reconciledCondition.Message = fmt.Sprintf("%s: error: %s", reconciliationMessage, errors.Cause(processingErr))
r.EventRecorder.Event(r.Instance, corev1.EventTypeWarning, reason, reconciledCondition.Message)
}
r.Status.SetCondition(reconciledCondition)
// calculate readiness after updating reconciliation status, so we don't mark failed reconcilations as "ready"
_ = r.updateReadinessStatus(ctx)
return r.PostStatus(ctx)
}
func (r *controlPlaneInstanceReconciler) initializeReconcileStatus() {
var readyMessage string
var eventReason string
var conditionReason status.ConditionReason
if r.isUpdating() {
if r.Status.ObservedGeneration == r.Instance.GetGeneration() {
readyMessage = fmt.Sprintf("Updating mesh due to operator version change (%s to %s)", r.Status.OperatorVersion, buildinfo.Info.Version)
conditionReason = status.ConditionReasonOperatorUpdated
} else {
readyMessage = fmt.Sprintf("Updating mesh from generation %d to generation %d", r.Status.ObservedGeneration, r.Instance.GetGeneration())
conditionReason = status.ConditionReasonSpecUpdated
}
eventReason = eventReasonUpdating
} else {
readyMessage = fmt.Sprintf("Installing mesh generation %d", r.Instance.GetGeneration())
eventReason = eventReasonInstalling
conditionReason = status.ConditionReasonResourceCreated
r.Status.SetCondition(status.Condition{
Type: status.ConditionTypeInstalled,
Status: status.ConditionStatusFalse,
Reason: conditionReason,
Message: readyMessage,
})
}
r.EventRecorder.Event(r.Instance, corev1.EventTypeNormal, eventReason, readyMessage)
r.Status.SetCondition(status.Condition{
Type: status.ConditionTypeReconciled,
Status: status.ConditionStatusFalse,
Reason: conditionReason,
Message: readyMessage,
})
r.Status.SetCondition(status.Condition{
Type: status.ConditionTypeReady,
Status: status.ConditionStatusFalse,
Reason: conditionReason,
Message: readyMessage,
})
}
func (r *controlPlaneInstanceReconciler) SetInstance(newInstance *v2.ServiceMeshControlPlane) {
if newInstance.GetGeneration() != r.Instance.GetGeneration() {
// we need to regenerate the renderings
r.renderings = nil
r.waitForComponents = sets.NewString()
// reset reconcile status
r.Status.SetCondition(status.Condition{Type: status.ConditionTypeReconciled, Status: status.ConditionStatusUnknown})
}
r.Instance = newInstance
}
func (r *controlPlaneInstanceReconciler) IsFinished() bool {
return r.Status.GetCondition(status.ConditionTypeReconciled).Status == status.ConditionStatusTrue
}
// returns the keys from r.renderings in the order they need to be installed in:
// - keys in orderedCharts
// - other istio components that have the "istio/" prefix
// - 3scale and other components
func (r *controlPlaneInstanceReconciler) getChartsInInstallationOrder(orderedCharts [][]string) [][]string {
charts := make([][]string, 0, len(r.renderings))
seen := sets.NewString()
// first install the charts listed in orderedCharts (but only if they appear in r.renderings)
for _, chartSet := range orderedCharts {
chartsToDeploy := make([]string, 0, len(chartSet))
for _, chart := range chartSet {
if _, found := r.renderings[chart]; found {
chartsToDeploy = append(chartsToDeploy, chart)
seen.Insert(chart)
}
}
if len(chartsToDeploy) > 0 {
charts = append(charts, chartsToDeploy)
}
}
// install other istio components that aren't listed in orderedCharts
for chart := range r.renderings {
if strings.HasPrefix(chart, "istio/") && !seen.Has(chart) {
charts = append(charts, []string{chart})
seen.Insert(chart)
}
}
// install 3scale and any other components
for chart := range r.renderings {
if !seen.Has(chart) {
charts = append(charts, []string{chart})
}
}
return charts
}
func componentFromChartName(chartName string) string {
_, componentName := path.Split(chartName)
return componentName
}