-
Notifications
You must be signed in to change notification settings - Fork 297
/
resources.go
2375 lines (2126 loc) · 95.9 KB
/
resources.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
package resources
import (
"context"
"crypto/md5"
"fmt"
"reflect"
"strings"
"sync"
"time"
"github.com/openshift/hypershift/control-plane-operator/hostedclusterconfigoperator/controllers/resources/cco"
admissionregistrationv1 "k8s.io/api/admissionregistration/v1"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/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/types"
"k8s.io/apimachinery/pkg/util/errors"
"k8s.io/apimachinery/pkg/util/sets"
apiregistrationv1 "k8s.io/kube-aggregator/pkg/apis/apiregistration/v1"
"k8s.io/utils/pointer"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"
"github.com/go-logr/logr"
operatorsv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
prometheusoperatorv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
configv1 "github.com/openshift/api/config/v1"
imageregistryv1 "github.com/openshift/api/imageregistry/v1"
operatorv1 "github.com/openshift/api/operator/v1"
hyperv1 "github.com/openshift/hypershift/api/hypershift/v1beta1"
"github.com/openshift/hypershift/control-plane-operator/controllers/hostedcontrolplane"
"github.com/openshift/hypershift/control-plane-operator/controllers/hostedcontrolplane/cloud/azure"
kubevirtcsi "github.com/openshift/hypershift/control-plane-operator/controllers/hostedcontrolplane/csi/kubevirt"
"github.com/openshift/hypershift/control-plane-operator/controllers/hostedcontrolplane/cvo"
cpomanifests "github.com/openshift/hypershift/control-plane-operator/controllers/hostedcontrolplane/manifests"
alerts "github.com/openshift/hypershift/control-plane-operator/hostedclusterconfigoperator/controllers/resources/alerts"
ccm "github.com/openshift/hypershift/control-plane-operator/hostedclusterconfigoperator/controllers/resources/cloudcontrollermanager/azure"
"github.com/openshift/hypershift/control-plane-operator/hostedclusterconfigoperator/controllers/resources/crd"
"github.com/openshift/hypershift/control-plane-operator/hostedclusterconfigoperator/controllers/resources/ingress"
"github.com/openshift/hypershift/control-plane-operator/hostedclusterconfigoperator/controllers/resources/konnectivity"
"github.com/openshift/hypershift/control-plane-operator/hostedclusterconfigoperator/controllers/resources/kubeadminpassword"
"github.com/openshift/hypershift/control-plane-operator/hostedclusterconfigoperator/controllers/resources/manifests"
"github.com/openshift/hypershift/control-plane-operator/hostedclusterconfigoperator/controllers/resources/monitoring"
"github.com/openshift/hypershift/control-plane-operator/hostedclusterconfigoperator/controllers/resources/namespaces"
networkoperator "github.com/openshift/hypershift/control-plane-operator/hostedclusterconfigoperator/controllers/resources/network"
"github.com/openshift/hypershift/control-plane-operator/hostedclusterconfigoperator/controllers/resources/oapi"
"github.com/openshift/hypershift/control-plane-operator/hostedclusterconfigoperator/controllers/resources/oauth"
"github.com/openshift/hypershift/control-plane-operator/hostedclusterconfigoperator/controllers/resources/olm"
"github.com/openshift/hypershift/control-plane-operator/hostedclusterconfigoperator/controllers/resources/rbac"
"github.com/openshift/hypershift/control-plane-operator/hostedclusterconfigoperator/controllers/resources/registry"
"github.com/openshift/hypershift/control-plane-operator/hostedclusterconfigoperator/controllers/resources/storage"
"github.com/openshift/hypershift/control-plane-operator/hostedclusterconfigoperator/operator"
"github.com/openshift/hypershift/support/config"
"github.com/openshift/hypershift/support/globalconfig"
"github.com/openshift/hypershift/support/releaseinfo"
"github.com/openshift/hypershift/support/upsert"
"github.com/openshift/hypershift/support/util"
)
const (
ControllerName = "resources"
SecretHashAnnotation = "hypershift.openshift.io/kubeadmin-secret-hash"
)
var (
// deleteDNSOperatorDeploymentOnce ensures that the reconciler tries
// to delete any existing DNS operator deployment on the hosted cluster
// only once.
deleteDNSOperatorDeploymentOnce sync.Once
deleteCVORemovedResourcesOnce sync.Once
)
const azureCCMScript = `
#!/bin/bash
set -o allexport
if [[ -f /etc/kubernetes/apiserver-url.env ]]; then
source /etc/kubernetes/apiserver-url.env
fi
exec /bin/azure-cloud-node-manager \
--node-name=${NODE_NAME} \
--enable-deprecated-beta-topology-labels \
--wait-routes=false
`
type reconciler struct {
client client.Client
uncachedClient client.Client
upsert.CreateOrUpdateProvider
platformType hyperv1.PlatformType
rootCA string
clusterSignerCA string
cpClient client.Client
kubevirtInfraClient client.Client
hcpName string
hcpNamespace string
releaseProvider releaseinfo.Provider
konnectivityServerAddress string
konnectivityServerPort int32
oauthAddress string
oauthPort int32
versions map[string]string
operateOnReleaseImage string
}
// eventHandler is the handler used throughout. As this controller reconciles all kind of different resources
// it uses an empty request but always reconciles everything.
func eventHandler() handler.EventHandler {
return handler.EnqueueRequestsFromMapFunc(
func(context.Context, client.Object) []reconcile.Request {
return []reconcile.Request{{}}
})
}
func Setup(opts *operator.HostedClusterConfigOperatorConfig) error {
if err := imageregistryv1.Install(opts.Manager.GetScheme()); err != nil {
return fmt.Errorf("failed to add to scheme: %w", err)
}
uncachedClient, err := client.New(opts.Manager.GetConfig(), client.Options{
Scheme: opts.Manager.GetScheme(),
Mapper: opts.Manager.GetRESTMapper(),
WarningHandler: client.WarningHandlerOptions{
SuppressWarnings: true,
},
})
if err != nil {
return fmt.Errorf("failed to create uncached client: %w", err)
}
// if kubevirt infra config is not used, it is being set the same as the mgmt config
kubevirtInfraClient, err := client.New(opts.KubevirtInfraConfig, client.Options{
Scheme: opts.Manager.GetScheme(),
Mapper: opts.Manager.GetRESTMapper(),
WarningHandler: client.WarningHandlerOptions{
SuppressWarnings: true,
},
})
if err != nil {
return fmt.Errorf("failed to create kubevirt infra uncached client: %w", err)
}
c, err := controller.New(ControllerName, opts.Manager, controller.Options{Reconciler: &reconciler{
client: opts.Manager.GetClient(),
uncachedClient: uncachedClient,
CreateOrUpdateProvider: opts.TargetCreateOrUpdateProvider,
platformType: opts.PlatformType,
rootCA: opts.InitialCA,
clusterSignerCA: opts.ClusterSignerCA,
cpClient: opts.CPCluster.GetClient(),
kubevirtInfraClient: kubevirtInfraClient,
hcpName: opts.HCPName,
hcpNamespace: opts.Namespace,
releaseProvider: opts.ReleaseProvider,
konnectivityServerAddress: opts.KonnectivityAddress,
konnectivityServerPort: opts.KonnectivityPort,
oauthAddress: opts.OAuthAddress,
oauthPort: opts.OAuthPort,
versions: opts.Versions,
operateOnReleaseImage: opts.OperateOnReleaseImage,
}})
if err != nil {
return fmt.Errorf("failed to construct controller: %w", err)
}
resourcesToWatch := []client.Object{
&imageregistryv1.Config{},
&corev1.ConfigMap{},
&corev1.Namespace{},
&corev1.Secret{},
&corev1.Service{},
&corev1.Endpoints{},
&corev1.PersistentVolumeClaim{},
&corev1.PersistentVolume{},
&rbacv1.ClusterRole{},
&rbacv1.ClusterRoleBinding{},
&configv1.Infrastructure{},
&configv1.DNS{},
&configv1.Ingress{},
&configv1.Network{},
&configv1.Proxy{},
&configv1.Build{},
&configv1.Image{},
&configv1.Project{},
&configv1.ClusterOperator{},
&configv1.OperatorHub{},
&appsv1.DaemonSet{},
&configv1.ClusterOperator{},
&configv1.ClusterVersion{},
&apiregistrationv1.APIService{},
&operatorv1.Network{},
&admissionregistrationv1.MutatingWebhookConfiguration{},
&admissionregistrationv1.ValidatingWebhookConfiguration{},
&prometheusoperatorv1.PrometheusRule{},
&operatorv1.IngressController{},
&imageregistryv1.Config{},
}
for _, r := range resourcesToWatch {
if err := c.Watch(source.Kind(opts.Manager.GetCache(), r), eventHandler()); err != nil {
return fmt.Errorf("failed to watch %T: %w", r, err)
}
}
if err := c.Watch(source.Kind(opts.CPCluster.GetCache(), &hyperv1.HostedControlPlane{}), eventHandler()); err != nil {
return fmt.Errorf("failed to watch HostedControlPlane: %w", err)
}
if err := c.Watch(source.Kind(opts.CPCluster.GetCache(), &corev1.Secret{ObjectMeta: metav1.ObjectMeta{
Name: manifests.PullSecret(opts.Namespace).Name,
Namespace: opts.Namespace,
},
}), eventHandler()); err != nil {
return fmt.Errorf("failed to watch HCP pullsecret: %w", err)
}
return nil
}
func (r *reconciler) Reconcile(ctx context.Context, _ ctrl.Request) (ctrl.Result, error) {
log := ctrl.LoggerFrom(ctx)
log.Info("Reconciling")
hcp := manifests.HostedControlPlane(r.hcpNamespace, r.hcpName)
if err := r.cpClient.Get(ctx, client.ObjectKeyFromObject(hcp), hcp); err != nil {
return ctrl.Result{}, fmt.Errorf("failed to get hosted control plane %s/%s: %w", r.hcpNamespace, r.hcpName, err)
}
if !hcp.DeletionTimestamp.IsZero() {
if shouldCleanupCloudResources(hcp) {
log.Info("Cleaning up hosted cluster cloud resources")
return r.destroyCloudResources(ctx, hcp)
}
return ctrl.Result{}, nil
}
if isPaused, duration := util.IsReconciliationPaused(log, hcp.Spec.PausedUntil); isPaused {
log.Info("Reconciliation paused", "pausedUntil", *hcp.Spec.PausedUntil)
return ctrl.Result{RequeueAfter: duration}, nil
}
if r.operateOnReleaseImage != "" && r.operateOnReleaseImage != hcp.Spec.ReleaseImage {
log.Info("releaseImage is " + hcp.Spec.ReleaseImage + ", but this operator is configured for " + r.operateOnReleaseImage + ", skipping reconciliation")
return ctrl.Result{}, nil
}
pullSecret := manifests.PullSecret(hcp.Namespace)
if err := r.cpClient.Get(ctx, client.ObjectKeyFromObject(pullSecret), pullSecret); err != nil {
return ctrl.Result{}, fmt.Errorf("failed to get pull secret: %w", err)
}
releaseImage, err := r.releaseProvider.Lookup(ctx, hcp.Spec.ReleaseImage, pullSecret.Data[corev1.DockerConfigJsonKey])
if err != nil {
return ctrl.Result{}, fmt.Errorf("failed to get lookup release image %s: %w", hcp.Spec.ReleaseImage, err)
}
var errs []error
log.Info("reconciling guest cluster crds")
if err := r.reconcileCRDs(ctx); err != nil {
errs = append(errs, fmt.Errorf("failed to reconcile crds: %w", err))
}
// We only keep reconciling the endpoint for existing clusters that are relying on this for nodes haproxy to work.
// Otherwise, changing the haproxy config to !=443 would result in a NodePool rollout which want to avoid for existing clusters.
// Existing clusters are given the *hcp.Spec.Networking.APIServer.Port == 443 semantic as we were enforcing this default previously,
// and it's a now a forbidden operation.
if hcp.Spec.Networking.APIServer != nil && hcp.Spec.Networking.APIServer.Port != nil &&
*hcp.Spec.Networking.APIServer.Port == 443 {
log.Info("reconciling kubernetes.default endpoints")
endpoints := manifests.APIServerEndpoints()
if _, err := r.CreateOrUpdate(ctx, r.client, endpoints, func() error {
if len(endpoints.Subsets) == 0 || len(endpoints.Subsets[0].Ports) == 0 {
return nil
}
endpoints.Subsets[0].Ports[0].Port = 443
return nil
}); err != nil {
errs = append(errs, fmt.Errorf("failed to reconcile kubernetes.default endpoints: %w", err))
}
}
log.Info("reconciling install configmap")
if err := r.reconcileInstallConfigMap(ctx, releaseImage); err != nil {
errs = append(errs, fmt.Errorf("failed to reconcile install configmap: %w", err))
}
log.Info("reconciling guest cluster alert rules")
if err := r.reconcileGuestClusterAlertRules(ctx); err != nil {
errs = append(errs, fmt.Errorf("failed to reconcile guest cluster alert rules: %w", err))
}
log.Info("reconciling clusterversion")
if err := r.reconcileClusterVersion(ctx, hcp); err != nil {
errs = append(errs, fmt.Errorf("failed to reconcile clusterversion: %w", err))
}
log.Info("reconciling clusterOperators")
if err := r.reconcileClusterOperators(ctx); err != nil {
errs = append(errs, fmt.Errorf("failed to reconcile clusterOperators: %w", err))
}
log.Info("reconciling guest cluster global configuration")
if err := r.reconcileConfig(ctx, hcp); err != nil {
errs = append(errs, fmt.Errorf("failed to reconcile global configuration: %w", err))
}
log.Info("reconciling guest cluster namespaces")
if err := r.reconcileNamespaces(ctx); err != nil {
errs = append(errs, fmt.Errorf("failed to reconcile namespaces: %w", err))
}
log.Info("reconciling guest cluster rbac")
if err := r.reconcileRBAC(ctx); err != nil {
errs = append(errs, fmt.Errorf("failed to reconcile rbac: %w", err))
}
log.Info("reconciling registry config")
registryConfig := manifests.Registry()
if _, err := r.CreateOrUpdate(ctx, r.client, registryConfig, func() error {
registry.ReconcileRegistryConfig(registryConfig, r.platformType, hcp.Spec.InfrastructureAvailabilityPolicy)
return nil
}); err != nil {
errs = append(errs, fmt.Errorf("failed to reconcile imageregistry config: %w", err))
}
log.Info("reconciling ingress controller")
if err := r.reconcileIngressController(ctx, hcp); err != nil {
errs = append(errs, fmt.Errorf("failed to reconcile ingress controller: %w", err))
}
log.Info("reconciling oauth client secrets")
if err := r.reconcileOAuthClientSecrets(ctx, hcp); err != nil {
errs = append(errs, fmt.Errorf("failed to reconcile ingress controller: %w", err))
}
log.Info("reconciling kube control plane signer secret")
kubeControlPlaneSignerSecret := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Namespace: "openshift-kube-apiserver-operator",
Name: "kube-control-plane-signer",
},
}
if _, err := r.CreateOrUpdate(ctx, r.client, kubeControlPlaneSignerSecret, func() error {
kubeControlPlaneSignerSecret.Data = map[string][]byte{corev1.TLSCertKey: []byte(r.clusterSignerCA)}
return nil
}); err != nil {
errs = append(errs, fmt.Errorf("failed to reconcile the %s Secret: %w", client.ObjectKeyFromObject(kubeControlPlaneSignerSecret), err))
}
log.Info("reconciling kubelet serving CA configmap")
kubeletServingCAConfigMap := &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Namespace: "openshift-config-managed",
Name: "kubelet-serving-ca",
},
}
if _, err := r.CreateOrUpdate(ctx, r.client, kubeletServingCAConfigMap, func() error {
kubeletServingCAConfigMap.Data = map[string]string{"ca-bundle.crt": r.clusterSignerCA}
return nil
}); err != nil {
errs = append(errs, fmt.Errorf("failed to reconcile the %s ConfigMap: %w", client.ObjectKeyFromObject(kubeletServingCAConfigMap), err))
}
log.Info("reconciling konnectivity agent")
if err := r.reconcileKonnectivityAgent(ctx, hcp, releaseImage); err != nil {
errs = append(errs, fmt.Errorf("failed to reconcile konnectivity agent: %w", err))
}
log.Info("reconciling openshift apiserver apiservices")
if err := r.reconcileOpenshiftAPIServerAPIServices(ctx, hcp); err != nil {
errs = append(errs, fmt.Errorf("failed to reconcile openshift apiserver service: %w", err))
}
log.Info("reconciling openshift apiserver service")
openshiftAPIServerService := manifests.OpenShiftAPIServerClusterService()
if _, err := r.CreateOrUpdate(ctx, r.client, openshiftAPIServerService, func() error {
oapi.ReconcileClusterService(openshiftAPIServerService)
return nil
}); err != nil {
errs = append(errs, fmt.Errorf("failed to reconcile openshift apiserver service: %w", err))
}
log.Info("reconciling openshift apiserver endpoints")
if err := r.reconcileOpenshiftAPIServerEndpoints(ctx, hcp); err != nil {
errs = append(errs, fmt.Errorf("failed to reconcile openshift apiserver endpoints: %w", err))
}
if util.HCPOAuthEnabled(hcp) {
log.Info("reconciling openshift oauth apiserver apiservices")
if err := r.reconcileOpenshiftOAuthAPIServerAPIServices(ctx, hcp); err != nil {
errs = append(errs, fmt.Errorf("failed to reconcile openshift apiserver service: %w", err))
}
log.Info("reconciling openshift oauth apiserver service")
openshiftOAuthAPIServerService := manifests.OpenShiftOAuthAPIServerClusterService()
if _, err := r.CreateOrUpdate(ctx, r.client, openshiftOAuthAPIServerService, func() error {
oapi.ReconcileClusterService(openshiftOAuthAPIServerService)
return nil
}); err != nil {
errs = append(errs, fmt.Errorf("failed to reconcile openshift oauth apiserver service: %w", err))
}
log.Info("reconciling openshift oauth apiserver endpoints")
if err := r.reconcileOpenshiftOAuthAPIServerEndpoints(ctx, hcp); err != nil {
errs = append(errs, fmt.Errorf("failed to reconcile openshift apiserver endpoints: %w", err))
}
log.Info("reconciling kubeadmin password hash secret")
if err := r.reconcileKubeadminPasswordHashSecret(ctx, hcp); err != nil {
errs = append(errs, fmt.Errorf("failed to reconcile kubeadmin password hash secret: %w", err))
}
}
log.Info("reconciling kube apiserver service monitor")
kasServiceMonitor := manifests.KubeAPIServerServiceMonitor()
if _, err := r.CreateOrUpdate(ctx, r.client, kasServiceMonitor, func() error {
return monitoring.ReconcileKubeAPIServerServiceMonitor(kasServiceMonitor)
}); err != nil {
errs = append(errs, fmt.Errorf("failed to reconcile the kube apiserver service monitor: %w", err))
}
log.Info("reconciling network operator")
networkOperator := networkoperator.NetworkOperator()
if _, err := r.CreateOrUpdate(ctx, r.client, networkOperator, func() error {
networkoperator.ReconcileNetworkOperator(networkOperator, hcp.Spec.Networking.NetworkType, hcp.Spec.Platform.Type)
return nil
}); err != nil {
errs = append(errs, fmt.Errorf("failed to reconcile network operator: %w", err))
}
// Detect suboptimal MTU size on kubevirt hosted cluster with ovn-k and raise a condition in such a case
if err := networkoperator.DetectSuboptimalMTU(ctx, r.cpClient, networkOperator, hcp); err != nil {
errs = append(errs, err)
}
// this allows users to disable data collection in sensitive environments
// solves https://issues.redhat.com/browse/OCPBUGS-12208
ensureExistsReconcilationStrategy := false
if _, exists := hcp.Annotations[hyperv1.EnsureExistsPullSecretReconciliation]; exists {
ensureExistsReconcilationStrategy = true
}
log.Info("reconciling pull secret")
for _, ns := range manifests.PullSecretTargetNamespaces() {
secret := manifests.PullSecret(ns)
if _, err := r.CreateOrUpdate(ctx, r.client, secret, func() error {
if !ensureExistsReconcilationStrategy || len(secret.Data) == 0 {
secret.Data = pullSecret.Data
secret.Type = pullSecret.Type
}
return nil
}); err != nil {
errs = append(errs, fmt.Errorf("failed to reconcile pull secret at namespace %s: %w", ns, err))
}
}
log.Info("reconciling user cert CA bundle")
if err := r.reconcileUserCertCABundle(ctx, hcp); err != nil {
errs = append(errs, fmt.Errorf("failed to reconcile user cert CA bundle: %w", err))
}
if util.HCPOAuthEnabled(hcp) {
log.Info("reconciling oauth serving cert ca bundle")
if err := r.reconcileOAuthServingCertCABundle(ctx, hcp); err != nil {
errs = append(errs, fmt.Errorf("failed to reconcile oauth serving cert CA bundle: %w", err))
}
log.Info("reconciling oauth browser client")
oauthBrowserClient := manifests.OAuthServerBrowserClient()
if _, err := r.CreateOrUpdate(ctx, r.client, oauthBrowserClient, func() error {
return oauth.ReconcileBrowserClient(oauthBrowserClient, r.oauthAddress, r.oauthPort)
}); err != nil {
errs = append(errs, fmt.Errorf("failed to reconcile oauth browser client: %w", err))
}
log.Info("reconciling oauth challenging client")
oauthChallengingClient := manifests.OAuthServerChallengingClient()
if _, err := r.CreateOrUpdate(ctx, r.client, oauthChallengingClient, func() error {
return oauth.ReconcileChallengingClient(oauthChallengingClient, r.oauthAddress, r.oauthPort)
}); err != nil {
errs = append(errs, fmt.Errorf("failed to reconcile oauth challenging client: %w", err))
}
log.Info("reconciling oauth cli client")
oauthCLIClient := manifests.OAuthServerCLIClient()
if _, err := r.CreateOrUpdate(ctx, r.client, oauthCLIClient, func() error {
return oauth.ReconcileCLIClient(oauthCLIClient, r.oauthAddress, r.oauthPort)
}); err != nil {
errs = append(errs, fmt.Errorf("failed to reconcile oauth cli client: %w", err))
}
log.Info("reconciling oauth serving cert rbac")
oauthServingCertRole := manifests.OAuthServingCertRole()
if _, err := r.CreateOrUpdate(ctx, r.client, oauthServingCertRole, func() error {
return oauth.ReconcileOauthServingCertRole(oauthServingCertRole)
}); err != nil {
errs = append(errs, fmt.Errorf("failed to reconcile oauth serving cert role: %w", err))
}
oauthServingCertRoleBinding := manifests.OAuthServingCertRoleBinding()
if _, err := r.CreateOrUpdate(ctx, r.client, oauthServingCertRoleBinding, func() error {
return oauth.ReconcileOauthServingCertRoleBinding(oauthServingCertRoleBinding)
}); err != nil {
errs = append(errs, fmt.Errorf("failed to reconcile oauth serving cert rolebinding: %w", err))
}
}
log.Info("reconciling cloud credential secrets")
errs = append(errs, r.reconcileCloudCredentialSecrets(ctx, hcp, log)...)
log.Info("reconciling in-cluster cloud config")
if err := r.reconcileCloudConfig(ctx, hcp); err != nil {
errs = append(errs, fmt.Errorf("failed to reconcile the cloud config: %w", err))
}
log.Info("reconciling openshift controller manager service ca bundle")
ocmServiceCA := manifests.OpenShiftControllerManagerServiceCA()
if _, err := r.CreateOrUpdate(ctx, r.client, ocmServiceCA, func() error {
if ocmServiceCA.Annotations == nil {
ocmServiceCA.Annotations = map[string]string{}
}
ocmServiceCA.Annotations["service.beta.openshift.io/inject-cabundle"] = "true"
return nil
}); err != nil {
errs = append(errs, fmt.Errorf("failed to reconcile openshift controller manager service ca bundle: %w", err))
}
log.Info("reconciling olm resources")
errs = append(errs, r.reconcileOLM(ctx, hcp)...)
if hostedcontrolplane.IsStorageAndCSIManaged(hcp) {
log.Info("reconciling storage resources")
errs = append(errs, r.reconcileStorage(ctx, hcp)...)
log.Info("reconciling node level csi configuration")
if err := r.reconcileCSIDriver(ctx, hcp, releaseImage); err != nil {
errs = append(errs, err)
}
}
recyclerServiceAccount := manifests.RecyclerServiceAccount()
if _, err := r.CreateOrUpdate(ctx, r.client, recyclerServiceAccount, func() error {
return nil
}); err != nil {
errs = append(errs, fmt.Errorf("failed to reconcile pv recycler service account: %w", err))
}
log.Info("reconciling observed configuration")
errs = append(errs, r.reconcileObservedConfiguration(ctx, hcp)...)
errs = append(errs, r.ensureGuestAdmissionWebhooksAreValid(ctx))
// Delete the DNS operator deployment in the hosted cluster, if it is
// present there. A separate DNS operator deployment runs as part of
// the hosted control-plane, but an upgraded cluster might still have
// an old DNS operator deployment in the hosted cluster. The caching
// client has a label selector that doesn't match the deployment,
// so we must use the uncached client for this delete call. To avoid
// excessive API calls using the uncached client, the delete call is
// guarded using a sync.Once.
if r.isClusterVersionUpdated(ctx, releaseImage.Version()) {
deleteDNSOperatorDeploymentOnce.Do(func() {
dnsOperatorDeployment := manifests.DNSOperatorDeployment()
log.Info("removing any existing DNS operator deployment")
if err := r.uncachedClient.Delete(ctx, dnsOperatorDeployment); err != nil && !apierrors.IsNotFound(err) {
errs = append(errs, err)
}
})
deleteCVORemovedResourcesOnce.Do(func() {
resources := cvo.ResourcesToRemove(hcp.Spec.Platform.Type)
for _, resource := range resources {
log.Info("removing existing resources", "resource", resource)
if err := r.uncachedClient.Delete(ctx, resource); err != nil && !apierrors.IsNotFound(err) {
errs = append(errs, err)
}
}
})
}
// Reconcile platform specific resources
switch hcp.Spec.Platform.Type {
case hyperv1.AWSPlatform:
log.Info("reconciling AWS specific resources")
errs = append(errs, r.reconcileAWSIdentityWebhook(ctx)...)
case hyperv1.AzurePlatform:
log.Info("reconciling Azure specific resources")
errs = append(errs, r.reconcileAzureCloudNodeManager(ctx, releaseImage.ComponentImages()["azure-cloud-node-manager"])...)
}
return ctrl.Result{}, errors.NewAggregate(errs)
}
func (r *reconciler) reconcileCSIDriver(ctx context.Context, hcp *hyperv1.HostedControlPlane, releaseImage *releaseinfo.ReleaseImage) error {
switch hcp.Spec.Platform.Type {
case hyperv1.KubevirtPlatform:
// Most csi drivers should be laid down by the Cluster Storage Operator (CSO) instead of
// the hcco operator. Only KubeVirt is unique at the moment.
err := kubevirtcsi.ReconcileTenant(r.client, hcp, ctx, r.CreateOrUpdate, releaseImage.ComponentImages())
if err != nil {
return err
}
}
return nil
}
func (r *reconciler) reconcileCRDs(ctx context.Context) error {
var errs []error
requestCount := manifests.RequestCountCRD()
if _, err := r.CreateOrUpdate(ctx, r.client, requestCount, func() error {
return crd.ReconcileRequestCountCRD(requestCount)
}); err != nil {
errs = append(errs, fmt.Errorf("failed to reconcile request count crd: %w", err))
}
return errors.NewAggregate(errs)
}
func (r *reconciler) reconcileConfig(ctx context.Context, hcp *hyperv1.HostedControlPlane) error {
var errs []error
apiServerAddress := hcp.Status.ControlPlaneEndpoint.Host
if len(apiServerAddress) == 0 {
return fmt.Errorf("hosted control plane does not have an APIServer endpoint address")
}
// Infrastructure is first reconciled for its spec
infra := globalconfig.InfrastructureConfig()
var currentInfra *configv1.Infrastructure
if _, err := r.CreateOrUpdate(ctx, r.client, infra, func() error {
currentInfra = infra.DeepCopy()
globalconfig.ReconcileInfrastructure(infra, hcp)
return nil
}); err != nil {
errs = append(errs, fmt.Errorf("failed to reconcile infrastructure config spec: %w", err))
} else {
// It is reconciled a second time to update its status
globalconfig.ReconcileInfrastructure(infra, hcp)
if !equality.Semantic.DeepEqual(infra.Status, currentInfra.Status) {
if err := r.client.Status().Update(ctx, infra); err != nil {
errs = append(errs, fmt.Errorf("failed to update infrastructure status: %w", err))
}
}
}
dns := globalconfig.DNSConfig()
if _, err := r.CreateOrUpdate(ctx, r.client, dns, func() error {
globalconfig.ReconcileDNSConfig(dns, hcp)
return nil
}); err != nil {
errs = append(errs, fmt.Errorf("failed to reconcile dns config: %w", err))
}
ingress := globalconfig.IngressConfig()
if _, err := r.CreateOrUpdate(ctx, r.client, ingress, func() error {
globalconfig.ReconcileIngressConfig(ingress, hcp)
return nil
}); err != nil {
errs = append(errs, fmt.Errorf("failed to reconcile ingress config: %w", err))
}
networkConfig := globalconfig.NetworkConfig()
if _, err := r.CreateOrUpdate(ctx, r.client, networkConfig, func() error {
if err := globalconfig.ReconcileNetworkConfig(networkConfig, hcp); err != nil {
errs = append(errs, fmt.Errorf("failed to reconcile network config: %w", err))
}
return nil
}); err != nil {
errs = append(errs, fmt.Errorf("failed to create network config: %w", err))
}
// Copy proxy trustedCA to guest cluster.
if err := r.reconcileProxyTrustedCAConfigMap(ctx, hcp); err != nil {
errs = append(errs, fmt.Errorf("failed to reconcile proxy TrustedCA configmap: %w", err))
}
proxy := globalconfig.ProxyConfig()
if _, err := r.CreateOrUpdate(ctx, r.client, proxy, func() error {
globalconfig.ReconcileInClusterProxyConfig(proxy, hcp.Spec.Configuration)
return nil
}); err != nil {
errs = append(errs, fmt.Errorf("failed to reconcile proxy config: %w", err))
}
err := r.reconcileImageContentPolicyType(ctx, hcp)
if err != nil {
errs = append(errs, err)
}
installConfigCM := manifests.InstallConfigConfigMap()
if _, err := r.CreateOrUpdate(ctx, r.client, installConfigCM, func() error {
installConfigCM.Data = map[string]string{
"install-config": globalconfig.NewInstallConfig(hcp).String(),
}
return nil
}); err != nil {
errs = append(errs, fmt.Errorf("failed to reconcile dns config: %w", err))
}
cloudCredentialConfig := manifests.CloudCredential()
if _, err := r.CreateOrUpdate(ctx, r.client, cloudCredentialConfig, func() error {
cco.ReconcileCloudCredentialConfig(cloudCredentialConfig)
return nil
}); err != nil {
errs = append(errs, fmt.Errorf("failed to reconcile cloud credential config: %w", err))
}
authenticationConfig := globalconfig.AuthenticationConfiguration()
if _, err := r.CreateOrUpdate(ctx, r.client, authenticationConfig, func() error {
return globalconfig.ReconcileAuthenticationConfiguration(authenticationConfig, hcp.Spec.Configuration, hcp.Spec.IssuerURL)
}); err != nil {
errs = append(errs, fmt.Errorf("failed to reconcile authentication config: %w", err))
}
return errors.NewAggregate(errs)
}
func (r *reconciler) reconcileProxyTrustedCAConfigMap(ctx context.Context, hcp *hyperv1.HostedControlPlane) error {
log := ctrl.LoggerFrom(ctx)
configMapRef := ""
if hcp.Spec.Configuration != nil && hcp.Spec.Configuration.Proxy != nil {
configMapRef = hcp.Spec.Configuration.Proxy.TrustedCA.Name
}
proxy := globalconfig.ProxyConfig()
if err := r.client.Get(ctx, client.ObjectKeyFromObject(proxy), proxy); err != nil {
return err
}
currentConfigMapRef := proxy.Spec.TrustedCA.Name
if currentConfigMapRef != "" && currentConfigMapRef != configMapRef {
// cleanup old configMaps
cm := &corev1.ConfigMap{}
cm.Name = currentConfigMapRef
// log and ignore deletion errors, should not disrupt normal workflow
cm.Namespace = hcp.Namespace
if err := r.cpClient.Delete(ctx, cm); err != nil {
log.Error(err, "failed to delete configmap", "name", cm.Name, "namespace", cm.Namespace)
}
cm.Namespace = manifests.ProxyTrustedCAConfigMap("").Namespace
if err := r.client.Delete(ctx, cm); err != nil {
log.Error(err, "failed to delete configmap in hosted cluster", "name", cm.Name, "namespace", cm.Namespace)
}
}
if configMapRef == "" {
return nil
}
sourceCM := &corev1.ConfigMap{}
if err := r.cpClient.Get(ctx, client.ObjectKey{Namespace: hcp.Namespace, Name: configMapRef}, sourceCM); err != nil {
return fmt.Errorf("failed to get referenced TrustedCA configmap %s/%s: %w", hcp.Namespace, configMapRef, err)
}
destCM := manifests.ProxyTrustedCAConfigMap(sourceCM.Name)
if _, err := r.CreateOrUpdate(ctx, r.client, destCM, func() error {
destCM.Data = sourceCM.Data
return nil
}); err != nil {
return fmt.Errorf("failed to reconcile referenced TrustedCA config map %s/%s: %w", destCM.Namespace, destCM.Name, err)
}
return nil
}
func (r *reconciler) reconcileNamespaces(ctx context.Context) error {
namespaceManifests := []struct {
manifest func() *corev1.Namespace
reconcile func(*corev1.Namespace) error
}{
{manifest: manifests.NamespaceOpenShiftAPIServer},
{manifest: manifests.NamespaceOpenShiftInfra, reconcile: namespaces.ReconcileOpenShiftInfraNamespace},
{manifest: manifests.NamespaceOpenshiftCloudControllerManager},
{manifest: manifests.NamespaceOpenShiftControllerManager},
{manifest: manifests.NamespaceKubeAPIServer, reconcile: namespaces.ReconcileKubeAPIServerNamespace},
{manifest: manifests.NamespaceKubeControllerManager},
{manifest: manifests.NamespaceKubeScheduler},
{manifest: manifests.NamespaceEtcd},
{manifest: manifests.NamespaceIngress, reconcile: namespaces.ReconcileOpenShiftIngressNamespace},
{manifest: manifests.NamespaceAuthentication},
{manifest: manifests.NamespaceRouteControllerManager},
}
var errs []error
for _, m := range namespaceManifests {
ns := m.manifest()
if _, err := r.CreateOrUpdate(ctx, r.client, ns, func() error {
if m.reconcile != nil {
return m.reconcile(ns)
}
return nil
}); err != nil {
errs = append(errs, fmt.Errorf("failed to reconcile namespace %s: %w", ns.Name, err))
}
}
return errors.NewAggregate(errs)
}
type manifestAndReconcile[o client.Object] struct {
manifest func() o
reconcile func(o) error
}
func (m manifestAndReconcile[o]) upsert(ctx context.Context, client client.Client, createOrUpdate upsert.CreateOrUpdateFN) error {
obj := m.manifest()
if _, err := createOrUpdate(ctx, client, obj, func() error {
return m.reconcile(obj)
}); err != nil {
return fmt.Errorf("failed to reconcile %T %s: %w", obj, obj.GetName(), err)
}
return nil
}
type manifestReconciler interface {
upsert(ctx context.Context, client client.Client, createOrUpdate upsert.CreateOrUpdateFN) error
}
func (r *reconciler) reconcileRBAC(ctx context.Context) error {
rbac := []manifestReconciler{
manifestAndReconcile[*rbacv1.ClusterRole]{manifest: manifests.CSRApproverClusterRole, reconcile: rbac.ReconcileCSRApproverClusterRole},
manifestAndReconcile[*rbacv1.ClusterRole]{manifest: manifests.IngressToRouteControllerClusterRole, reconcile: rbac.ReconcileIngressToRouteControllerClusterRole},
manifestAndReconcile[*rbacv1.ClusterRole]{manifest: manifests.NamespaceSecurityAllocationControllerClusterRole, reconcile: rbac.ReconcileNamespaceSecurityAllocationControllerClusterRole},
manifestAndReconcile[*rbacv1.Role]{manifest: manifests.IngressToRouteControllerRole, reconcile: rbac.ReconcileReconcileIngressToRouteControllerRole},
manifestAndReconcile[*rbacv1.ClusterRoleBinding]{manifest: manifests.CSRApproverClusterRoleBinding, reconcile: rbac.ReconcileCSRApproverClusterRoleBinding},
manifestAndReconcile[*rbacv1.ClusterRoleBinding]{manifest: manifests.IngressToRouteControllerClusterRoleBinding, reconcile: rbac.ReconcileIngressToRouteControllerClusterRoleBinding},
manifestAndReconcile[*rbacv1.ClusterRoleBinding]{manifest: manifests.NamespaceSecurityAllocationControllerClusterRoleBinding, reconcile: rbac.ReconcileNamespaceSecurityAllocationControllerClusterRoleBinding},
manifestAndReconcile[*rbacv1.ClusterRoleBinding]{manifest: manifests.NodeBootstrapperClusterRoleBinding, reconcile: rbac.ReconcileNodeBootstrapperClusterRoleBinding},
manifestAndReconcile[*rbacv1.ClusterRoleBinding]{manifest: manifests.CSRRenewalClusterRoleBinding, reconcile: rbac.ReconcileCSRRenewalClusterRoleBinding},
manifestAndReconcile[*rbacv1.ClusterRoleBinding]{manifest: manifests.MetricsClientClusterRoleBinding, reconcile: rbac.ReconcileGenericMetricsClusterRoleBinding("system:serviceaccount:hypershift:prometheus")},
manifestAndReconcile[*rbacv1.RoleBinding]{manifest: manifests.IngressToRouteControllerRoleBinding, reconcile: rbac.ReconcileIngressToRouteControllerRoleBinding},
manifestAndReconcile[*rbacv1.RoleBinding]{manifest: manifests.AuthenticatedReaderForAuthenticatedUserRolebinding, reconcile: rbac.ReconcileAuthenticatedReaderForAuthenticatedUserRolebinding},
manifestAndReconcile[*rbacv1.Role]{manifest: manifests.KCMLeaderElectionRole, reconcile: rbac.ReconcileKCMLeaderElectionRole},
manifestAndReconcile[*rbacv1.RoleBinding]{manifest: manifests.KCMLeaderElectionRoleBinding, reconcile: rbac.ReconcileKCMLeaderElectionRoleBinding},
manifestAndReconcile[*rbacv1.ClusterRole]{manifest: manifests.ImageTriggerControllerClusterRole, reconcile: rbac.ReconcileImageTriggerControllerClusterRole},
manifestAndReconcile[*rbacv1.ClusterRoleBinding]{manifest: manifests.ImageTriggerControllerClusterRoleBinding, reconcile: rbac.ReconcileImageTriggerControllerClusterRoleBinding},
manifestAndReconcile[*rbacv1.ClusterRole]{manifest: manifests.PodSecurityAdmissionLabelSyncerControllerClusterRole, reconcile: rbac.ReconcilePodSecurityAdmissionLabelSyncerControllerClusterRole},
manifestAndReconcile[*rbacv1.ClusterRoleBinding]{manifest: manifests.PodSecurityAdmissionLabelSyncerControllerRoleBinding, reconcile: rbac.ReconcilePodSecurityAdmissionLabelSyncerControllerRoleBinding},
manifestAndReconcile[*rbacv1.ClusterRole]{manifest: manifests.PriviligedNamespacesPSALabelSyncerClusterRole, reconcile: rbac.ReconcilePriviligedNamespacesPSALabelSyncerClusterRole},
manifestAndReconcile[*rbacv1.ClusterRoleBinding]{manifest: manifests.PriviligedNamespacesPSALabelSyncerClusterRoleBinding, reconcile: rbac.ReconcilePriviligedNamespacesPSALabelSyncerClusterRoleBinding},
manifestAndReconcile[*rbacv1.ClusterRole]{manifest: manifests.DeployerClusterRole, reconcile: rbac.ReconcileDeployerClusterRole},
manifestAndReconcile[*rbacv1.ClusterRoleBinding]{manifest: manifests.DeployerClusterRoleBinding, reconcile: rbac.ReconcileDeployerClusterRoleBinding},
// ClusterRole and ClusterRoleBinding for useroauthaccesstokens referenced from https://github.com/openshift/cluster-authentication-operator/tree/bebf0fd3932be12594227b415fecd5d664611bc0/bindata/oauth-apiserver/RBAC
// Let this go by for now
manifestAndReconcile[*rbacv1.ClusterRole]{manifest: manifests.UserOAuthClusterRole, reconcile: rbac.ReconcileUserOAuthClusterRole},
manifestAndReconcile[*rbacv1.ClusterRoleBinding]{manifest: manifests.UserOAuthClusterRoleBinding, reconcile: rbac.ReconcileUserOAuthClusterRoleBinding},
}
var errs []error
for _, m := range rbac {
if err := m.upsert(ctx, r.client, r.CreateOrUpdate); err != nil {
errs = append(errs, err)
}
}
return errors.NewAggregate(errs)
}
func (r *reconciler) reconcileIngressController(ctx context.Context, hcp *hyperv1.HostedControlPlane) error {
var errs []error
p := ingress.NewIngressParams(hcp)
ingressController := manifests.IngressDefaultIngressController()
if _, err := r.CreateOrUpdate(ctx, r.client, ingressController, func() error {
return ingress.ReconcileDefaultIngressController(ingressController, p.IngressSubdomain, p.PlatformType, p.Replicas, p.IBMCloudUPI, p.IsPrivate, p.AWSNLB, p.AWSNLBScope)
}); err != nil {
errs = append(errs, fmt.Errorf("failed to reconcile default ingress controller: %w", err))
}
sourceCert := cpomanifests.IngressCert(hcp.Namespace)
if err := r.cpClient.Get(ctx, client.ObjectKeyFromObject(sourceCert), sourceCert); err != nil {
errs = append(errs, fmt.Errorf("failed to get ingress cert (%s/%s) from control plane: %w", sourceCert.Namespace, sourceCert.Name, err))
} else {
ingressControllerCert := manifests.IngressDefaultIngressControllerCert()
if _, err := r.CreateOrUpdate(ctx, r.client, ingressControllerCert, func() error {
return ingress.ReconcileDefaultIngressControllerCertSecret(ingressControllerCert, sourceCert)
}); err != nil {
errs = append(errs, fmt.Errorf("failed to reconcile default ingress controller cert: %w", err))
}
}
// Default Ingress is passed through as a subdomain of the infra/mgmt cluster
// for KubeVirt when the base domain passthrough feature is in use.
if hcp.Spec.Platform.Type == hyperv1.KubevirtPlatform &&
hcp.Spec.Platform.Kubevirt != nil &&
hcp.Spec.Platform.Kubevirt.BaseDomainPassthrough != nil &&
*hcp.Spec.Platform.Kubevirt.BaseDomainPassthrough {
// Here we are creating a route and service in the hosted control plane namespace
// while in the HCCO (which typically only works on the guest client, not the mgmt client).
//
// This is being done in the HCCO because we have to get the NodePort's port used by the
// default ingress services in the guest cluster in order to create the service in the
// mgmt/infra cluster. basically, the mgmt cluster service has to point the backend
// "somewhere", and that somewhere is the nodeport's port of the routers in the guest cluster.
// The component that can get that information about the nodeport's port is the HCCO, so
// that's why we're reconciling a service and route within hosted control plane in the HCCO
defaultIngressNodePortService := manifests.IngressDefaultIngressNodePortService()
err := r.client.Get(ctx, client.ObjectKeyFromObject(defaultIngressNodePortService), defaultIngressNodePortService)
if err != nil {
errs = append(errs, fmt.Errorf("failed to retrieve guest cluster ingress NodePort: %w", err))
}
var namespace string
if hcp.Spec.Platform.Kubevirt.Credentials != nil {
namespace = hcp.Spec.Platform.Kubevirt.Credentials.InfraNamespace
} else {
namespace = hcp.Namespace
}
// Manifests for infra/mgmt cluster passthrough service
cpService := manifests.IngressDefaultIngressPassthroughService(namespace)
cpService.Name = fmt.Sprintf("%s-%s",
manifests.IngressDefaultIngressPassthroughServiceName,
hcp.Spec.Platform.Kubevirt.GenerateID)
// Manifests for infra/mgmt cluster passthrough routes
cpPassthroughRoute := manifests.IngressDefaultIngressPassthroughRoute(namespace)
cpPassthroughRoute.Name = fmt.Sprintf("%s-%s",
manifests.IngressDefaultIngressPassthroughRouteName,
hcp.Spec.Platform.Kubevirt.GenerateID)
if _, err := r.CreateOrUpdate(ctx, r.kubevirtInfraClient, cpService, func() error {
return ingress.ReconcileDefaultIngressPassthroughService(cpService, defaultIngressNodePortService, hcp)
}); err != nil {
errs = append(errs, fmt.Errorf("failed to reconcile kubevirt ingress passthrough service: %w", err))
}
if _, err := r.CreateOrUpdate(ctx, r.kubevirtInfraClient, cpPassthroughRoute, func() error {
return ingress.ReconcileDefaultIngressPassthroughRoute(cpPassthroughRoute, cpService, hcp)
}); err != nil {
errs = append(errs, fmt.Errorf("failed to reconcile kubevirt ingress passthrough route: %w", err))
}
}
return errors.NewAggregate(errs)
}
func (r *reconciler) reconcileOAuthClientSecrets(ctx context.Context, hcp *hyperv1.HostedControlPlane) error {
var errs []error
if !util.HCPOAuthEnabled(hcp) &&
len(hcp.Spec.Configuration.Authentication.OIDCProviders) != 0 &&
len(hcp.Spec.Configuration.Authentication.OIDCProviders[0].OIDCClients) > 0 {
for _, oidcClient := range hcp.Spec.Configuration.Authentication.OIDCProviders[0].OIDCClients {
var src corev1.Secret
err := r.cpClient.Get(ctx, client.ObjectKey{Namespace: hcp.Namespace, Name: oidcClient.ClientSecret.Name}, &src)
if err != nil {
errs = append(errs, fmt.Errorf("failed to get OIDCClient secret %s: %w", oidcClient.ClientSecret.Name, err))
continue
}
dest := corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: oidcClient.ClientSecret.Name,
Namespace: "openshift-config",
},
}
_, err = r.CreateOrUpdate(ctx, r.client, &dest, func() error {
if dest.Data == nil {
dest.Data = map[string][]byte{}
}
dest.Data["clientSecret"] = src.Data["clientSecret"]
return nil
})
if err != nil {
errs = append(errs, fmt.Errorf("failed to reconcile OIDCClient secret %s: %w", dest.Name, err))
}
}
}
return errors.NewAggregate(errs)
}
func (r *reconciler) reconcileKonnectivityAgent(ctx context.Context, hcp *hyperv1.HostedControlPlane, releaseImage *releaseinfo.ReleaseImage) error {
var errs []error
// Set pod security labels on kube-system to avoid API warnings
kubeSystemNamespace := manifests.NamespaceKubeSystem()
if _, err := r.CreateOrUpdate(ctx, r.client, kubeSystemNamespace, func() error {
if kubeSystemNamespace.Labels == nil {
kubeSystemNamespace.Labels = map[string]string{}
}
kubeSystemNamespace.Labels["security.openshift.io/scc.podSecurityLabelSync"] = "false"