-
Notifications
You must be signed in to change notification settings - Fork 299
/
hostedcluster_controller.go
5181 lines (4679 loc) · 201 KB
/
hostedcluster_controller.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
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package hostedcluster
import (
"bytes"
"context"
"crypto/rand"
"crypto/x509"
"crypto/x509/pkix"
"errors"
"fmt"
"net"
"net/netip"
"os"
"reflect"
"runtime"
"sort"
"strconv"
"strings"
"time"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/s3"
"github.com/aws/aws-sdk-go/service/s3/s3iface"
"github.com/blang/semver"
"github.com/go-logr/logr"
"github.com/google/uuid"
configv1 "github.com/openshift/api/config/v1"
routev1 "github.com/openshift/api/route/v1"
agentv1 "github.com/openshift/cluster-api-provider-agent/api/v1beta1"
prometheusoperatorv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
"gopkg.in/ini.v1"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
networkingv1 "k8s.io/api/networking/v1"
rbacv1 "k8s.io/api/rbac/v1"
"k8s.io/apimachinery/pkg/api/equality"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/types"
utilerrors "k8s.io/apimachinery/pkg/util/errors"
"k8s.io/apimachinery/pkg/util/intstr"
utilrand "k8s.io/apimachinery/pkg/util/rand"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/util/validation/field"
"k8s.io/client-go/util/workqueue"
"k8s.io/utils/clock"
k8sutilspointer "k8s.io/utils/pointer"
capiaws "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2" // Need this dep atm to satisfy IBM provider dep.
capiibmv1 "sigs.k8s.io/cluster-api-provider-ibmcloud/api/v1beta2"
capikubevirt "sigs.k8s.io/cluster-api-provider-kubevirt/api/v1alpha1"
capiv1 "sigs.k8s.io/cluster-api/api/v1beta1"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/handler"
ctrllog "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
hyperv1 "github.com/openshift/hypershift/api/hypershift/v1beta1"
"github.com/openshift/hypershift/api/util/configrefs"
"github.com/openshift/hypershift/cmd/util"
"github.com/openshift/hypershift/control-plane-operator/controllers/hostedcontrolplane/autoscaler"
"github.com/openshift/hypershift/control-plane-operator/controllers/hostedcontrolplane/machineapprover"
cpomanifests "github.com/openshift/hypershift/control-plane-operator/controllers/hostedcontrolplane/manifests"
"github.com/openshift/hypershift/control-plane-pki-operator/certificates"
ignitionserverreconciliation "github.com/openshift/hypershift/hypershift-operator/controllers/hostedcluster/ignitionserver"
"github.com/openshift/hypershift/hypershift-operator/controllers/hostedcluster/internal/platform"
platformaws "github.com/openshift/hypershift/hypershift-operator/controllers/hostedcluster/internal/platform/aws"
hcmetrics "github.com/openshift/hypershift/hypershift-operator/controllers/hostedcluster/metrics"
"github.com/openshift/hypershift/hypershift-operator/controllers/manifests"
"github.com/openshift/hypershift/hypershift-operator/controllers/manifests/clusterapi"
"github.com/openshift/hypershift/hypershift-operator/controllers/manifests/controlplaneoperator"
controlplanepkioperatormanifests "github.com/openshift/hypershift/hypershift-operator/controllers/manifests/controlplanepkioperator"
"github.com/openshift/hypershift/hypershift-operator/controllers/manifests/ignitionserver"
kvinfra "github.com/openshift/hypershift/kubevirtexternalinfra"
"github.com/openshift/hypershift/support/api"
"github.com/openshift/hypershift/support/azureutil"
"github.com/openshift/hypershift/support/capabilities"
"github.com/openshift/hypershift/support/certs"
"github.com/openshift/hypershift/support/config"
"github.com/openshift/hypershift/support/globalconfig"
"github.com/openshift/hypershift/support/images"
"github.com/openshift/hypershift/support/infraid"
"github.com/openshift/hypershift/support/metrics"
"github.com/openshift/hypershift/support/oidc"
"github.com/openshift/hypershift/support/proxy"
"github.com/openshift/hypershift/support/releaseinfo"
"github.com/openshift/hypershift/support/releaseinfo/registryclient"
"github.com/openshift/hypershift/support/rhobsmonitoring"
"github.com/openshift/hypershift/support/supportedversion"
"github.com/openshift/hypershift/support/upsert"
hyperutil "github.com/openshift/hypershift/support/util"
)
const (
HostedClusterFinalizer = "hypershift.openshift.io/finalizer"
HostedClusterAnnotation = "hypershift.openshift.io/cluster"
clusterDeletionRequeueDuration = 5 * time.Second
ReportingGracePeriodRequeueDuration = 25 * time.Second
ImageStreamCAPI = "cluster-capi-controllers"
ImageStreamAutoscalerImage = "cluster-autoscaler"
ImageStreamClusterMachineApproverImage = "cluster-machine-approver"
controlPlaneOperatorSubcommandsLabel = "io.openshift.hypershift.control-plane-operator-subcommands"
ignitionServerHealthzHandlerLabel = "io.openshift.hypershift.ignition-server-healthz-handler"
controlplaneOperatorManagesIgnitionServerLabel = "io.openshift.hypershift.control-plane-operator-manages-ignition-server"
controlPlaneOperatorManagesMachineApprover = "io.openshift.hypershift.control-plane-operator-manages.cluster-machine-approver"
controlPlaneOperatorManagesMachineAutoscaler = "io.openshift.hypershift.control-plane-operator-manages.cluster-autoscaler"
controlPlaneOperatorAppliesManagementKASNetworkPolicyLabel = "io.openshift.hypershift.control-plane-operator-applies-management-kas-network-policy-label"
controlPlanePKIOperatorSignsCSRsLabel = "io.openshift.hypershift.control-plane-pki-operator-signs-csrs"
useRestrictedPodSecurityLabel = "io.openshift.hypershift.restricted-psa"
etcdEncKeyPostfix = "-etcd-encryption-key"
managedServiceEnvVar = "MANAGED_SERVICE"
)
var (
// NoopReconcile is just a default mutation function that does nothing.
NoopReconcile controllerutil.MutateFn = func() error { return nil }
)
// HostedClusterReconciler reconciles a HostedCluster object
type HostedClusterReconciler struct {
client.Client
// ManagementClusterCapabilities can be asked for support of optional management cluster capabilities
ManagementClusterCapabilities capabilities.CapabiltyChecker
// HypershiftOperatorImage is the image used to deploy the control plane operator if
// 1) There is no hypershift.openshift.io/control-plane-operator-image annotation on the HostedCluster and
// 2) The OCP version being deployed is the latest version supported by Hypershift
HypershiftOperatorImage string
RegistryOverrides map[string]string
// SetDefaultSecurityContext is used to configure Security Context for containers
SetDefaultSecurityContext bool
// Clock is used to determine the time in a testable way.
Clock clock.WithTickerAndDelayedExecution
EnableOCPClusterMonitoring bool
createOrUpdate func(reconcile.Request) upsert.CreateOrUpdateFN
EnableCIDebugOutput bool
PrivatePlatform hyperv1.PlatformType
OIDCStorageProviderS3BucketName string
S3Client s3iface.S3API
MetricsSet metrics.MetricsSet
SREConfigHash string
OperatorNamespace string
ReconcileMetadataProviders func(ctx context.Context, imgOverrides map[string]string) (releaseinfo.ProviderWithOpenShiftImageRegistryOverrides, hyperutil.ImageMetadataProvider, error)
overwriteReconcile func(ctx context.Context, req ctrl.Request, log logr.Logger, hcluster *hyperv1.HostedCluster) (ctrl.Result, error)
now func() metav1.Time
KubevirtInfraClients kvinfra.KubevirtInfraClientMap
MonitoringDashboards bool
CertRotationScale time.Duration
EnableCVOManagementClusterMetricsAccess bool
}
// +kubebuilder:rbac:groups=hypershift.openshift.io,resources=hostedclusters,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=hypershift.openshift.io,resources=hostedclusters/status,verbs=get;update;patch
func (r *HostedClusterReconciler) SetupWithManager(mgr ctrl.Manager, createOrUpdate upsert.CreateOrUpdateProvider, metricsSet metrics.MetricsSet, operatorNamespace string) error {
if r.Clock == nil {
r.Clock = clock.RealClock{}
}
if r.now == nil {
r.now = metav1.Now
}
r.createOrUpdate = createOrUpdateWithAnnotationFactory(createOrUpdate)
// Set up watches for resource types the controller manages. The list basically
// tracks types of the resources in the clusterapi, controlplaneoperator, and
// ignitionserver manifests packages. Since we're receiving watch events across
// namespaces, the events are filtered to enqueue only those resources which
// are annotated as being associated with a hostedcluster (using an annotation).
bldr := ctrl.NewControllerManagedBy(mgr).
For(&hyperv1.HostedCluster{}, builder.WithPredicates(hyperutil.PredicatesForHostedClusterAnnotationScoping(mgr.GetClient()))).
WithOptions(controller.Options{
RateLimiter: workqueue.NewItemExponentialFailureRateLimiter(1*time.Second, 10*time.Second),
MaxConcurrentReconciles: 10,
})
for _, managedResource := range r.managedResources() {
bldr.Watches(managedResource, handler.EnqueueRequestsFromMapFunc(enqueueHostedClustersFunc(metricsSet, operatorNamespace, mgr.GetClient())), builder.WithPredicates(hyperutil.PredicatesForHostedClusterAnnotationScoping(mgr.GetClient())))
}
// Set based on SCC capability
// When SCC is available (OpenShift), the container's security context and UID range is automatically set
// When SCC is not available (Kubernetes), we want to explicitly set a default (non-root) security context
r.SetDefaultSecurityContext = !r.ManagementClusterCapabilities.Has(capabilities.CapabilitySecurityContextConstraint)
r.ReconcileMetadataProviders = r.ReconcileMetadataProvidersImpl
return bldr.Complete(r)
}
// managedResources are all the resources that are managed as childresources for a HostedCluster
func (r *HostedClusterReconciler) managedResources() []client.Object {
managedResources := []client.Object{
&capiaws.AWSCluster{},
&hyperv1.HostedControlPlane{},
&capiv1.Cluster{},
&appsv1.Deployment{},
&prometheusoperatorv1.PodMonitor{},
&networkingv1.NetworkPolicy{},
&rbacv1.ClusterRole{},
&rbacv1.ClusterRoleBinding{},
&rbacv1.Role{},
&rbacv1.RoleBinding{},
&corev1.ConfigMap{},
&corev1.Secret{},
&corev1.Namespace{},
&corev1.ServiceAccount{},
&corev1.Service{},
&corev1.Endpoints{},
&agentv1.AgentCluster{},
&capiibmv1.IBMVPCCluster{},
&capikubevirt.KubevirtCluster{},
}
// Watch based on Routes capability
if r.ManagementClusterCapabilities.Has(capabilities.CapabilityRoute) {
managedResources = append(managedResources, &routev1.Route{})
}
if r.ManagementClusterCapabilities.Has(capabilities.CapabilityIngress) {
managedResources = append(managedResources, &configv1.Ingress{})
}
return managedResources
}
// serviceFirstNodePortAvailable checks if the first port in a service has a node port available. Utilized to
// check status of the ignition service
func serviceFirstNodePortAvailable(svc *corev1.Service) bool {
return svc != nil && len(svc.Spec.Ports) > 0 && svc.Spec.Ports[0].NodePort > 0
}
// pauseHostedControlPlane will handle adding the pausedUntil field to the hostedControlPlane object if it exists.
// If it doesn't exist: it returns as there's no need to add it
func pauseHostedControlPlane(ctx context.Context, c client.Client, hcp *hyperv1.HostedControlPlane, pauseValue *string) error {
// At the initial hosted cluster creation time, there is no HCP.
if hcp == nil {
return nil
}
err := c.Get(ctx, client.ObjectKeyFromObject(hcp), hcp)
if err != nil {
if !apierrors.IsNotFound(err) {
return fmt.Errorf("failed to get hostedcontrolplane: %w", err)
}
return nil
}
if hcp.Spec.PausedUntil != pauseValue {
hcp.Spec.PausedUntil = pauseValue
if err := c.Update(ctx, hcp); err != nil {
return fmt.Errorf("failed to pause hostedcontrolplane: %w", err)
}
}
return nil
}
func (r *HostedClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
log := ctrl.LoggerFrom(ctx)
log.Info("reconciling")
// Look up the HostedCluster instance to reconcile
hcluster := &hyperv1.HostedCluster{}
err := r.Get(ctx, req.NamespacedName, hcluster)
if err != nil {
if apierrors.IsNotFound(err) {
log.Info("hostedcluster not found, aborting reconcile", "name", req.NamespacedName)
return ctrl.Result{}, nil
}
return ctrl.Result{}, fmt.Errorf("failed to get cluster %q: %w", req.NamespacedName, err)
}
var res reconcile.Result
if r.overwriteReconcile != nil {
res, err = r.overwriteReconcile(ctx, req, log, hcluster)
} else {
res, err = r.reconcile(ctx, req, log, hcluster)
}
condition := metav1.Condition{
Type: string(hyperv1.ReconciliationSucceeded),
ObservedGeneration: hcluster.Generation,
Status: metav1.ConditionTrue,
Reason: "ReconciliatonSucceeded",
Message: "Reconciliation completed successfully",
LastTransitionTime: r.now(),
}
if err != nil {
condition.Status = metav1.ConditionFalse
condition.Reason = "ReconciliationError"
condition.Message = err.Error()
}
old := meta.FindStatusCondition(hcluster.Status.Conditions, string(hyperv1.ReconciliationSucceeded))
if old != nil {
old.LastTransitionTime = condition.LastTransitionTime
}
if !reflect.DeepEqual(old, &condition) {
meta.SetStatusCondition(&hcluster.Status.Conditions, condition)
return res, utilerrors.NewAggregate([]error{err, r.Client.Status().Update(ctx, hcluster)})
}
return res, err
}
func (r *HostedClusterReconciler) ReconcileMetadataProvidersImpl(ctx context.Context, imgOverrides map[string]string) (releaseinfo.ProviderWithOpenShiftImageRegistryOverrides, hyperutil.ImageMetadataProvider, error) {
releaseProvider, imageMetadataProvider, err := globalconfig.RenconcileMgmtImageRegistryOverrides(ctx, r.ManagementClusterCapabilities, r.Client, imgOverrides)
return releaseProvider, imageMetadataProvider, err
}
func (r *HostedClusterReconciler) reconcile(ctx context.Context, req ctrl.Request, log logr.Logger, hcluster *hyperv1.HostedCluster) (ctrl.Result, error) {
controlPlaneNamespace := manifests.HostedControlPlaneNamespaceObject(hcluster.Namespace, hcluster.Name)
hcp := controlplaneoperator.HostedControlPlane(controlPlaneNamespace.Name, hcluster.Name)
err := r.Client.Get(ctx, client.ObjectKeyFromObject(hcp), hcp)
if err != nil {
if !apierrors.IsNotFound(err) {
return ctrl.Result{}, fmt.Errorf("failed to get hostedcontrolplane: %w", err)
} else {
hcp = nil
}
}
// Bubble up ValidIdentityProvider condition from the hostedControlPlane.
// We set this condition even if the HC is being deleted. Otherwise, a hostedCluster with a conflicted identity provider
// would fail to complete deletion forever with no clear signal for consumers.
if hcluster.Spec.Platform.Type == hyperv1.AWSPlatform {
freshCondition := &metav1.Condition{
Type: string(hyperv1.ValidAWSIdentityProvider),
Status: metav1.ConditionUnknown,
Reason: hyperv1.StatusUnknownReason,
ObservedGeneration: hcluster.Generation,
}
if hcp != nil {
validIdentityProviderCondition := meta.FindStatusCondition(hcp.Status.Conditions, string(hyperv1.ValidAWSIdentityProvider))
if validIdentityProviderCondition != nil {
freshCondition = validIdentityProviderCondition
}
}
oldCondition := meta.FindStatusCondition(hcluster.Status.Conditions, string(hyperv1.ValidAWSIdentityProvider))
// Preserve previous false status if we can no longer determine the status (for example when the hostedcontrolplane has been deleted)
if oldCondition != nil && oldCondition.Status == metav1.ConditionFalse && freshCondition.Status == metav1.ConditionUnknown {
freshCondition.Status = metav1.ConditionFalse
}
if oldCondition == nil || oldCondition.Status != freshCondition.Status {
freshCondition.ObservedGeneration = hcluster.Generation
meta.SetStatusCondition(&hcluster.Status.Conditions, *freshCondition)
// Persist status updates
if err := r.Client.Status().Update(ctx, hcluster); err != nil {
return ctrl.Result{}, fmt.Errorf("failed to update status: %w", err)
}
}
}
// Bubble up AWSDefaultSecurityGroupDeleted condition from the hostedControlPlane.
// We set this condition even if the HC is being deleted, so we can report blocking objects on deletion.
{
if hcp != nil && hcp.DeletionTimestamp != nil {
freshCondition := &metav1.Condition{
Type: string(hyperv1.AWSDefaultSecurityGroupDeleted),
Status: metav1.ConditionUnknown,
Reason: hyperv1.StatusUnknownReason,
ObservedGeneration: hcluster.Generation,
}
securityGroupDeletionCondition := meta.FindStatusCondition(hcp.Status.Conditions, string(hyperv1.AWSDefaultSecurityGroupDeleted))
if securityGroupDeletionCondition != nil {
freshCondition = securityGroupDeletionCondition
}
oldCondition := meta.FindStatusCondition(hcluster.Status.Conditions, string(hyperv1.AWSDefaultSecurityGroupDeleted))
if oldCondition == nil || oldCondition.Message != freshCondition.Message {
freshCondition.ObservedGeneration = hcluster.Generation
meta.SetStatusCondition(&hcluster.Status.Conditions, *freshCondition)
// Persist status updates
if err := r.Client.Status().Update(ctx, hcluster); err != nil {
return ctrl.Result{}, fmt.Errorf("failed to update status: %w", err)
}
}
}
}
// Bubble up CloudResourcesDestroyed condition from the hostedControlPlane.
// We set this condition even if the HC is being deleted, so we can construct SLIs for deletion times.
{
if hcp != nil && hcp.DeletionTimestamp != nil {
freshCondition := &metav1.Condition{
Type: string(hyperv1.CloudResourcesDestroyed),
Status: metav1.ConditionUnknown,
Reason: hyperv1.StatusUnknownReason,
ObservedGeneration: hcluster.Generation,
}
cloudResourcesDestroyedCondition := meta.FindStatusCondition(hcp.Status.Conditions, string(hyperv1.CloudResourcesDestroyed))
if cloudResourcesDestroyedCondition != nil {
freshCondition = cloudResourcesDestroyedCondition
}
oldCondition := meta.FindStatusCondition(hcluster.Status.Conditions, string(hyperv1.CloudResourcesDestroyed))
if oldCondition == nil || oldCondition.Message != freshCondition.Message {
freshCondition.ObservedGeneration = hcluster.Generation
meta.SetStatusCondition(&hcluster.Status.Conditions, *freshCondition)
// Persist status updates
if err := r.Client.Status().Update(ctx, hcluster); err != nil {
return ctrl.Result{}, fmt.Errorf("failed to update status: %w", err)
}
}
}
}
var hcDestroyGracePeriod time.Duration
if gracePeriodString := hcluster.Annotations[hyperv1.HCDestroyGracePeriodAnnotation]; len(gracePeriodString) > 0 {
hcDestroyGracePeriod, err = time.ParseDuration(gracePeriodString)
if err != nil {
return ctrl.Result{}, fmt.Errorf("failed to parse %s annotation: %w", hyperv1.HCDestroyGracePeriodAnnotation, err)
}
}
// If deleted, clean up and return early.
if !hcluster.DeletionTimestamp.IsZero() {
// This new condition is necessary for OCM personnel to report any cloud dangling objects to the user.
// The grace period is customizable using an annotation called HCDestroyGracePeriodAnnotation. It's a time.Duration annotation.
// This annotation will create a new condition called HostedClusterDestroyed which in conjuntion with CloudResourcesDestroyed
// a SRE could determine if there are dangling objects once the HostedCluster is deleted. These cloud dangling objects will remain
// in AWS, and SRE will report them to the final user.
hostedClusterDestroyedCondition := meta.FindStatusCondition(hcluster.Status.Conditions, string(hyperv1.HostedClusterDestroyed))
if hostedClusterDestroyedCondition == nil || hostedClusterDestroyedCondition.Status != metav1.ConditionTrue {
// Keep trying to delete until we know it's safe to finalize.
completed, err := r.delete(ctx, hcluster)
if err != nil {
return ctrl.Result{}, fmt.Errorf("failed to delete hostedcluster: %w", err)
}
if !completed {
log.Info("hostedcluster is still deleting", "name", req.NamespacedName)
return ctrl.Result{RequeueAfter: clusterDeletionRequeueDuration}, nil
}
}
// Once the deletion has occurred, we need to clean up cluster-wide resources
selector := client.MatchingLabelsSelector{Selector: labels.SelectorFromSet(labels.Set{
controlplanepkioperatormanifests.OwningHostedClusterNamespaceLabel: hcluster.Namespace,
controlplanepkioperatormanifests.OwningHostedClusterNameLabel: hcluster.Name,
})}
var crs rbacv1.ClusterRoleList
if err := r.List(ctx, &crs, selector); err != nil {
return ctrl.Result{}, fmt.Errorf("failed to list cluster roles: %w", err)
}
if len(crs.Items) > 0 {
if err := r.DeleteAllOf(ctx, &rbacv1.ClusterRole{}, selector); err != nil {
return ctrl.Result{}, fmt.Errorf("failed to delete cluster roles: %w", err)
}
}
var crbs rbacv1.ClusterRoleBindingList
if err := r.List(ctx, &crbs, selector); err != nil {
return ctrl.Result{}, fmt.Errorf("failed to list cluster role bindings: %w", err)
}
if len(crbs.Items) > 0 {
if err := r.DeleteAllOf(ctx, &rbacv1.ClusterRoleBinding{}, selector); err != nil {
return ctrl.Result{}, fmt.Errorf("failed to delete cluster role bindings: %w", err)
}
}
if hcDestroyGracePeriod > 0 {
if hostedClusterDestroyedCondition == nil {
hostedClusterDestroyedCondition = &metav1.Condition{
Type: string(hyperv1.HostedClusterDestroyed),
Status: metav1.ConditionTrue,
Message: fmt.Sprintf("Grace period set: %v", hcDestroyGracePeriod),
Reason: hyperv1.WaitingForGracePeriodReason,
LastTransitionTime: metav1.NewTime(time.Now()),
ObservedGeneration: hcluster.Generation,
}
meta.SetStatusCondition(&hcluster.Status.Conditions, *hostedClusterDestroyedCondition)
if err := r.Client.Status().Update(ctx, hcluster); err != nil {
return ctrl.Result{}, fmt.Errorf("failed to update status: %w", err)
}
log.Info("Waiting for grace period", "gracePeriod", hcDestroyGracePeriod)
return ctrl.Result{RequeueAfter: hcDestroyGracePeriod}, nil
}
if time.Since(hostedClusterDestroyedCondition.LastTransitionTime.Time) < hcDestroyGracePeriod {
log.Info("Waiting for grace period", "gracePeriod", hcDestroyGracePeriod)
return ctrl.Result{RequeueAfter: hcDestroyGracePeriod - time.Since(hostedClusterDestroyedCondition.LastTransitionTime.Time)}, nil
}
log.Info("grace period finished", "gracePeriod", hcDestroyGracePeriod)
}
// Now we can remove the finalizer.
if controllerutil.ContainsFinalizer(hcluster, HostedClusterFinalizer) {
controllerutil.RemoveFinalizer(hcluster, HostedClusterFinalizer)
if err := r.Update(ctx, hcluster); err != nil {
return ctrl.Result{}, fmt.Errorf("failed to remove finalizer from hostedcluster: %w", err)
}
}
log.Info("Deleted hostedcluster", "name", req.NamespacedName)
return ctrl.Result{}, nil
}
// Part zero: fix up conversion
originalSpec := hcluster.Spec.DeepCopy()
// Reconcile converted AWS roles.
if hcluster.Spec.Platform.AWS != nil {
if err := r.dereferenceAWSRoles(ctx, &hcluster.Spec.Platform.AWS.RolesRef, hcluster.Namespace); err != nil {
return ctrl.Result{}, err
}
}
if hcluster.Spec.SecretEncryption != nil && hcluster.Spec.SecretEncryption.KMS != nil && hcluster.Spec.SecretEncryption.KMS.AWS != nil {
if strings.HasPrefix(hcluster.Spec.SecretEncryption.KMS.AWS.Auth.AWSKMSRoleARN, "arn-from-secret::") {
secretName := strings.TrimPrefix(hcluster.Spec.SecretEncryption.KMS.AWS.Auth.AWSKMSRoleARN, "arn-from-secret::")
arn, err := r.getARNFromSecret(ctx, secretName, hcluster.Namespace)
if err != nil {
return ctrl.Result{}, fmt.Errorf("failed to get ARN from secret %s/%s: %w", hcluster.Namespace, secretName, err)
}
hcluster.Spec.SecretEncryption.KMS.AWS.Auth.AWSKMSRoleARN = arn
}
}
createOrUpdate := r.createOrUpdate(req)
// Reconcile platform defaults
if err := r.reconcilePlatformDefaultSettings(ctx, hcluster, createOrUpdate, log); err != nil {
return ctrl.Result{}, err
}
// Update fields if required.
if !equality.Semantic.DeepEqual(&hcluster.Spec, originalSpec) {
log.Info("Updating deprecated fields for hosted cluster")
return ctrl.Result{}, r.Client.Update(ctx, hcluster)
}
// Part one: update status
// Set kubeconfig status
{
kubeConfigSecret := manifests.KubeConfigSecret(hcluster.Namespace, hcluster.Name)
err := r.Client.Get(ctx, client.ObjectKeyFromObject(kubeConfigSecret), kubeConfigSecret)
if err != nil {
if !apierrors.IsNotFound(err) {
return ctrl.Result{}, fmt.Errorf("failed to reconcile kubeconfig secret: %w", err)
}
} else {
hcluster.Status.KubeConfig = &corev1.LocalObjectReference{Name: kubeConfigSecret.Name}
}
}
// Reconcile the ICSP/IDMS from the management cluster
releaseProvider, registryClientImageMetadataProvider, err := r.ReconcileMetadataProviders(ctx, r.RegistryOverrides)
if err != nil {
return ctrl.Result{}, err
}
// Set kubeadminPassword status
{
explicitOauthConfig := hcluster.Spec.Configuration != nil && hcluster.Spec.Configuration.OAuth != nil
if explicitOauthConfig {
hcluster.Status.KubeadminPassword = nil
} else {
kubeadminPasswordSecret := manifests.KubeadminPasswordSecret(hcluster.Namespace, hcluster.Name)
err := r.Client.Get(ctx, client.ObjectKeyFromObject(kubeadminPasswordSecret), kubeadminPasswordSecret)
if err != nil {
if !apierrors.IsNotFound(err) {
return ctrl.Result{}, fmt.Errorf("failed to reconcile kubeadmin password secret: %w", err)
}
} else {
hcluster.Status.KubeadminPassword = &corev1.LocalObjectReference{Name: kubeadminPasswordSecret.Name}
}
}
}
// Set version status
hcluster.Status.Version = computeClusterVersionStatus(r.Clock, hcluster, hcp)
// Copy the CVO conditions from the HCP.
hcpCVOConditions := map[hyperv1.ConditionType]*metav1.Condition{
hyperv1.ClusterVersionSucceeding: nil,
hyperv1.ClusterVersionProgressing: nil,
hyperv1.ClusterVersionReleaseAccepted: nil,
hyperv1.ClusterVersionUpgradeable: nil,
hyperv1.ClusterVersionAvailable: nil,
}
if hcp != nil {
hcpCVOConditions = map[hyperv1.ConditionType]*metav1.Condition{
hyperv1.ClusterVersionSucceeding: meta.FindStatusCondition(hcp.Status.Conditions, string(hyperv1.ClusterVersionFailing)),
hyperv1.ClusterVersionProgressing: meta.FindStatusCondition(hcp.Status.Conditions, string(hyperv1.ClusterVersionProgressing)),
hyperv1.ClusterVersionReleaseAccepted: meta.FindStatusCondition(hcp.Status.Conditions, string(hyperv1.ClusterVersionReleaseAccepted)),
hyperv1.ClusterVersionUpgradeable: meta.FindStatusCondition(hcp.Status.Conditions, string(hyperv1.ClusterVersionUpgradeable)),
hyperv1.ClusterVersionAvailable: meta.FindStatusCondition(hcp.Status.Conditions, string(hyperv1.ClusterVersionAvailable)),
}
}
for conditionType := range hcpCVOConditions {
var hcCVOCondition *metav1.Condition
// Set unknown status.
var unknownStatusMessage string
if hcpCVOConditions[conditionType] == nil {
unknownStatusMessage = "Condition not found in the CVO."
}
hcCVOCondition = &metav1.Condition{
Type: string(conditionType),
Status: metav1.ConditionUnknown,
Reason: hyperv1.StatusUnknownReason,
Message: unknownStatusMessage,
ObservedGeneration: hcluster.Generation,
}
if hcp != nil && hcpCVOConditions[conditionType] != nil {
// Bubble up info from HCP.
hcCVOCondition = hcpCVOConditions[conditionType]
hcCVOCondition.ObservedGeneration = hcluster.Generation
// Inverse ClusterVersionFailing condition into ClusterVersionSucceeding
// So consumers e.g. UI can categorize as good (True) / bad (False).
if conditionType == hyperv1.ClusterVersionSucceeding {
hcCVOCondition.Type = string(hyperv1.ClusterVersionSucceeding)
var status metav1.ConditionStatus
switch hcpCVOConditions[conditionType].Status {
case metav1.ConditionTrue:
status = metav1.ConditionFalse
case metav1.ConditionFalse:
status = metav1.ConditionTrue
}
hcCVOCondition.Status = status
}
}
meta.SetStatusCondition(&hcluster.Status.Conditions, *hcCVOCondition)
}
// Copy the Degraded condition on the hostedcontrolplane
{
condition := &metav1.Condition{
Type: string(hyperv1.HostedClusterDegraded),
Status: metav1.ConditionUnknown,
Reason: hyperv1.StatusUnknownReason,
Message: "The hosted control plane is not found",
ObservedGeneration: hcluster.Generation,
}
if hcp != nil {
degradedCondition := meta.FindStatusCondition(hcp.Status.Conditions, string(hyperv1.HostedControlPlaneDegraded))
if degradedCondition != nil {
condition = degradedCondition
condition.Type = string(hyperv1.HostedClusterDegraded)
if condition.Status == metav1.ConditionFalse {
condition.Message = "The hosted cluster is not degraded"
}
}
}
condition.ObservedGeneration = hcluster.Generation
meta.SetStatusCondition(&hcluster.Status.Conditions, *condition)
}
// Copy the ValidKubeVirtInfraNetworkMTU condition from the HostedControlPlane
if hcluster.Spec.Platform.Type == hyperv1.KubevirtPlatform {
if hcp != nil {
validMtuCondCreated := meta.FindStatusCondition(hcp.Status.Conditions, string(hyperv1.ValidKubeVirtInfraNetworkMTU))
if validMtuCondCreated != nil {
validMtuCondCreated.ObservedGeneration = hcluster.Generation
meta.SetStatusCondition(&hcluster.Status.Conditions, *validMtuCondCreated)
}
}
}
// Copy conditions from hostedcontrolplane
{
hcpConditions := []hyperv1.ConditionType{
hyperv1.EtcdAvailable,
hyperv1.KubeAPIServerAvailable,
hyperv1.InfrastructureReady,
hyperv1.ExternalDNSReachable,
hyperv1.ValidHostedControlPlaneConfiguration,
hyperv1.ValidReleaseInfo,
}
for _, conditionType := range hcpConditions {
condition := &metav1.Condition{
Type: string(conditionType),
Status: metav1.ConditionUnknown,
Reason: hyperv1.StatusUnknownReason,
Message: "The hosted control plane is not found",
ObservedGeneration: hcluster.Generation,
}
if hcp != nil {
hcpCondition := meta.FindStatusCondition(hcp.Status.Conditions, string(conditionType))
if hcpCondition != nil {
condition = hcpCondition
} else {
condition.Message = "Condition not found in the HCP"
}
}
condition.ObservedGeneration = hcluster.Generation
meta.SetStatusCondition(&hcluster.Status.Conditions, *condition)
}
}
// Copy the platform status from the hostedcontrolplane
if hcp != nil {
hcluster.Status.Platform = hcp.Status.Platform
}
// Copy the AWSDefaultSecurityGroupCreated condition from the hostedcontrolplane
if hcluster.Spec.Platform.Type == hyperv1.AWSPlatform {
if hcp != nil {
sgCreated := meta.FindStatusCondition(hcp.Status.Conditions, string(hyperv1.AWSDefaultSecurityGroupCreated))
if sgCreated != nil {
sgCreated.ObservedGeneration = hcluster.Generation
meta.SetStatusCondition(&hcluster.Status.Conditions, *sgCreated)
}
validKMSConfig := meta.FindStatusCondition(hcp.Status.Conditions, string(hyperv1.ValidAWSKMSConfig))
if validKMSConfig != nil {
validKMSConfig.ObservedGeneration = hcluster.Generation
meta.SetStatusCondition(&hcluster.Status.Conditions, *validKMSConfig)
}
}
}
if hcluster.Spec.Platform.Type == hyperv1.AzurePlatform {
if hcp != nil {
validKMSConfig := meta.FindStatusCondition(hcp.Status.Conditions, string(hyperv1.ValidAzureKMSConfig))
if validKMSConfig != nil {
validKMSConfig.ObservedGeneration = hcluster.Generation
meta.SetStatusCondition(&hcluster.Status.Conditions, *validKMSConfig)
}
}
}
// Reconcile unmanaged etcd client tls secret validation error status. Note only update status on validation error case to
// provide clear status to the user on the resource without having to look at operator logs.
{
if hcluster.Spec.Etcd.ManagementType == hyperv1.Unmanaged {
unmanagedEtcdTLSClientSecret := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Namespace: hcluster.GetNamespace(),
Name: hcluster.Spec.Etcd.Unmanaged.TLS.ClientSecret.Name,
},
}
if err := r.Client.Get(ctx, client.ObjectKeyFromObject(unmanagedEtcdTLSClientSecret), unmanagedEtcdTLSClientSecret); err != nil {
if apierrors.IsNotFound(err) {
unmanagedEtcdTLSClientSecret = nil
} else {
return ctrl.Result{}, fmt.Errorf("failed to get unmanaged etcd tls secret: %w", err)
}
}
meta.SetStatusCondition(&hcluster.Status.Conditions, computeUnmanagedEtcdAvailability(hcluster, unmanagedEtcdTLSClientSecret))
}
}
// Set the Available condition
// TODO: This is really setting something that could be more granular like
// HostedControlPlaneAvailable, and then the HostedCluster high-level Available
// condition could be computed as a function of the granular ThingAvailable
// conditions (so that it could incorporate e.g. HostedControlPlane and IgnitionServer
// availability in the ultimate HostedCluster Available condition)
{
availableCondition := computeHostedClusterAvailability(hcluster, hcp)
_, isHasBeenAvailableAnnotationSet := hcluster.Annotations[hcmetrics.HasBeenAvailableAnnotation]
meta.SetStatusCondition(&hcluster.Status.Conditions, availableCondition)
if availableCondition.Status == metav1.ConditionTrue && !isHasBeenAvailableAnnotationSet {
original := hcluster.DeepCopy()
if hcluster.Annotations == nil {
hcluster.Annotations = make(map[string]string)
}
hcluster.Annotations[hcmetrics.HasBeenAvailableAnnotation] = "true"
if err := r.Patch(ctx, hcluster, client.MergeFromWithOptions(original)); err != nil {
return ctrl.Result{}, fmt.Errorf("cannot patch hosted cluster with has been available annotation: %w", err)
}
}
}
// Copy AWSEndpointAvailable and AWSEndpointServiceAvailable conditions from the AWSEndpointServices.
if hcluster.Spec.Platform.Type == hyperv1.AWSPlatform {
hcpNamespace := manifests.HostedControlPlaneNamespace(hcluster.Namespace, hcluster.Name)
var awsEndpointServiceList hyperv1.AWSEndpointServiceList
if err := r.List(ctx, &awsEndpointServiceList, &client.ListOptions{Namespace: hcpNamespace}); err != nil {
condition := metav1.Condition{
Type: string(hyperv1.AWSEndpointAvailable),
Status: metav1.ConditionUnknown,
Reason: hyperv1.NotFoundReason,
Message: fmt.Sprintf("error listing awsendpointservices in namespace %s: %v", hcpNamespace, err),
}
meta.SetStatusCondition(&hcluster.Status.Conditions, condition)
} else {
meta.SetStatusCondition(&hcluster.Status.Conditions, computeAWSEndpointServiceCondition(awsEndpointServiceList, hyperv1.AWSEndpointAvailable))
meta.SetStatusCondition(&hcluster.Status.Conditions, computeAWSEndpointServiceCondition(awsEndpointServiceList, hyperv1.AWSEndpointServiceAvailable))
}
}
// Set ValidConfiguration condition
{
condition := metav1.Condition{
Type: string(hyperv1.ValidHostedClusterConfiguration),
ObservedGeneration: hcluster.Generation,
}
if err := r.validateConfigAndClusterCapabilities(ctx, hcluster); err != nil {
condition.Status = metav1.ConditionFalse
condition.Message = err.Error()
condition.Reason = hyperv1.InvalidConfigurationReason
} else {
condition.Status = metav1.ConditionTrue
condition.Message = "Configuration passes validation"
condition.Reason = hyperv1.AsExpectedReason
}
meta.SetStatusCondition(&hcluster.Status.Conditions, condition)
}
// Set SupportedHostedCluster condition
{
condition := metav1.Condition{
Type: string(hyperv1.SupportedHostedCluster),
ObservedGeneration: hcluster.Generation,
}
if err := r.validateHostedClusterSupport(hcluster); err != nil {
condition.Status = metav1.ConditionFalse
condition.Message = err.Error()
condition.Reason = hyperv1.UnsupportedHostedClusterReason
} else {
condition.Status = metav1.ConditionTrue
condition.Message = "HostedCluster is supported by operator configuration"
condition.Reason = hyperv1.AsExpectedReason
}
meta.SetStatusCondition(&hcluster.Status.Conditions, condition)
}
// Set Ignition Server endpoint
{
serviceStrategy := servicePublishingStrategyByType(hcluster, hyperv1.Ignition)
if serviceStrategy == nil {
// We don't return the error here as reconciling won't solve the input problem.
// An update event will trigger reconciliation.
log.Error(fmt.Errorf("ignition server service strategy not specified"), "")
return ctrl.Result{}, nil
}
switch serviceStrategy.Type {
case hyperv1.Route:
if serviceStrategy.Route != nil && serviceStrategy.Route.Hostname != "" {
hcluster.Status.IgnitionEndpoint = serviceStrategy.Route.Hostname
} else {
ignitionServerRoute := ignitionserver.Route(controlPlaneNamespace.GetName())
if err := r.Client.Get(ctx, client.ObjectKeyFromObject(ignitionServerRoute), ignitionServerRoute); err != nil {
if !apierrors.IsNotFound(err) {
return ctrl.Result{}, fmt.Errorf("failed to get ignitionServerRoute: %w", err)
}
}
if ignitionServerRoute.Spec.Host != "" {
hcluster.Status.IgnitionEndpoint = ignitionServerRoute.Spec.Host
}
}
case hyperv1.NodePort:
if serviceStrategy.NodePort == nil {
// We don't return the error here as reconciling won't solve the input problem.
// An update event will trigger reconciliation.
log.Error(fmt.Errorf("nodeport metadata not specified for ignition service"), "")
return ctrl.Result{}, nil
}
ignitionService := ignitionserver.ProxyService(controlPlaneNamespace.GetName())
if err = r.Client.Get(ctx, client.ObjectKeyFromObject(ignitionService), ignitionService); err != nil {
if !apierrors.IsNotFound(err) {
return ctrl.Result{}, fmt.Errorf("failed to get ignition proxy service: %w", err)
} else {
// ignition-server-proxy service not found, possible IBM platform or older CPO that doesn't create the service
ignitionService = ignitionserver.Service(controlPlaneNamespace.GetName())
if err = r.Client.Get(ctx, client.ObjectKeyFromObject(ignitionService), ignitionService); err != nil {
if !apierrors.IsNotFound(err) {
return ctrl.Result{}, fmt.Errorf("failed to get ignition service: %w", err)
}
}
}
}
if err == nil && serviceFirstNodePortAvailable(ignitionService) {
hcluster.Status.IgnitionEndpoint = fmt.Sprintf("%s:%d", serviceStrategy.NodePort.Address, ignitionService.Spec.Ports[0].NodePort)
}
default:
// We don't return the error here as reconciling won't solve the input problem.
// An update event will trigger reconciliation.
log.Error(fmt.Errorf("unknown service strategy type for ignition service: %s", serviceStrategy.Type), "")
return ctrl.Result{}, nil
}
}
// Set the Control Plane and OAuth endpoints URL
{
if hcp != nil {
hcluster.Status.ControlPlaneEndpoint = hcp.Status.ControlPlaneEndpoint
// TODO: (cewong) Remove this hack when we no longer need to support HostedControlPlanes that report
// the wrong port for the route strategy.
if isAPIServerRoute(hcluster) {
hcluster.Status.ControlPlaneEndpoint.Port = 443
}
hcluster.Status.OAuthCallbackURLTemplate = hcp.Status.OAuthCallbackURLTemplate
}
}
// Set the ignition server availability condition by checking its deployment.
{
// Assume the server is unavailable unless proven otherwise.
newCondition := metav1.Condition{
Type: string(hyperv1.IgnitionEndpointAvailable),
Status: metav1.ConditionUnknown,
Reason: hyperv1.StatusUnknownReason,
}
// Check to ensure the deployment exists and is available.
deployment := ignitionserver.Deployment(controlPlaneNamespace.Name)
if err := r.Client.Get(ctx, client.ObjectKeyFromObject(deployment), deployment); err != nil {
if apierrors.IsNotFound(err) {
newCondition = metav1.Condition{
Type: string(hyperv1.IgnitionEndpointAvailable),
Status: metav1.ConditionFalse,
Reason: hyperv1.NotFoundReason,
Message: "Ignition server deployment not found",
}
} else {
return ctrl.Result{}, fmt.Errorf("failed to get ignition server deployment: %w", err)
}
} else {
// Assume the deployment is unavailable until proven otherwise.
newCondition = metav1.Condition{
Type: string(hyperv1.IgnitionEndpointAvailable),
Status: metav1.ConditionFalse,
Reason: hyperv1.WaitingForAvailableReason,
Message: "Ignition server deployment is not yet available",
}
for _, cond := range deployment.Status.Conditions {
if cond.Type == appsv1.DeploymentAvailable && cond.Status == corev1.ConditionTrue {
newCondition = metav1.Condition{
Type: string(hyperv1.IgnitionEndpointAvailable),
Status: metav1.ConditionTrue,
Reason: hyperv1.AsExpectedReason,
Message: "Ignition server deployment is available",
}
break
}
}
}
newCondition.ObservedGeneration = hcluster.Generation
meta.SetStatusCondition(&hcluster.Status.Conditions, newCondition)
}
meta.SetStatusCondition(&hcluster.Status.Conditions, hyperutil.GenerateReconciliationActiveCondition(hcluster.Spec.PausedUntil, hcluster.Generation))
// Set ValidReleaseImage condition
{
condition := meta.FindStatusCondition(hcluster.Status.Conditions, string(hyperv1.ValidReleaseImage))
// This check can be expensive looking up release image versions
// (hopefully they are cached). Skip if we have already observed for
// this generation.
if condition == nil || condition.ObservedGeneration != hcluster.Generation || condition.Status != metav1.ConditionTrue {
condition := metav1.Condition{
Type: string(hyperv1.ValidReleaseImage),
ObservedGeneration: hcluster.Generation,
}
err := r.validateReleaseImage(ctx, hcluster, releaseProvider)
if err != nil {