-
Notifications
You must be signed in to change notification settings - Fork 444
[WRKLDS-730] react to route-controller-manager refactoring #2674
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| package ocm | ||
|
|
||
| import ( | ||
| v1 "github.com/openshift/api/config/v1" | ||
| "github.com/openshift/hypershift/control-plane-operator/controllers/hostedcontrolplane/imageprovider" | ||
| "github.com/openshift/hypershift/control-plane-operator/controllers/hostedcontrolplane/manifests" | ||
| config2 "github.com/openshift/hypershift/support/config" | ||
| "github.com/openshift/hypershift/support/globalconfig" | ||
| corev1 "k8s.io/api/core/v1" | ||
| "testing" | ||
|
|
||
| hyperv1 "github.com/openshift/hypershift/api/v1beta1" | ||
| "github.com/openshift/hypershift/support/api" | ||
| "github.com/openshift/hypershift/support/testutil" | ||
| "github.com/openshift/hypershift/support/util" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| ) | ||
|
|
||
| func TestReconcileOpenShiftControllerManagerConfig(t *testing.T) { | ||
| hcp := &hyperv1.HostedControlPlane{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: "test", | ||
| Namespace: "test-namespace", | ||
| }, | ||
| Spec: hyperv1.HostedControlPlaneSpec{ | ||
| ReleaseImage: "quay.io/ocp-dev/test-release-image:latest", | ||
| Platform: hyperv1.PlatformSpec{ | ||
| Type: hyperv1.AWSPlatform, | ||
| }, | ||
| IssuerURL: "https://www.example.com", | ||
| }, | ||
| } | ||
| images := map[string]string{ | ||
| "openshift-controller-manager": "quay.io/test/openshift-controller-manager", | ||
| "docker-builder": "quay.io/test/docker-builder", | ||
| "deployer": "quay.io/test/deployer", | ||
| } | ||
| imageProvider := imageprovider.NewFromImages(images) | ||
|
|
||
| imageConfig := &v1.Image{ | ||
| Status: v1.ImageStatus{ | ||
| InternalRegistryHostname: "image-registry.openshift-image-registry.svc:5000", | ||
| }, | ||
| } | ||
|
|
||
| buildConfig := &v1.Build{ | ||
| Spec: v1.BuildSpec{ | ||
| BuildDefaults: v1.BuildDefaults{ | ||
| Env: []corev1.EnvVar{ | ||
| { | ||
| Name: "TEST_VAR", | ||
| Value: "TEST_VALUE", | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| networkConfig := &v1.NetworkSpec{ | ||
| ExternalIP: &v1.ExternalIPConfig{ | ||
| AutoAssignCIDRs: []string{"99.1.0.0/24"}, | ||
| }, | ||
| } | ||
|
|
||
| observedConfig := &globalconfig.ObservedConfig{ | ||
| Build: buildConfig, | ||
| Image: imageConfig, | ||
| } | ||
|
|
||
| params := NewOpenShiftControllerManagerParams(hcp, observedConfig, imageProvider, true) | ||
| configMap := manifests.OpenShiftControllerManagerConfig(hcp.Namespace) | ||
|
|
||
| if err := ReconcileOpenShiftControllerManagerConfig(configMap, config2.OwnerRefFrom(hcp), params.DeployerImage, params.DockerBuilderImage, params.MinTLSVersion(), params.CipherSuites(), imageConfig, buildConfig, networkConfig); err != nil { | ||
| t.Fatalf("unexpected error: %v", err) | ||
| } | ||
| configMapYaml, err := util.SerializeResource(configMap, api.Scheme) | ||
| if err != nil { | ||
| t.Fatalf("unexpected error: %v", err) | ||
| } | ||
| testutil.CompareWithFixture(t, configMapYaml) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| apiVersion: v1 | ||
| data: | ||
| config.yaml: | | ||
| apiVersion: openshiftcontrolplane.config.openshift.io/v1 | ||
| build: | ||
| additionalTrustedCA: "" | ||
| buildDefaults: | ||
| env: | ||
| - name: TEST_VAR | ||
| value: TEST_VALUE | ||
| resources: {} | ||
| buildOverrides: null | ||
| imageTemplateFormat: | ||
| format: quay.io/test/docker-builder | ||
| latest: false | ||
| controllers: null | ||
| deployer: | ||
| imageTemplateFormat: | ||
| format: quay.io/test/deployer | ||
| latest: false | ||
| dockerPullSecret: | ||
| internalRegistryHostname: image-registry.openshift-image-registry.svc:5000 | ||
| registryURLs: null | ||
| featureGates: null | ||
| imageImport: | ||
| disableScheduledImport: false | ||
| maxScheduledImageImportsPerMinute: 0 | ||
| scheduledImageImportMinimumIntervalSeconds: 0 | ||
| ingress: | ||
| ingressIPNetworkCIDR: 99.1.0.0/24 | ||
| kind: OpenShiftControllerManagerConfig | ||
| kubeClientConfig: | ||
| connectionOverrides: | ||
| acceptContentTypes: "" | ||
| burst: 0 | ||
| contentType: "" | ||
| qps: 0 | ||
| kubeConfig: /etc/kubernetes/secrets/svc-kubeconfig/kubeconfig | ||
| leaderElection: | ||
| leaseDuration: 0s | ||
| renewDeadline: 0s | ||
| retryPeriod: 0s | ||
| network: | ||
| clusterNetworks: null | ||
| networkPluginName: "" | ||
| serviceNetworkCIDR: "" | ||
| vxlanPort: 0 | ||
| resourceQuota: | ||
| concurrentSyncs: 0 | ||
| minResyncPeriod: 0s | ||
| syncPeriod: 0s | ||
| securityAllocator: | ||
| mcsAllocatorRange: "" | ||
| mcsLabelsPerProject: 0 | ||
| uidAllocatorRange: "" | ||
| serviceAccount: | ||
| managedNames: null | ||
| serviceServingCert: | ||
| signer: null | ||
| servingInfo: | ||
| bindAddress: 0.0.0.0:8443 | ||
| bindNetwork: "" | ||
| certFile: /etc/kubernetes/certs/tls.crt | ||
| cipherSuites: | ||
| - TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 | ||
| - TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 | ||
| - TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 | ||
| - TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 | ||
| - TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256 | ||
| - TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 | ||
| clientCA: /etc/kubernetes/client-ca/ca.crt | ||
| keyFile: /etc/kubernetes/certs/tls.key | ||
| maxRequestsInFlight: 0 | ||
| minTLSVersion: VersionTLS12 | ||
| requestTimeoutSeconds: 0 | ||
| kind: ConfigMap | ||
| metadata: | ||
| creationTimestamp: null | ||
| name: openshift-controller-manager-config | ||
| namespace: test-namespace | ||
| ownerReferences: | ||
| - apiVersion: hypershift.openshift.io/v1beta1 | ||
| blockOwnerDeletion: true | ||
| controller: true | ||
| kind: HostedControlPlane | ||
| name: test | ||
| uid: "" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| package routecm | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "github.com/openshift/hypershift/control-plane-operator/controllers/hostedcontrolplane/kas" | ||
| "path" | ||
|
|
||
| corev1 "k8s.io/api/core/v1" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
|
||
| configv1 "github.com/openshift/api/config/v1" | ||
| openshiftcpv1 "github.com/openshift/api/openshiftcontrolplane/v1" | ||
|
|
||
| "github.com/openshift/hypershift/control-plane-operator/controllers/hostedcontrolplane/common" | ||
| "github.com/openshift/hypershift/support/api" | ||
| "github.com/openshift/hypershift/support/certs" | ||
| "github.com/openshift/hypershift/support/config" | ||
| "github.com/openshift/hypershift/support/util" | ||
| ) | ||
|
|
||
| const ( | ||
| configKey = "config.yaml" | ||
| ) | ||
|
|
||
| func ReconcileOpenShiftRouteControllerManagerConfig(cm *corev1.ConfigMap, ownerRef config.OwnerRef, minTLSVersion string, cipherSuites []string, networkConfig *configv1.NetworkSpec) error { | ||
| ownerRef.ApplyTo(cm) | ||
|
|
||
| if cm.Data == nil { | ||
| cm.Data = map[string]string{} | ||
| } | ||
| config := &openshiftcpv1.OpenShiftControllerManagerConfig{} | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do we need to deserialize this instead of just construct the struct, serialize and store it?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @enxebre I thought it was to potentially allow changes to the config by another actor (similar to OCM). But I can remove the deserialization part if that is not needed. |
||
| if configStr, exists := cm.Data[configKey]; exists && len(configStr) > 0 { | ||
| err := util.DeserializeResource(configStr, config, api.Scheme) | ||
| if err != nil { | ||
| return fmt.Errorf("unable to decode existing openshift route controller manager configuration: %w", err) | ||
| } | ||
| } | ||
| if err := reconcileConfig(config, minTLSVersion, cipherSuites, networkConfig); err != nil { | ||
| return err | ||
| } | ||
| configStr, err := util.SerializeResource(config, api.Scheme) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to serialize openshift route controller manager configuration: %w", err) | ||
| } | ||
| cm.Data[configKey] = configStr | ||
| return nil | ||
| } | ||
|
|
||
| func reconcileConfig(cfg *openshiftcpv1.OpenShiftControllerManagerConfig, minTLSVersion string, cipherSuites []string, networkConfig *configv1.NetworkSpec) error { | ||
| cpath := func(volume, file string) string { | ||
| dir := volumeMounts.Path(routeOCMContainerMain().Name, volume) | ||
| return path.Join(dir, file) | ||
| } | ||
| cfg.TypeMeta = metav1.TypeMeta{ | ||
| Kind: "OpenShiftControllerManagerConfig", | ||
| APIVersion: openshiftcpv1.GroupVersion.String(), | ||
| } | ||
|
|
||
| // network config | ||
| if networkConfig != nil && networkConfig.ExternalIP != nil && len(networkConfig.ExternalIP.AutoAssignCIDRs) > 0 { | ||
| cfg.Ingress.IngressIPNetworkCIDR = networkConfig.ExternalIP.AutoAssignCIDRs[0] | ||
| } else { | ||
| cfg.Ingress.IngressIPNetworkCIDR = "" | ||
| } | ||
|
|
||
| cfg.LeaderElection.Name = "openshift-route-controllers" | ||
| cfg.KubeClientConfig.KubeConfig = cpath(routeOCMVolumeKubeconfig().Name, kas.KubeconfigKey) | ||
| cfg.ServingInfo = &configv1.HTTPServingInfo{ | ||
| ServingInfo: configv1.ServingInfo{ | ||
| BindAddress: fmt.Sprintf("0.0.0.0:%d", servingPort), | ||
| CertInfo: configv1.CertInfo{ | ||
| CertFile: cpath(routeOCMVolumeServingCert().Name, corev1.TLSCertKey), | ||
| KeyFile: cpath(routeOCMVolumeServingCert().Name, corev1.TLSPrivateKeyKey), | ||
| }, | ||
| ClientCA: cpath(common.VolumeTotalClientCA().Name, certs.CASignerCertMapKey), | ||
| MinTLSVersion: minTLSVersion, | ||
| CipherSuites: cipherSuites, | ||
| }, | ||
| } | ||
| return nil | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| package routecm | ||
|
|
||
| import ( | ||
| v1 "github.com/openshift/api/config/v1" | ||
| "github.com/openshift/hypershift/control-plane-operator/controllers/hostedcontrolplane/imageprovider" | ||
| "github.com/openshift/hypershift/control-plane-operator/controllers/hostedcontrolplane/manifests" | ||
| config2 "github.com/openshift/hypershift/support/config" | ||
| "testing" | ||
|
|
||
| hyperv1 "github.com/openshift/hypershift/api/v1beta1" | ||
| "github.com/openshift/hypershift/support/api" | ||
| "github.com/openshift/hypershift/support/testutil" | ||
| "github.com/openshift/hypershift/support/util" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| ) | ||
|
|
||
| func TestReconcileOpenShiftRouteControllerManagerConfig(t *testing.T) { | ||
| hcp := &hyperv1.HostedControlPlane{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: "test", | ||
| Namespace: "test-namespace", | ||
| }, | ||
| Spec: hyperv1.HostedControlPlaneSpec{ | ||
| ReleaseImage: "quay.io/ocp-dev/test-release-image:latest", | ||
| Platform: hyperv1.PlatformSpec{ | ||
| Type: hyperv1.AWSPlatform, | ||
| }, | ||
| IssuerURL: "https://www.example.com", | ||
| }, | ||
| } | ||
| images := map[string]string{ | ||
| "route-controller-manager": "quay.io/test/route-controller-manager", | ||
| } | ||
| imageProvider := imageprovider.NewFromImages(images) | ||
|
|
||
| params := NewOpenShiftRouteControllerManagerParams(hcp, nil, imageProvider, true) | ||
| configMap := manifests.OpenShiftRouteControllerManagerConfig(hcp.Namespace) | ||
|
|
||
| networkConfig := &v1.NetworkSpec{ | ||
| ExternalIP: &v1.ExternalIPConfig{ | ||
| AutoAssignCIDRs: []string{"99.1.0.0/24"}, | ||
| }, | ||
| } | ||
|
|
||
| if err := ReconcileOpenShiftRouteControllerManagerConfig(configMap, config2.OwnerRefFrom(hcp), params.MinTLSVersion(), params.CipherSuites(), networkConfig); err != nil { | ||
| t.Fatalf("unexpected error: %v", err) | ||
| } | ||
| configMapYaml, err := util.SerializeResource(configMap, api.Scheme) | ||
| if err != nil { | ||
| t.Fatalf("unexpected error: %v", err) | ||
| } | ||
| testutil.CompareWithFixture(t, configMapYaml) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we please have a unit test for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added tests for both OCM and RCM