-
Notifications
You must be signed in to change notification settings - Fork 556
Expand file tree
/
Copy pathhostedcluster_controller.go
More file actions
5919 lines (5299 loc) · 241 KB
/
Copy pathhostedcluster_controller.go
File metadata and controls
5919 lines (5299 loc) · 241 KB
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/tls"
"errors"
"fmt"
"maps"
"net"
"net/netip"
"os"
"reflect"
"strconv"
"strings"
"time"
hyperv1 "github.com/openshift/hypershift/api/hypershift/v1beta1"
hyperkarpenterv1 "github.com/openshift/hypershift/api/karpenter/v1"
"github.com/openshift/hypershift/api/util/configrefs"
"github.com/openshift/hypershift/cmd/util"
"github.com/openshift/hypershift/control-plane-operator/controllers/hostedcontrolplane/imageprovider"
cpomanifests "github.com/openshift/hypershift/control-plane-operator/controllers/hostedcontrolplane/manifests"
capimanagerv2 "github.com/openshift/hypershift/control-plane-operator/controllers/hostedcontrolplane/v2/capi_manager"
capiproviderv2 "github.com/openshift/hypershift/control-plane-operator/controllers/hostedcontrolplane/v2/capi_provider"
cpov2 "github.com/openshift/hypershift/control-plane-operator/controllers/hostedcontrolplane/v2/controlplaneoperator"
"github.com/openshift/hypershift/control-plane-pki-operator/certificates"
"github.com/openshift/hypershift/hypershift-operator/controllers/hostedcluster/internal/platform"
platformaws "github.com/openshift/hypershift/hypershift-operator/controllers/hostedcluster/internal/platform/aws"
"github.com/openshift/hypershift/hypershift-operator/controllers/hostedcluster/internal/proxy"
hcmetrics "github.com/openshift/hypershift/hypershift-operator/controllers/hostedcluster/metrics"
validations "github.com/openshift/hypershift/hypershift-operator/controllers/hostedcluster/validations"
"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"
etcdrecoverymanifests "github.com/openshift/hypershift/hypershift-operator/controllers/manifests/etcdrecovery"
"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/awsapi"
"github.com/openshift/hypershift/support/azureutil"
"github.com/openshift/hypershift/support/capabilities"
"github.com/openshift/hypershift/support/certs"
"github.com/openshift/hypershift/support/config"
controlplanecomponent "github.com/openshift/hypershift/support/controlplane-component"
"github.com/openshift/hypershift/support/gcpapi"
"github.com/openshift/hypershift/support/globalconfig"
"github.com/openshift/hypershift/support/infraid"
"github.com/openshift/hypershift/support/k8sutil"
"github.com/openshift/hypershift/support/metrics"
"github.com/openshift/hypershift/support/netutil"
"github.com/openshift/hypershift/support/oidc"
"github.com/openshift/hypershift/support/podspec"
"github.com/openshift/hypershift/support/releaseinfo"
"github.com/openshift/hypershift/support/secretproviderclass"
"github.com/openshift/hypershift/support/supportedversion"
"github.com/openshift/hypershift/support/upsert"
hyperutil "github.com/openshift/hypershift/support/util"
supportvalidations "github.com/openshift/hypershift/support/validations"
configv1 "github.com/openshift/api/config/v1"
routev1 "github.com/openshift/api/route/v1"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/s3"
s3types "github.com/aws/aws-sdk-go-v2/service/s3/types"
appsv1 "k8s.io/api/apps/v1"
batchv1 "k8s.io/api/batch/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"
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"
utilrand "k8s.io/apimachinery/pkg/util/rand"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/util/validation"
"k8s.io/apimachinery/pkg/util/validation/field"
"k8s.io/client-go/util/workqueue"
"k8s.io/utils/clock"
"k8s.io/utils/ptr"
capov1alpha1 "sigs.k8s.io/cluster-api-provider-openstack/api/v1alpha1"
capiv1 "sigs.k8s.io/cluster-api/api/core/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"
"github.com/blang/semver"
"github.com/go-logr/logr"
"github.com/google/uuid"
orcv1alpha1 "github.com/k-orc/openstack-resource-controller/v2/api/v1alpha1"
prometheusoperatorv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
"gopkg.in/ini.v1"
)
const (
HostedClusterFinalizer = "hypershift.openshift.io/finalizer"
ControlPlaneComponentFinalizer = "hypershift.openshift.io/component-finalizer"
clusterDeletionRequeueDuration = 5 * time.Second
ReportingGracePeriodRequeueDuration = 25 * time.Second
ImageStreamCAPI = "cluster-capi-controllers"
ImageStreamAutoscalerImage = "cluster-autoscaler"
controlPlaneOperatorSubcommandsLabel = "io.openshift.hypershift.control-plane-operator-subcommands"
controlPlaneOperatorSupportsKASCustomKubeconfigLabel = "io.openshift.hypershift.control-plane-operator-supports-kas-custom-kubeconfig"
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"
defaultToControlPlaneV2Label = "io.openshift.hypershift.control-plane-operator.v2-isdefault"
apiOpenShiftComLabelPrefix = "api.openshift.com/"
etcdEncKeyPostfix = "-etcd-encryption-key"
jobHostedClusterNameLabel = "hypershift.openshift.io/cluster-name"
jobHostedClusterNamespaceLabel = "hypershift.openshift.io/cluster-namespace"
etcdCheckRequeueInterval = 10 * time.Second
awsEndpointDeletionGracePeriod = 10 * time.Minute
previouslySyncedRestartDateAnnotation = "hypershift.openshift.io/previous-restart-date"
kasServingCertHashAnnotation = "hypershift.openshift.io/kas-serving-cert-hash"
referencedResourceAnnotationPrefix = "referenced-resource.hypershift.openshift.io/"
)
var (
// NoopReconcile is just a default mutation function that does nothing.
NoopReconcile controllerutil.MutateFn = func() error { return nil }
CAPIComponents = []string{capimanagerv2.ComponentName, capiproviderv2.ComponentName}
)
// 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 awsapi.S3API
GCPOIDCStorageBucketName string
GCSClient gcpapi.GCSAPI
MetricsSet metrics.MetricsSet
SREConfigHash string
OperatorNamespace string
RegistryProvider globalconfig.RegistryProvider
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
EnableEtcdRecovery bool
ReconcileLegacy bool
FeatureSet configv1.FeatureSet
OpenShiftTrustedCAFilePath string
// ProbeSharedIngressEndpoint tests whether a public endpoint is reachable
// via the shared ingress. Defaults to probeSharedIngressEndpoint. Override
// in tests to avoid real network calls.
ProbeSharedIngressEndpoint func(context context.Context, serviceIP string, servicePort int, kasHostname string) bool
// HCPEgressBlockCIDRs, when non-empty, provides a static list of CIDRs to
// block in HCP namespace egress NetworkPolicies. These replace the
// dynamically-discovered management cluster KAS endpoint IPs, eliminating
// NetworkPolicy churn during KAS rolling restarts that can trigger OVN
// port-group reconciliation races and cause traffic drops to HCP routers.
HCPEgressBlockCIDRs []string
}
// +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.NewTypedItemExponentialFailureRateLimiter[reconcile.Request](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)
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{
&hyperv1.HostedControlPlane{},
&appsv1.Deployment{},
&prometheusoperatorv1.PodMonitor{},
&networkingv1.NetworkPolicy{},
&rbacv1.ClusterRole{},
&rbacv1.ClusterRoleBinding{},
&rbacv1.Role{},
&rbacv1.RoleBinding{},
&corev1.ConfigMap{},
&corev1.Secret{},
&corev1.Namespace{},
&corev1.ServiceAccount{},
&corev1.Service{},
//nolint:staticcheck // SA1019: corev1.Endpoints is intentionally used for backward compatibility
&corev1.Endpoints{},
&hyperv1.NodePool{},
}
// Watch based on platforms installed
if platformsInstalled := os.Getenv("PLATFORMS_INSTALLED"); len(platformsInstalled) > 0 {
managedResources = append(managedResources, k8sutil.GetHostedClusterManagedResources(platformsInstalled)...)
} else {
managedResources = append(managedResources, k8sutil.BaseResources...)
managedResources = append(managedResources, k8sutil.AWSResources...)
managedResources = append(managedResources, k8sutil.AzureResources...)
managedResources = append(managedResources, k8sutil.IBMCloudResources...)
managedResources = append(managedResources, k8sutil.KubevirtResources...)
managedResources = append(managedResources, k8sutil.AgentResources...)
managedResources = append(managedResources, k8sutil.OpenStackResources...)
}
// Only watch managed Azure resources if the HO is explicitly configured to do so. Otherwise, the HO will fail to
// reconcile HostedClusters since some CRs are only installed in the managed Azure use case.
if azureutil.IsAroHCP() {
managedResources = append(managedResources, k8sutil.ManagedAzure...)
}
// Watch if etcd recovery is enabled
if r.EnableEtcdRecovery {
managedResources = append(managedResources, []client.Object{
&appsv1.StatefulSet{},
&batchv1.Job{},
}...)
}
// Watch based on Routes capability
if r.ManagementClusterCapabilities.Has(capabilities.CapabilityRoute) {
managedResources = append(managedResources, &routev1.Route{})
}
// Watch based on Ingress capability
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)
// 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 if r.ReconcileLegacy {
res, err = r.reconcileLegacy(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
}
//nolint:gocyclo
func (r *HostedClusterReconciler) reconcile(ctx context.Context, req ctrl.Request, log logr.Logger, hcluster *hyperv1.HostedCluster) (ctrl.Result, error) {
// Phase 0: Initialization — get the HostedControlPlane and set up the control plane namespace.
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
}
}
// Phase 1: Bubble up pre-deletion conditions from HCP.
// These conditions are set even during deletion so consumers have clear signals.
// 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 {
updated := false
var validIdentityProviderCondition *metav1.Condition
if hcp != nil {
validIdentityProviderCondition = meta.FindStatusCondition(hcp.Status.Conditions, string(hyperv1.ValidAWSIdentityProvider))
}
// condition not found in HCP or HCP has been deleted
if validIdentityProviderCondition == nil {
updated = meta.SetStatusCondition(&hcluster.Status.Conditions, metav1.Condition{
Type: string(hyperv1.ValidAWSIdentityProvider),
Status: metav1.ConditionUnknown,
Reason: hyperv1.StatusUnknownReason,
ObservedGeneration: hcluster.Generation,
})
} else {
validIdentityProviderCondition.ObservedGeneration = hcluster.Generation
updated = meta.SetStatusCondition(&hcluster.Status.Conditions, *validIdentityProviderCondition)
}
if updated {
// 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 to report blocking objects on deletion.
if condition, changed := computeAWSDefaultSGDeletedCondition(hcluster, hcp); changed {
meta.SetStatusCondition(&hcluster.Status.Conditions, *condition)
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.IsZero() {
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)
}
}
}
}
// Phase 2: Deletion handling — if the cluster is being deleted, clean up and return early.
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 !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 conjunction 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)
}
}
// Remove any referenced resource annotations for this hosted cluster from secrets and configmaps
deleteReferencedResourceAnnotation := func(obj client.Object) error {
annotations := obj.GetAnnotations()
if annotations == nil {
return nil
}
key := referencedResourceAnnotationPrefix + hcluster.Name
if _, ok := annotations[key]; !ok {
return nil
}
delete(annotations, key)
obj.SetAnnotations(annotations)
if err := r.Update(ctx, obj); err != nil {
return err
}
return nil
}
var secretList corev1.SecretList
if err := r.List(ctx, &secretList, client.InNamespace(hcluster.Namespace)); err != nil {
return ctrl.Result{}, fmt.Errorf("failed to list secrets: %w", err)
}
for _, secret := range secretList.Items {
if err := deleteReferencedResourceAnnotation(&secret); err != nil {
return ctrl.Result{}, fmt.Errorf("failed to delete referenced resource annotation on secret: %w", err)
}
}
var configmapList corev1.ConfigMapList
if err := r.List(ctx, &configmapList, client.InNamespace(hcluster.Namespace)); err != nil {
return ctrl.Result{}, fmt.Errorf("failed to list configmaps: %w", err)
}
for _, configmap := range configmapList.Items {
if err := deleteReferencedResourceAnnotation(&configmap); err != nil {
return ctrl.Result{}, fmt.Errorf("failed to delete referenced resource annotation on configmap: %w", err)
}
}
if hcDestroyGracePeriod > 0 {
if hostedClusterDestroyedCondition == nil || hostedClusterDestroyedCondition.Status != metav1.ConditionTrue {
hostedClusterDestroyedCondition = &metav1.Condition{
Type: string(hyperv1.HostedClusterDestroyed),
Status: metav1.ConditionTrue,
Message: fmt.Sprintf("Grace period set: %v", hcDestroyGracePeriod),
Reason: hyperv1.WaitingForGracePeriodReason,
LastTransitionTime: metav1.NewTime(r.Clock.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
}
elapsed := r.Clock.Since(hostedClusterDestroyedCondition.LastTransitionTime.Time)
if elapsed < hcDestroyGracePeriod {
log.Info("Waiting for grace period", "gracePeriod", hcDestroyGracePeriod)
return ctrl.Result{RequeueAfter: hcDestroyGracePeriod - elapsed}, 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
}
// Phase 3: Fix up conversion and reconcile platform defaults.
originalSpec := hcluster.Spec.DeepCopy()
// Reconcile converted AWS roles.
if hcluster.Spec.Platform.AWS != nil {
if err := r.dereferenceAWSRoles(ctx, hcluster.Name, &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, hcluster.Name, 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)
}
// Phase 4: Update status conditions and persist.
// 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
err = r.RegistryProvider.Reconcile(ctx, r.Client)
if err != nil {
return ctrl.Result{}, err
}
releaseProvider := r.RegistryProvider.GetReleaseProvider()
registryClientImageMetadataProvider := r.RegistryProvider.GetMetadataProvider()
// Set kubeconfig status unconditionally — all supported CPO versions expose the custom kubeconfig.
if len(hcluster.Spec.KubeAPIServerDNSName) > 0 {
CustomKubeconfigSecret := manifests.KubeConfigExternalSecret(hcluster.Namespace, hcluster.Name)
err := r.Client.Get(ctx, client.ObjectKeyFromObject(CustomKubeconfigSecret), CustomKubeconfigSecret)
if err != nil {
if !apierrors.IsNotFound(err) {
return ctrl.Result{}, fmt.Errorf("failed to reconcile external kubeconfig secret: %w", err)
}
} else {
hcluster.Status.CustomKubeconfig = &corev1.LocalObjectReference{Name: CustomKubeconfigSecret.Name}
}
}
// 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.ClusterVersionRetrievedUpdates: 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.ClusterVersionRetrievedUpdates: meta.FindStatusCondition(hcp.Status.Conditions, string(hyperv1.ClusterVersionRetrievedUpdates)),
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
}
}
if hcCVOCondition.Type == string(hyperv1.ClusterVersionRetrievedUpdates) && hcCVOCondition.Reason == hyperv1.StatusUnknownReason {
// until all HostedControlPlane controllers understand how to propagate this condition, avoid bothering folks with unknown status in HostedCluster conditions.
meta.RemoveStatusCondition(&hcluster.Status.Conditions, string(hyperv1.ClusterVersionRetrievedUpdates))
continue
}
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)
}
}
if err := r.syncKVLiveMigratableCondition(ctx, hcluster); err != nil {
return ctrl.Result{}, fmt.Errorf("failed to update condition: %w", err)
}
}
// Copy conditions from hostedcontrolplane
{
hcpConditions := []hyperv1.ConditionType{
hyperv1.EtcdAvailable,
hyperv1.KubeAPIServerAvailable,
hyperv1.InfrastructureReady,
hyperv1.ExternalDNSReachable,
hyperv1.ValidHostedControlPlaneConfiguration,
hyperv1.ValidReleaseInfo,
hyperv1.ValidIDPConfiguration,
hyperv1.HostedClusterRestoredFromBackup,
hyperv1.DataPlaneConnectionAvailable,
hyperv1.ControlPlaneConnectionAvailable,
hyperv1.EtcdBackupSucceeded,
hyperv1.ConfigOperatorReconciliationSucceeded,
}
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
hcluster.Status.AutoNode = hcp.Status.AutoNode
}
// Copy the secret encryption status from the hostedcontrolplane
if hcp != nil {
hcp.Status.SecretEncryption.DeepCopyInto(&hcluster.Status.SecretEncryption)
}
// Copy the control plane version status from the hostedcontrolplane
propagateControlPlaneVersion(hcluster, hcp)
// Set the AutoNodeEnabled condition reflecting both spec intent and actual component rollout progress.
autoNodeCondition, autoNodeProgressing := r.reconcileAutoNodeEnabledCondition(ctx, hcluster, controlPlaneNamespace.Name)
meta.SetStatusCondition(&hcluster.Status.Conditions, autoNodeCondition)
// 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)
}
}
}
// Copy the EtcdDataEncryptionUpToDate condition from the HostedControlPlane
if hcp != nil {
encryptionCond := meta.FindStatusCondition(hcp.Status.Conditions, string(hyperv1.EtcdDataEncryptionUpToDate))
if encryptionCond != nil {
encryptionCond.ObservedGeneration = hcluster.Generation
meta.SetStatusCondition(&hcluster.Status.Conditions, *encryptionCond)
}
}
// 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))
}
}
// Copy GCPEndpointAvailable and GCPServiceAttachmentAvailable conditions from the GCPPrivateServiceConnect resources.
if hcluster.Spec.Platform.Type == hyperv1.GCPPlatform {
hcpNamespace := manifests.HostedControlPlaneNamespace(hcluster.Namespace, hcluster.Name)
var gcpPSCList hyperv1.GCPPrivateServiceConnectList
if err := r.List(ctx, &gcpPSCList, &client.ListOptions{Namespace: hcpNamespace}); err != nil {
condition := metav1.Condition{
Type: string(hyperv1.GCPEndpointAvailable),
Status: metav1.ConditionUnknown,
Reason: hyperv1.NotFoundReason,
Message: fmt.Sprintf("error listing GCPPrivateServiceConnect in namespace %s: %v", hcpNamespace, err),
}
meta.SetStatusCondition(&hcluster.Status.Conditions, condition)
} else {
meta.SetStatusCondition(&hcluster.Status.Conditions, computeGCPPSCCondition(gcpPSCList, hyperv1.GCPEndpointAvailable))
meta.SetStatusCondition(&hcluster.Status.Conditions, computeGCPPSCCondition(gcpPSCList, hyperv1.GCPServiceAttachmentAvailable))
}
}
// Copy Azure Private Link conditions from the AzurePrivateLinkService resources.
// ARO HCP uses Swift networking, not Private Link Services.
if hcluster.Spec.Platform.Type == hyperv1.AzurePlatform && !netutil.UseSwiftNetworkingHC(hcluster) {
hcpNamespace := manifests.HostedControlPlaneNamespace(hcluster.Namespace, hcluster.Name)
var azPLSList hyperv1.AzurePrivateLinkServiceList
if err := r.List(ctx, &azPLSList, &client.ListOptions{Namespace: hcpNamespace}); err != nil {
condition := metav1.Condition{
Type: string(hyperv1.AzurePrivateLinkServiceAvailable),
Status: metav1.ConditionUnknown,
Reason: hyperv1.NotFoundReason,
Message: fmt.Sprintf("error listing AzurePrivateLinkService in namespace %s: %v", hcpNamespace, err),
}
meta.SetStatusCondition(&hcluster.Status.Conditions, condition)