From cd450a453fdadc4ab719089c00b73ff5ff79d5ad Mon Sep 17 00:00:00 2001 From: Joe Kratzat Date: Wed, 12 Apr 2023 16:25:35 -0400 Subject: [PATCH 1/3] feat: allow OCI client endpoint override per cluster --- api/v1beta1/ocicluster_conversion.go | 1 + api/v1beta1/ociclustertemplate_conversion.go | 1 + api/v1beta1/zz_generated.conversion.go | 1 + api/v1beta2/ocicluster_types.go | 46 +++++++++++++ api/v1beta2/zz_generated.deepcopy.go | 50 ++++++++++++++ cloud/scope/clients.go | 66 +++++++++++++------ cloud/scope/clients_test.go | 4 +- cloud/scope/cluster_accessor.go | 2 + cloud/scope/oci_managed_cluster.go | 4 ++ cloud/scope/oci_selfmanaged_cluster.go | 4 ++ cloud/util/util.go | 16 ++++- cloud/util/util_test.go | 2 +- ...tructure.cluster.x-k8s.io_ociclusters.yaml | 35 ++++++++++ ....cluster.x-k8s.io_ociclustertemplates.yaml | 36 ++++++++++ ...e.cluster.x-k8s.io_ocimanagedclusters.yaml | 35 ++++++++++ ...r.x-k8s.io_ocimanagedclustertemplates.yaml | 36 ++++++++++ .../v1beta1/ocimanagedcluster_conversion.go | 1 + exp/api/v1beta1/zz_generated.conversion.go | 1 + exp/api/v1beta2/ocimanagedcluster_types.go | 6 ++ exp/api/v1beta2/zz_generated.deepcopy.go | 5 ++ main.go | 2 +- test/e2e/e2e_suite_test.go | 2 +- 22 files changed, 329 insertions(+), 27 deletions(-) diff --git a/api/v1beta1/ocicluster_conversion.go b/api/v1beta1/ocicluster_conversion.go index a5ff57b9..ce1bbd04 100644 --- a/api/v1beta1/ocicluster_conversion.go +++ b/api/v1beta1/ocicluster_conversion.go @@ -48,6 +48,7 @@ func (src *OCICluster) ConvertTo(dstRaw conversion.Hub) error { dst.Spec.NetworkSpec.Vcn.InternetGateway.Skip = restored.Spec.NetworkSpec.Vcn.InternetGateway.Skip dst.Spec.NetworkSpec.Vcn.RouteTable.Skip = restored.Spec.NetworkSpec.Vcn.RouteTable.Skip dst.Spec.NetworkSpec.APIServerLB.LoadBalancerType = restored.Spec.NetworkSpec.APIServerLB.LoadBalancerType + dst.Spec.ClientHostUrls = restored.Spec.ClientHostUrls return nil } diff --git a/api/v1beta1/ociclustertemplate_conversion.go b/api/v1beta1/ociclustertemplate_conversion.go index 02502871..dcf3ce0d 100644 --- a/api/v1beta1/ociclustertemplate_conversion.go +++ b/api/v1beta1/ociclustertemplate_conversion.go @@ -42,6 +42,7 @@ func (src *OCIClusterTemplate) ConvertTo(dstRaw conversion.Hub) error { dst.Spec.Template.Spec.NetworkSpec.Vcn.RouteTable.Skip = restored.Spec.Template.Spec.NetworkSpec.Vcn.RouteTable.Skip dst.Spec.Template.Spec.AvailabilityDomains = restored.Spec.Template.Spec.AvailabilityDomains dst.Spec.Template.Spec.NetworkSpec.APIServerLB.LoadBalancerType = restored.Spec.Template.Spec.NetworkSpec.APIServerLB.LoadBalancerType + dst.Spec.Template.Spec.ClientHostUrls = restored.Spec.Template.Spec.ClientHostUrls return nil } diff --git a/api/v1beta1/zz_generated.conversion.go b/api/v1beta1/zz_generated.conversion.go index 9a07f9e3..6bdd4151 100644 --- a/api/v1beta1/zz_generated.conversion.go +++ b/api/v1beta1/zz_generated.conversion.go @@ -1549,6 +1549,7 @@ func autoConvert_v1beta2_OCIClusterSpec_To_v1beta1_OCIClusterSpec(in *v1beta2.OC out.Region = in.Region out.ControlPlaneEndpoint = in.ControlPlaneEndpoint // WARNING: in.AvailabilityDomains requires manual conversion: does not exist in peer-type + // WARNING: in.ClientHostUrls requires manual conversion: does not exist in peer-type return nil } diff --git a/api/v1beta2/ocicluster_types.go b/api/v1beta2/ocicluster_types.go index bf255195..923a4e74 100644 --- a/api/v1beta2/ocicluster_types.go +++ b/api/v1beta2/ocicluster_types.go @@ -74,6 +74,12 @@ type OCIClusterSpec struct { // where the map key is the AD name and the struct is details about the AD. // +optional AvailabilityDomains map[string]OCIAvailabilityDomain `json:"availabilityDomains,omitempty"` + + // HostUrls allows the default client SDK URLs to be changed. + // + // +optional + // +nullable + ClientHostUrls *ClusterClientHostUrls `json:"clientHostUrls,omitempty"` } // OCIClusterStatus defines the observed state of OCICluster @@ -120,6 +126,46 @@ type OCIAvailabilityDomain struct { FaultDomains []string `json:"faultDomains,omitempty"` } +// ClusterClientHostUrls contains information about client host url overrides. +type ClusterClientHostUrls struct { + + // ComputeClientHost allows the default compute SDK client URL to be changed. + // + // +optional + // +nullable + ComputeClientHost *string `json:"computeClientHost,omitempty"` + + // ComputeManagementClientHost allows the default compute management SDK client URL to be changed. + // + // +optional + // +nullable + ComputeManagementClientHost *string `json:"computeManagementClientHost,omitempty"` + + // VCNClientHost allows the default vcn SDK client URL to be changed. + // + // +optional + // +nullable + VCNClientHost *string `json:"vCNClientHost,omitempty"` + + // LoadBalancerClientHost allows the default load balancer SDK client URL to be changed. + // + // +optional + // +nullable + LoadBalancerClientHost *string `json:"loadBalancerClientHost,omitempty"` + + // IdentityClientHost allows the default identity SDK client URL to be changed. + // + // +optional + // +nullable + IdentityClientHost *string `json:"identityClientHost,omitempty"` + + // ContainerEngineClientHost allows the default container engine SDK client URL to be changed. + // + // +optional + // +nullable + ContainerEngineClientHost *string `json:"containerEngineClientHost,omitempty"` +} + // GetConditions returns the list of conditions for an OCICluster API object. func (c *OCICluster) GetConditions() clusterv1.Conditions { return c.Status.Conditions diff --git a/api/v1beta2/zz_generated.deepcopy.go b/api/v1beta2/zz_generated.deepcopy.go index a60e3e66..2534db0a 100644 --- a/api/v1beta2/zz_generated.deepcopy.go +++ b/api/v1beta2/zz_generated.deepcopy.go @@ -264,6 +264,51 @@ func (in *AmdVmPlatformConfig) DeepCopy() *AmdVmPlatformConfig { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ClusterClientHostUrls) DeepCopyInto(out *ClusterClientHostUrls) { + *out = *in + if in.ComputeClientHost != nil { + in, out := &in.ComputeClientHost, &out.ComputeClientHost + *out = new(string) + **out = **in + } + if in.ComputeManagementClientHost != nil { + in, out := &in.ComputeManagementClientHost, &out.ComputeManagementClientHost + *out = new(string) + **out = **in + } + if in.VCNClientHost != nil { + in, out := &in.VCNClientHost, &out.VCNClientHost + *out = new(string) + **out = **in + } + if in.LoadBalancerClientHost != nil { + in, out := &in.LoadBalancerClientHost, &out.LoadBalancerClientHost + *out = new(string) + **out = **in + } + if in.IdentityClientHost != nil { + in, out := &in.IdentityClientHost, &out.IdentityClientHost + *out = new(string) + **out = **in + } + if in.ContainerEngineClientHost != nil { + in, out := &in.ContainerEngineClientHost, &out.ContainerEngineClientHost + *out = new(string) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterClientHostUrls. +func (in *ClusterClientHostUrls) DeepCopy() *ClusterClientHostUrls { + if in == nil { + return nil + } + out := new(ClusterClientHostUrls) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *DRG) DeepCopyInto(out *DRG) { *out = *in @@ -1112,6 +1157,11 @@ func (in *OCIClusterSpec) DeepCopyInto(out *OCIClusterSpec) { (*out)[key] = *val.DeepCopy() } } + if in.ClientHostUrls != nil { + in, out := &in.ClientHostUrls, &out.ClientHostUrls + *out = new(ClusterClientHostUrls) + (*in).DeepCopyInto(*out) + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new OCIClusterSpec. diff --git a/cloud/scope/clients.go b/cloud/scope/clients.go index bfd386b7..3766b07b 100644 --- a/cloud/scope/clients.go +++ b/cloud/scope/clients.go @@ -21,6 +21,7 @@ import ( "sync" "github.com/go-logr/logr" + "github.com/oracle/cluster-api-provider-oci/api/v1beta2" "github.com/oracle/cluster-api-provider-oci/cloud/services/base" "github.com/oracle/cluster-api-provider-oci/cloud/services/compute" "github.com/oracle/cluster-api-provider-oci/cloud/services/computemanagement" @@ -58,10 +59,11 @@ type ClientProvider struct { ociClients map[string]OCIClients ociClientsLock *sync.RWMutex ociAuthConfigProvider common.ConfigurationProvider + ociClientHostUrls *v1beta2.ClusterClientHostUrls } // NewClientProvider builds the ClientProvider with a client for the given region -func NewClientProvider(ociAuthConfigProvider common.ConfigurationProvider) (*ClientProvider, error) { +func NewClientProvider(ociAuthConfigProvider common.ConfigurationProvider, clientHostUrlOverrides *v1beta2.ClusterClientHostUrls) (*ClientProvider, error) { log := klogr.New() if ociAuthConfigProvider == nil { @@ -73,11 +75,17 @@ func NewClientProvider(ociAuthConfigProvider common.ConfigurationProvider) (*Cli ociAuthConfigProvider: ociAuthConfigProvider, ociClients: map[string]OCIClients{}, ociClientsLock: new(sync.RWMutex), + ociClientHostUrls: clientHostUrlOverrides, } return &provider, nil } +// GetAuthProvider returns the client provider auth config +func (c *ClientProvider) GetAuthProvider() common.ConfigurationProvider { + return c.ociAuthConfigProvider +} + // GetOrBuildClient if the OCIClients exist for the region they are returned, if not clients will build them func (c *ClientProvider) GetOrBuildClient(region string) (OCIClients, error) { if len(region) <= 0 { @@ -94,7 +102,7 @@ func (c *ClientProvider) GetOrBuildClient(region string) (OCIClients, error) { c.ociClientsLock.Lock() defer c.ociClientsLock.Unlock() - regionalClient, err := createClients(region, c.ociAuthConfigProvider, c.Logger) + regionalClient, err := c.createClients(region) if err != nil { return regionalClient, err } @@ -108,36 +116,36 @@ func (c *ClientProvider) GetRegion() (string, error) { return c.ociAuthConfigProvider.Region() } -func createClients(region string, oCIAuthConfigProvider common.ConfigurationProvider, logger *logr.Logger) (OCIClients, error) { - vcnClient, err := createVncClient(region, oCIAuthConfigProvider, logger) +func (c *ClientProvider) createClients(region string) (OCIClients, error) { + vcnClient, err := c.createVncClient(region, c.ociAuthConfigProvider, c.Logger) if err != nil { return OCIClients{}, err } - nlbClient, err := createNLbClient(region, oCIAuthConfigProvider, logger) + nlbClient, err := c.createNLbClient(region, c.ociAuthConfigProvider, c.Logger) if err != nil { return OCIClients{}, err } - lbClient, err := createLBClient(region, oCIAuthConfigProvider, logger) + lbClient, err := c.createLBClient(region, c.ociAuthConfigProvider, c.Logger) if err != nil { return OCIClients{}, err } - identityClient, err := createIdentityClient(region, oCIAuthConfigProvider, logger) + identityClient, err := c.createIdentityClient(region, c.ociAuthConfigProvider, c.Logger) if err != nil { return OCIClients{}, err } - computeClient, err := createComputeClient(region, oCIAuthConfigProvider, logger) + computeClient, err := c.createComputeClient(region, c.ociAuthConfigProvider, c.Logger) if err != nil { return OCIClients{}, err } - computeManagementClient, err := createComputeManagementClient(region, oCIAuthConfigProvider, logger) + computeManagementClient, err := c.createComputeManagementClient(region, c.ociAuthConfigProvider, c.Logger) if err != nil { return OCIClients{}, err } - containerEngineClient, err := createContainerEngineClient(region, oCIAuthConfigProvider, logger) + containerEngineClient, err := c.createContainerEngineClient(region, c.ociAuthConfigProvider, c.Logger) if err != nil { return OCIClients{}, err } - baseClient, err := createBaseClient(region, oCIAuthConfigProvider, logger) + baseClient, err := c.createBaseClient(region, c.ociAuthConfigProvider, c.Logger) if err != nil { return OCIClients{}, err } @@ -158,19 +166,22 @@ func createClients(region string, oCIAuthConfigProvider common.ConfigurationProv }, err } -func createVncClient(region string, ociAuthConfigProvider common.ConfigurationProvider, logger *logr.Logger) (*core.VirtualNetworkClient, error) { +func (c *ClientProvider) createVncClient(region string, ociAuthConfigProvider common.ConfigurationProvider, logger *logr.Logger) (*core.VirtualNetworkClient, error) { vcnClient, err := core.NewVirtualNetworkClientWithConfigurationProvider(ociAuthConfigProvider) if err != nil { logger.Error(err, "unable to create OCI VCN Client") return nil, err } vcnClient.SetRegion(region) + if c.ociClientHostUrls != nil && c.ociClientHostUrls.VCNClientHost != nil { + vcnClient.Host = *c.ociClientHostUrls.VCNClientHost + } vcnClient.Interceptor = setVersionHeader() return &vcnClient, nil } -func createNLbClient(region string, ociAuthConfigProvider common.ConfigurationProvider, logger *logr.Logger) (*networkloadbalancer.NetworkLoadBalancerClient, error) { +func (c *ClientProvider) createNLbClient(region string, ociAuthConfigProvider common.ConfigurationProvider, logger *logr.Logger) (*networkloadbalancer.NetworkLoadBalancerClient, error) { nlbClient, err := networkloadbalancer.NewNetworkLoadBalancerClientWithConfigurationProvider(ociAuthConfigProvider) if err != nil { logger.Error(err, "unable to create OCI LB Client") @@ -182,67 +193,84 @@ func createNLbClient(region string, ociAuthConfigProvider common.ConfigurationPr return &nlbClient, nil } -func createLBClient(region string, ociAuthConfigProvider common.ConfigurationProvider, logger *logr.Logger) (*loadbalancer.LoadBalancerClient, error) { +func (c *ClientProvider) createLBClient(region string, ociAuthConfigProvider common.ConfigurationProvider, logger *logr.Logger) (*loadbalancer.LoadBalancerClient, error) { lbClient, err := loadbalancer.NewLoadBalancerClientWithConfigurationProvider(ociAuthConfigProvider) if err != nil { logger.Error(err, "unable to create OCI LBaaS Client") return nil, err } lbClient.SetRegion(region) + if c.ociClientHostUrls != nil && c.ociClientHostUrls.LoadBalancerClientHost != nil { + lbClient.Host = *c.ociClientHostUrls.LoadBalancerClientHost + } lbClient.Interceptor = setVersionHeader() return &lbClient, nil } -func createIdentityClient(region string, ociAuthConfigProvider common.ConfigurationProvider, logger *logr.Logger) (*identity.IdentityClient, error) { +func (c *ClientProvider) createIdentityClient(region string, ociAuthConfigProvider common.ConfigurationProvider, logger *logr.Logger) (*identity.IdentityClient, error) { identityClient, err := identity.NewIdentityClientWithConfigurationProvider(ociAuthConfigProvider) if err != nil { logger.Error(err, "unable to create OCI Identity Client") return nil, err } identityClient.SetRegion(region) + + if c.ociClientHostUrls != nil && c.ociClientHostUrls.IdentityClientHost != nil { + identityClient.Host = *c.ociClientHostUrls.IdentityClientHost + } identityClient.Interceptor = setVersionHeader() return &identityClient, nil } -func createComputeClient(region string, ociAuthConfigProvider common.ConfigurationProvider, logger *logr.Logger) (*core.ComputeClient, error) { +func (c *ClientProvider) createComputeClient(region string, ociAuthConfigProvider common.ConfigurationProvider, logger *logr.Logger) (*core.ComputeClient, error) { computeClient, err := core.NewComputeClientWithConfigurationProvider(ociAuthConfigProvider) if err != nil { logger.Error(err, "unable to create OCI Compute Client") return nil, err } computeClient.SetRegion(region) + //https://dyn.slack.com/archives/C7MS7QWC8/p1675719244230459?thread_ts=1675460644.801049&cid=C7MS7QWC8 + if c.ociClientHostUrls != nil && c.ociClientHostUrls.ComputeClientHost != nil { + computeClient.Host = *c.ociClientHostUrls.ComputeClientHost + } computeClient.Interceptor = setVersionHeader() return &computeClient, nil } -func createComputeManagementClient(region string, ociAuthConfigProvider common.ConfigurationProvider, logger *logr.Logger) (*core.ComputeManagementClient, error) { +func (c *ClientProvider) createComputeManagementClient(region string, ociAuthConfigProvider common.ConfigurationProvider, logger *logr.Logger) (*core.ComputeManagementClient, error) { computeManagementClient, err := core.NewComputeManagementClientWithConfigurationProvider(ociAuthConfigProvider) if err != nil { logger.Error(err, "unable to create OCI Compute Management Client") return nil, err } computeManagementClient.SetRegion(region) + if c.ociClientHostUrls != nil && c.ociClientHostUrls.ComputeManagementClientHost != nil { + computeManagementClient.Host = *c.ociClientHostUrls.ComputeManagementClientHost + } computeManagementClient.Interceptor = setVersionHeader() return &computeManagementClient, nil } -func createContainerEngineClient(region string, ociAuthConfigProvider common.ConfigurationProvider, logger *logr.Logger) (*containerengine.ContainerEngineClient, error) { +func (c *ClientProvider) createContainerEngineClient(region string, ociAuthConfigProvider common.ConfigurationProvider, logger *logr.Logger) (*containerengine.ContainerEngineClient, error) { containerEngineClient, err := containerengine.NewContainerEngineClientWithConfigurationProvider(ociAuthConfigProvider) if err != nil { logger.Error(err, "unable to create OCI Container Engine Client") return nil, err } containerEngineClient.SetRegion(region) + if c.ociClientHostUrls != nil && c.ociClientHostUrls.ContainerEngineClientHost != nil { + containerEngineClient.Host = *c.ociClientHostUrls.ContainerEngineClientHost + } containerEngineClient.Interceptor = setVersionHeader() return &containerEngineClient, nil } -func createBaseClient(region string, ociAuthConfigProvider common.ConfigurationProvider, logger *logr.Logger) (base.BaseClient, error) { +func (c *ClientProvider) createBaseClient(region string, ociAuthConfigProvider common.ConfigurationProvider, logger *logr.Logger) (base.BaseClient, error) { baseClient, err := base.NewBaseClient(ociAuthConfigProvider, logger) if err != nil { logger.Error(err, "unable to create OCI Base Client") diff --git a/cloud/scope/clients_test.go b/cloud/scope/clients_test.go index e8aa852e..318f2e11 100644 --- a/cloud/scope/clients_test.go +++ b/cloud/scope/clients_test.go @@ -37,7 +37,7 @@ func TestClients_NewClientProvider(t *testing.T) { } - clientProvider, err := NewClientProvider(ociAuthConfigProvider) + clientProvider, err := NewClientProvider(ociAuthConfigProvider, nil) if err != nil { t.Errorf("Expected %v to equal nil", err) } @@ -49,7 +49,7 @@ func TestClients_NewClientProvider(t *testing.T) { func TestClients_NewClientProviderWithBadAuthConfig(t *testing.T) { - clientProvider, err := NewClientProvider(nil) + clientProvider, err := NewClientProvider(nil, nil) if err == nil { t.Errorf("Expected error:%v to not equal nil", err) } diff --git a/cloud/scope/cluster_accessor.go b/cloud/scope/cluster_accessor.go index 46a7651e..3d02661d 100644 --- a/cloud/scope/cluster_accessor.go +++ b/cloud/scope/cluster_accessor.go @@ -42,6 +42,8 @@ type OCIClusterAccessor interface { GetNameSpace() string // GetRegion returns the region of the cluster, if specified in the spec. GetRegion() string + // GetClientHostUrls returns the client host url overrides for the cluster + GetClientHostUrls() *infrastructurev1beta2.ClusterClientHostUrls // GetNetworkSpec returns the NetworkSpec of the cluster. GetNetworkSpec() *infrastructurev1beta2.NetworkSpec // SetControlPlaneEndpoint sets the control plane endpoint of the cluster. diff --git a/cloud/scope/oci_managed_cluster.go b/cloud/scope/oci_managed_cluster.go index 7b6bd99d..a29dcef2 100644 --- a/cloud/scope/oci_managed_cluster.go +++ b/cloud/scope/oci_managed_cluster.go @@ -37,6 +37,10 @@ func (c OCIManagedCluster) GetRegion() string { return c.OCIManagedCluster.Spec.Region } +func (c OCIManagedCluster) GetClientHostUrls() *infrastructurev1beta2.ClusterClientHostUrls { + return c.OCIManagedCluster.Spec.ClientHostUrls +} + func (c OCIManagedCluster) MarkConditionFalse(t clusterv1.ConditionType, reason string, severity clusterv1.ConditionSeverity, messageFormat string, messageArgs ...interface{}) { conditions.MarkFalse(c.OCIManagedCluster, infrastructurev1beta2.ClusterReadyCondition, reason, severity, messageFormat, messageArgs...) diff --git a/cloud/scope/oci_selfmanaged_cluster.go b/cloud/scope/oci_selfmanaged_cluster.go index 2e7b60bf..1b89192a 100644 --- a/cloud/scope/oci_selfmanaged_cluster.go +++ b/cloud/scope/oci_selfmanaged_cluster.go @@ -36,6 +36,10 @@ func (c OCISelfManagedCluster) GetRegion() string { return c.OCICluster.Spec.Region } +func (c OCISelfManagedCluster) GetClientHostUrls() *infrastructurev1beta2.ClusterClientHostUrls { + return c.OCICluster.Spec.ClientHostUrls +} + func (c OCISelfManagedCluster) GetIdentityRef() *corev1.ObjectReference { return c.OCICluster.Spec.IdentityRef } diff --git a/cloud/util/util.go b/cloud/util/util.go index 93003243..93486088 100644 --- a/cloud/util/util.go +++ b/cloud/util/util.go @@ -51,7 +51,7 @@ func GetClusterIdentityFromRef(ctx context.Context, c client.Client, ociClusterN } // GetOrBuildClientFromIdentity creates ClientProvider from OCIClusterIdentity object -func GetOrBuildClientFromIdentity(ctx context.Context, c client.Client, identity *infrastructurev1beta2.OCIClusterIdentity, defaultRegion string) (*scope.ClientProvider, error) { +func GetOrBuildClientFromIdentity(ctx context.Context, c client.Client, identity *infrastructurev1beta2.OCIClusterIdentity, defaultRegion string, clientHostUrls *infrastructurev1beta2.ClusterClientHostUrls) (*scope.ClientProvider, error) { if identity.Spec.Type == infrastructurev1beta2.UserPrincipal { secretRef := identity.Spec.PrincipalSecret key := types.NamespacedName{ @@ -82,7 +82,7 @@ func GetOrBuildClientFromIdentity(ctx context.Context, c client.Client, identity privatekey, common.String(passphrase)) - clientProvider, err := scope.NewClientProvider(conf) + clientProvider, err := scope.NewClientProvider(conf, clientHostUrls) if err != nil { return nil, err } @@ -155,13 +155,22 @@ func InitClientsAndRegion(ctx context.Context, client client.Client, defaultRegi return nil, "", scope.OCIClients{}, err } clusterRegion = region + } else if clusterAccessor.GetClientHostUrls() != nil { + // IdentityRef provider will be created with client host url overrides + // but if no identityRef we will want to create a new client provider with the overrides + clientProvider, err = scope.NewClientProvider(defaultClientProvider.GetAuthProvider(), clusterAccessor.GetClientHostUrls()) + if err != nil { + return nil, "", scope.OCIClients{}, err + } } else { clientProvider = defaultClientProvider } + if clientProvider == nil { return nil, "", scope.OCIClients{}, errors.New("OCI authentication credentials could not be retrieved from pod or cluster level," + "please install Cluster API Provider for OCI with OCI authentication credentials or set Cluster Identity in the OCICluster") } + // Region set at cluster takes highest precedence if len(clusterAccessor.GetRegion()) > 0 { clusterRegion = clusterAccessor.GetRegion() @@ -186,7 +195,8 @@ func CreateClientProviderFromClusterIdentity(ctx context.Context, client client. clusterAccessor.MarkConditionFalse(infrastructurev1beta2.ClusterReadyCondition, infrastructurev1beta2.NamespaceNotAllowedByIdentity, clusterv1.ConditionSeverityError, "") return nil, errors.Errorf("OCIClusterIdentity list of allowed namespaces doesn't include current cluster namespace %s", namespace) } - clientProvider, err := GetOrBuildClientFromIdentity(ctx, client, identity, defaultRegion) + + clientProvider, err := GetOrBuildClientFromIdentity(ctx, client, identity, defaultRegion, clusterAccessor.GetClientHostUrls()) if err != nil { return nil, err } diff --git a/cloud/util/util_test.go b/cloud/util/util_test.go index 0900c42b..0cd208d6 100644 --- a/cloud/util/util_test.go +++ b/cloud/util/util_test.go @@ -161,7 +161,7 @@ func TestGetOrBuildClientFromIdentity(t *testing.T) { t.Run(tt.name, func(t *testing.T) { g := NewWithT(t) client := fake.NewClientBuilder().WithObjects(tt.objects...).Build() - _, err := GetOrBuildClientFromIdentity(context.Background(), client, tt.clusterIdentity, tt.defaultRegion) + _, err := GetOrBuildClientFromIdentity(context.Background(), client, tt.clusterIdentity, tt.defaultRegion, nil) if tt.errorExpected { g.Expect(err).To(Not(BeNil())) } else { diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_ociclusters.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_ociclusters.yaml index 51bd828f..64bd3d81 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_ociclusters.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_ociclusters.yaml @@ -1124,6 +1124,41 @@ spec: Domain (AD) information in a map where the map key is the AD name and the struct is details about the AD. type: object + clientHostUrls: + description: HostUrls allows the default client SDK URLs to be changed. + nullable: true + properties: + computeClientHost: + description: ComputeClientHost allows the default compute SDK + client URL to be changed. + nullable: true + type: string + computeManagementClientHost: + description: ComputeManagementClientHost allows the default compute + management SDK client URL to be changed. + nullable: true + type: string + containerEngineClientHost: + description: ContainerEngineClientHost allows the default container + engine SDK client URL to be changed. + nullable: true + type: string + identityClientHost: + description: IdentityClientHost allows the default identity SDK + client URL to be changed. + nullable: true + type: string + loadBalancerClientHost: + description: LoadBalancerClientHost allows the default load balancer + SDK client URL to be changed. + nullable: true + type: string + vCNClientHost: + description: VCNClientHost allows the default vcn SDK client URL + to be changed. + nullable: true + type: string + type: object compartmentId: description: Compartment to create the cluster network. type: string diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_ociclustertemplates.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_ociclustertemplates.yaml index 45fe28ee..da6a331e 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_ociclustertemplates.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_ociclustertemplates.yaml @@ -1177,6 +1177,42 @@ spec: map key is the AD name and the struct is details about the AD. type: object + clientHostUrls: + description: HostUrls allows the default client SDK URLs to + be changed. + nullable: true + properties: + computeClientHost: + description: ComputeClientHost allows the default compute + SDK client URL to be changed. + nullable: true + type: string + computeManagementClientHost: + description: ComputeManagementClientHost allows the default + compute management SDK client URL to be changed. + nullable: true + type: string + containerEngineClientHost: + description: ContainerEngineClientHost allows the default + container engine SDK client URL to be changed. + nullable: true + type: string + identityClientHost: + description: IdentityClientHost allows the default identity + SDK client URL to be changed. + nullable: true + type: string + loadBalancerClientHost: + description: LoadBalancerClientHost allows the default + load balancer SDK client URL to be changed. + nullable: true + type: string + vCNClientHost: + description: VCNClientHost allows the default vcn SDK + client URL to be changed. + nullable: true + type: string + type: object compartmentId: description: Compartment to create the cluster network. type: string diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_ocimanagedclusters.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_ocimanagedclusters.yaml index cf8ba387..ab7a2c4c 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_ocimanagedclusters.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_ocimanagedclusters.yaml @@ -1162,6 +1162,41 @@ spec: type: string description: Free-form tags for this resource. type: object + hostUrl: + description: HostUrls allows the default client SDK URLs to be changed. + nullable: true + properties: + computeClientHost: + description: ComputeClientHost allows the default compute SDK + client URL to be changed. + nullable: true + type: string + computeManagementClientHost: + description: ComputeManagementClientHost allows the default compute + management SDK client URL to be changed. + nullable: true + type: string + containerEngineClientHost: + description: ContainerEngineClientHost allows the default container + engine SDK client URL to be changed. + nullable: true + type: string + identityClientHost: + description: IdentityClientHost allows the default identity SDK + client URL to be changed. + nullable: true + type: string + loadBalancerClientHost: + description: LoadBalancerClientHost allows the default load balancer + SDK client URL to be changed. + nullable: true + type: string + vCNClientHost: + description: VCNClientHost allows the default vcn SDK client URL + to be changed. + nullable: true + type: string + type: object identityRef: description: IdentityRef is a reference to an identity(principal) to be used when reconciling this cluster diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_ocimanagedclustertemplates.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_ocimanagedclustertemplates.yaml index 15e69514..a690ce3d 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_ocimanagedclustertemplates.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_ocimanagedclustertemplates.yaml @@ -1219,6 +1219,42 @@ spec: type: string description: Free-form tags for this resource. type: object + hostUrl: + description: HostUrls allows the default client SDK URLs to + be changed. + nullable: true + properties: + computeClientHost: + description: ComputeClientHost allows the default compute + SDK client URL to be changed. + nullable: true + type: string + computeManagementClientHost: + description: ComputeManagementClientHost allows the default + compute management SDK client URL to be changed. + nullable: true + type: string + containerEngineClientHost: + description: ContainerEngineClientHost allows the default + container engine SDK client URL to be changed. + nullable: true + type: string + identityClientHost: + description: IdentityClientHost allows the default identity + SDK client URL to be changed. + nullable: true + type: string + loadBalancerClientHost: + description: LoadBalancerClientHost allows the default + load balancer SDK client URL to be changed. + nullable: true + type: string + vCNClientHost: + description: VCNClientHost allows the default vcn SDK + client URL to be changed. + nullable: true + type: string + type: object identityRef: description: IdentityRef is a reference to an identity(principal) to be used when reconciling this cluster diff --git a/exp/api/v1beta1/ocimanagedcluster_conversion.go b/exp/api/v1beta1/ocimanagedcluster_conversion.go index e9e3f507..1a37c53d 100644 --- a/exp/api/v1beta1/ocimanagedcluster_conversion.go +++ b/exp/api/v1beta1/ocimanagedcluster_conversion.go @@ -49,6 +49,7 @@ func (src *OCIManagedCluster) ConvertTo(dstRaw conversion.Hub) error { dst.Spec.NetworkSpec.Vcn.InternetGateway.Skip = restored.Spec.NetworkSpec.Vcn.InternetGateway.Skip dst.Spec.NetworkSpec.Vcn.RouteTable.Skip = restored.Spec.NetworkSpec.Vcn.RouteTable.Skip dst.Spec.NetworkSpec.APIServerLB.LoadBalancerType = restored.Spec.NetworkSpec.APIServerLB.LoadBalancerType + dst.Spec.ClientHostUrls = restored.Spec.ClientHostUrls return nil } diff --git a/exp/api/v1beta1/zz_generated.conversion.go b/exp/api/v1beta1/zz_generated.conversion.go index 398853cc..af159c79 100644 --- a/exp/api/v1beta1/zz_generated.conversion.go +++ b/exp/api/v1beta1/zz_generated.conversion.go @@ -1254,6 +1254,7 @@ func autoConvert_v1beta2_OCIManagedClusterSpec_To_v1beta1_OCIManagedClusterSpec( out.Region = in.Region out.ControlPlaneEndpoint = in.ControlPlaneEndpoint // WARNING: in.AvailabilityDomains requires manual conversion: does not exist in peer-type + // WARNING: in.ClientHostUrls requires manual conversion: does not exist in peer-type return nil } diff --git a/exp/api/v1beta2/ocimanagedcluster_types.go b/exp/api/v1beta2/ocimanagedcluster_types.go index c19a8d0b..5983db92 100644 --- a/exp/api/v1beta2/ocimanagedcluster_types.go +++ b/exp/api/v1beta2/ocimanagedcluster_types.go @@ -71,6 +71,12 @@ type OCIManagedClusterSpec struct { // where the map key is the AD name and the struct is details about the AD. // +optional AvailabilityDomains map[string]infrastructurev1beta2.OCIAvailabilityDomain `json:"availabilityDomains,omitempty"` + + // HostUrls allows the default client SDK URLs to be changed. + // + // +optional + // +nullable + ClientHostUrls *infrastructurev1beta2.ClusterClientHostUrls `json:"hostUrl,omitempty"` } // OCIManagedClusterStatus defines the observed state of OCICluster diff --git a/exp/api/v1beta2/zz_generated.deepcopy.go b/exp/api/v1beta2/zz_generated.deepcopy.go index e6ec94cd..30eafa0c 100644 --- a/exp/api/v1beta2/zz_generated.deepcopy.go +++ b/exp/api/v1beta2/zz_generated.deepcopy.go @@ -770,6 +770,11 @@ func (in *OCIManagedClusterSpec) DeepCopyInto(out *OCIManagedClusterSpec) { (*out)[key] = *val.DeepCopy() } } + if in.ClientHostUrls != nil { + in, out := &in.ClientHostUrls, &out.ClientHostUrls + *out = new(apiv1beta2.ClusterClientHostUrls) + (*in).DeepCopyInto(*out) + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new OCIManagedClusterSpec. diff --git a/main.go b/main.go index 92beca28..e269b726 100644 --- a/main.go +++ b/main.go @@ -185,7 +185,7 @@ func main() { os.Exit(1) } - clientProvider, err = scope.NewClientProvider(ociAuthConfigProvider) + clientProvider, err = scope.NewClientProvider(ociAuthConfigProvider, nil) if err != nil { setupLog.Error(err, "unable to create OCI ClientProvider") os.Exit(1) diff --git a/test/e2e/e2e_suite_test.go b/test/e2e/e2e_suite_test.go index 0d841a40..09b41b6c 100644 --- a/test/e2e/e2e_suite_test.go +++ b/test/e2e/e2e_suite_test.go @@ -226,7 +226,7 @@ var _ = SynchronizedBeforeSuite(func() []byte { By("Using user principal as auth provider") } - clientProvider, err := scope.NewClientProvider(ociAuthConfigProvider) + clientProvider, err := scope.NewClientProvider(ociAuthConfigProvider, nil) Expect(err).NotTo(HaveOccurred()) region, err := ociAuthConfigProvider.Region() From b529b3ce5a93386bd365991b6713ad7cc4366a3b Mon Sep 17 00:00:00 2001 From: Joe Kratzat Date: Tue, 25 Apr 2023 12:09:42 -0400 Subject: [PATCH 2/3] Update the structs and adding tests. --- api/v1beta1/ocicluster_conversion.go | 2 +- api/v1beta1/ociclustertemplate_conversion.go | 2 +- api/v1beta1/zz_generated.conversion.go | 2 +- api/v1beta2/ocicluster_types.go | 32 +++--- api/v1beta2/zz_generated.deepcopy.go | 38 +++---- cloud/scope/clients.go | 43 ++++--- cloud/scope/clients_test.go | 107 +++++++++++++++++- cloud/scope/cluster_accessor.go | 4 +- cloud/scope/oci_managed_cluster.go | 4 +- cloud/scope/oci_selfmanaged_cluster.go | 4 +- cloud/util/util.go | 14 ++- ...tructure.cluster.x-k8s.io_ociclusters.yaml | 31 ++--- ....cluster.x-k8s.io_ociclustertemplates.yaml | 32 +++--- ...e.cluster.x-k8s.io_ocimanagedclusters.yaml | 29 ++--- ...r.x-k8s.io_ocimanagedclustertemplates.yaml | 30 ++--- .../v1beta1/ocimanagedcluster_conversion.go | 2 +- exp/api/v1beta1/zz_generated.conversion.go | 2 +- exp/api/v1beta2/ocimanagedcluster_types.go | 4 +- exp/api/v1beta2/zz_generated.deepcopy.go | 6 +- main.go | 3 +- test/e2e/e2e_suite_test.go | 4 +- 21 files changed, 257 insertions(+), 138 deletions(-) diff --git a/api/v1beta1/ocicluster_conversion.go b/api/v1beta1/ocicluster_conversion.go index ce1bbd04..94ded4cb 100644 --- a/api/v1beta1/ocicluster_conversion.go +++ b/api/v1beta1/ocicluster_conversion.go @@ -48,7 +48,7 @@ func (src *OCICluster) ConvertTo(dstRaw conversion.Hub) error { dst.Spec.NetworkSpec.Vcn.InternetGateway.Skip = restored.Spec.NetworkSpec.Vcn.InternetGateway.Skip dst.Spec.NetworkSpec.Vcn.RouteTable.Skip = restored.Spec.NetworkSpec.Vcn.RouteTable.Skip dst.Spec.NetworkSpec.APIServerLB.LoadBalancerType = restored.Spec.NetworkSpec.APIServerLB.LoadBalancerType - dst.Spec.ClientHostUrls = restored.Spec.ClientHostUrls + dst.Spec.ClientOverrides = restored.Spec.ClientOverrides return nil } diff --git a/api/v1beta1/ociclustertemplate_conversion.go b/api/v1beta1/ociclustertemplate_conversion.go index dcf3ce0d..69353ab9 100644 --- a/api/v1beta1/ociclustertemplate_conversion.go +++ b/api/v1beta1/ociclustertemplate_conversion.go @@ -42,7 +42,7 @@ func (src *OCIClusterTemplate) ConvertTo(dstRaw conversion.Hub) error { dst.Spec.Template.Spec.NetworkSpec.Vcn.RouteTable.Skip = restored.Spec.Template.Spec.NetworkSpec.Vcn.RouteTable.Skip dst.Spec.Template.Spec.AvailabilityDomains = restored.Spec.Template.Spec.AvailabilityDomains dst.Spec.Template.Spec.NetworkSpec.APIServerLB.LoadBalancerType = restored.Spec.Template.Spec.NetworkSpec.APIServerLB.LoadBalancerType - dst.Spec.Template.Spec.ClientHostUrls = restored.Spec.Template.Spec.ClientHostUrls + dst.Spec.Template.Spec.ClientOverrides = restored.Spec.Template.Spec.ClientOverrides return nil } diff --git a/api/v1beta1/zz_generated.conversion.go b/api/v1beta1/zz_generated.conversion.go index 6bdd4151..7c6b2869 100644 --- a/api/v1beta1/zz_generated.conversion.go +++ b/api/v1beta1/zz_generated.conversion.go @@ -1549,7 +1549,7 @@ func autoConvert_v1beta2_OCIClusterSpec_To_v1beta1_OCIClusterSpec(in *v1beta2.OC out.Region = in.Region out.ControlPlaneEndpoint = in.ControlPlaneEndpoint // WARNING: in.AvailabilityDomains requires manual conversion: does not exist in peer-type - // WARNING: in.ClientHostUrls requires manual conversion: does not exist in peer-type + // WARNING: in.ClientOverrides requires manual conversion: does not exist in peer-type return nil } diff --git a/api/v1beta2/ocicluster_types.go b/api/v1beta2/ocicluster_types.go index 923a4e74..513e8da0 100644 --- a/api/v1beta2/ocicluster_types.go +++ b/api/v1beta2/ocicluster_types.go @@ -75,11 +75,11 @@ type OCIClusterSpec struct { // +optional AvailabilityDomains map[string]OCIAvailabilityDomain `json:"availabilityDomains,omitempty"` - // HostUrls allows the default client SDK URLs to be changed. + // ClientOverrides allows the default client SDK URLs to be changed. // // +optional // +nullable - ClientHostUrls *ClusterClientHostUrls `json:"clientHostUrls,omitempty"` + ClientOverrides *ClientOverrides `json:"clientOverrides,omitempty"` } // OCIClusterStatus defines the observed state of OCICluster @@ -126,44 +126,44 @@ type OCIAvailabilityDomain struct { FaultDomains []string `json:"faultDomains,omitempty"` } -// ClusterClientHostUrls contains information about client host url overrides. -type ClusterClientHostUrls struct { +// ClientOverrides contains information about client host url overrides. +type ClientOverrides struct { - // ComputeClientHost allows the default compute SDK client URL to be changed. + // ComputeClientUrl allows the default compute SDK client URL to be changed. // // +optional // +nullable - ComputeClientHost *string `json:"computeClientHost,omitempty"` + ComputeClientUrl *string `json:"computeClientUrl,omitempty"` - // ComputeManagementClientHost allows the default compute management SDK client URL to be changed. + // ComputeManagementClientUrl allows the default compute management SDK client URL to be changed. // // +optional // +nullable - ComputeManagementClientHost *string `json:"computeManagementClientHost,omitempty"` + ComputeManagementClientUrl *string `json:"computeManagementClientUrl,omitempty"` - // VCNClientHost allows the default vcn SDK client URL to be changed. + // VCNClientUrl allows the default vcn SDK client URL to be changed. // // +optional // +nullable - VCNClientHost *string `json:"vCNClientHost,omitempty"` + VCNClientUrl *string `json:"vCNClientUrl,omitempty"` - // LoadBalancerClientHost allows the default load balancer SDK client URL to be changed. + // LoadBalancerClientUrl allows the default load balancer SDK client URL to be changed. // // +optional // +nullable - LoadBalancerClientHost *string `json:"loadBalancerClientHost,omitempty"` + LoadBalancerClientUrl *string `json:"loadBalancerClientUrl,omitempty"` - // IdentityClientHost allows the default identity SDK client URL to be changed. + // IdentityClientUrl allows the default identity SDK client URL to be changed. // // +optional // +nullable - IdentityClientHost *string `json:"identityClientHost,omitempty"` + IdentityClientUrl *string `json:"identityClientUrl,omitempty"` - // ContainerEngineClientHost allows the default container engine SDK client URL to be changed. + // ContainerEngineClientUrl allows the default container engine SDK client URL to be changed. // // +optional // +nullable - ContainerEngineClientHost *string `json:"containerEngineClientHost,omitempty"` + ContainerEngineClientUrl *string `json:"containerEngineClientUrl,omitempty"` } // GetConditions returns the list of conditions for an OCICluster API object. diff --git a/api/v1beta2/zz_generated.deepcopy.go b/api/v1beta2/zz_generated.deepcopy.go index 2534db0a..87542b81 100644 --- a/api/v1beta2/zz_generated.deepcopy.go +++ b/api/v1beta2/zz_generated.deepcopy.go @@ -265,46 +265,46 @@ func (in *AmdVmPlatformConfig) DeepCopy() *AmdVmPlatformConfig { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ClusterClientHostUrls) DeepCopyInto(out *ClusterClientHostUrls) { +func (in *ClientOverrides) DeepCopyInto(out *ClientOverrides) { *out = *in - if in.ComputeClientHost != nil { - in, out := &in.ComputeClientHost, &out.ComputeClientHost + if in.ComputeClientUrl != nil { + in, out := &in.ComputeClientUrl, &out.ComputeClientUrl *out = new(string) **out = **in } - if in.ComputeManagementClientHost != nil { - in, out := &in.ComputeManagementClientHost, &out.ComputeManagementClientHost + if in.ComputeManagementClientUrl != nil { + in, out := &in.ComputeManagementClientUrl, &out.ComputeManagementClientUrl *out = new(string) **out = **in } - if in.VCNClientHost != nil { - in, out := &in.VCNClientHost, &out.VCNClientHost + if in.VCNClientUrl != nil { + in, out := &in.VCNClientUrl, &out.VCNClientUrl *out = new(string) **out = **in } - if in.LoadBalancerClientHost != nil { - in, out := &in.LoadBalancerClientHost, &out.LoadBalancerClientHost + if in.LoadBalancerClientUrl != nil { + in, out := &in.LoadBalancerClientUrl, &out.LoadBalancerClientUrl *out = new(string) **out = **in } - if in.IdentityClientHost != nil { - in, out := &in.IdentityClientHost, &out.IdentityClientHost + if in.IdentityClientUrl != nil { + in, out := &in.IdentityClientUrl, &out.IdentityClientUrl *out = new(string) **out = **in } - if in.ContainerEngineClientHost != nil { - in, out := &in.ContainerEngineClientHost, &out.ContainerEngineClientHost + if in.ContainerEngineClientUrl != nil { + in, out := &in.ContainerEngineClientUrl, &out.ContainerEngineClientUrl *out = new(string) **out = **in } } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterClientHostUrls. -func (in *ClusterClientHostUrls) DeepCopy() *ClusterClientHostUrls { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClientOverrides. +func (in *ClientOverrides) DeepCopy() *ClientOverrides { if in == nil { return nil } - out := new(ClusterClientHostUrls) + out := new(ClientOverrides) in.DeepCopyInto(out) return out } @@ -1157,9 +1157,9 @@ func (in *OCIClusterSpec) DeepCopyInto(out *OCIClusterSpec) { (*out)[key] = *val.DeepCopy() } } - if in.ClientHostUrls != nil { - in, out := &in.ClientHostUrls, &out.ClientHostUrls - *out = new(ClusterClientHostUrls) + if in.ClientOverrides != nil { + in, out := &in.ClientOverrides, &out.ClientOverrides + *out = new(ClientOverrides) (*in).DeepCopyInto(*out) } } diff --git a/cloud/scope/clients.go b/cloud/scope/clients.go index 3766b07b..6ab4a8d3 100644 --- a/cloud/scope/clients.go +++ b/cloud/scope/clients.go @@ -59,23 +59,32 @@ type ClientProvider struct { ociClients map[string]OCIClients ociClientsLock *sync.RWMutex ociAuthConfigProvider common.ConfigurationProvider - ociClientHostUrls *v1beta2.ClusterClientHostUrls + ociClientOverrides *v1beta2.ClientOverrides +} + +// ClientProviderParams is the params struct for NewClientProvider +type ClientProviderParams struct { + // OciAuthConfigProvider wraps information about the account owner + OciAuthConfigProvider common.ConfigurationProvider + + // ClientOverrides contains information about client host url overrides. + ClientOverrides *v1beta2.ClientOverrides } // NewClientProvider builds the ClientProvider with a client for the given region -func NewClientProvider(ociAuthConfigProvider common.ConfigurationProvider, clientHostUrlOverrides *v1beta2.ClusterClientHostUrls) (*ClientProvider, error) { +func NewClientProvider(params ClientProviderParams) (*ClientProvider, error) { log := klogr.New() - if ociAuthConfigProvider == nil { + if params.OciAuthConfigProvider == nil { return nil, errors.New("ConfigurationProvider can not be nil") } provider := ClientProvider{ Logger: &log, - ociAuthConfigProvider: ociAuthConfigProvider, + ociAuthConfigProvider: params.OciAuthConfigProvider, ociClients: map[string]OCIClients{}, ociClientsLock: new(sync.RWMutex), - ociClientHostUrls: clientHostUrlOverrides, + ociClientOverrides: params.ClientOverrides, } return &provider, nil @@ -173,8 +182,8 @@ func (c *ClientProvider) createVncClient(region string, ociAuthConfigProvider co return nil, err } vcnClient.SetRegion(region) - if c.ociClientHostUrls != nil && c.ociClientHostUrls.VCNClientHost != nil { - vcnClient.Host = *c.ociClientHostUrls.VCNClientHost + if c.ociClientOverrides != nil && c.ociClientOverrides.VCNClientUrl != nil { + vcnClient.Host = *c.ociClientOverrides.VCNClientUrl } vcnClient.Interceptor = setVersionHeader() @@ -200,8 +209,8 @@ func (c *ClientProvider) createLBClient(region string, ociAuthConfigProvider com return nil, err } lbClient.SetRegion(region) - if c.ociClientHostUrls != nil && c.ociClientHostUrls.LoadBalancerClientHost != nil { - lbClient.Host = *c.ociClientHostUrls.LoadBalancerClientHost + if c.ociClientOverrides != nil && c.ociClientOverrides.LoadBalancerClientUrl != nil { + lbClient.Host = *c.ociClientOverrides.LoadBalancerClientUrl } lbClient.Interceptor = setVersionHeader() @@ -216,8 +225,8 @@ func (c *ClientProvider) createIdentityClient(region string, ociAuthConfigProvid } identityClient.SetRegion(region) - if c.ociClientHostUrls != nil && c.ociClientHostUrls.IdentityClientHost != nil { - identityClient.Host = *c.ociClientHostUrls.IdentityClientHost + if c.ociClientOverrides != nil && c.ociClientOverrides.IdentityClientUrl != nil { + identityClient.Host = *c.ociClientOverrides.IdentityClientUrl } identityClient.Interceptor = setVersionHeader() @@ -232,8 +241,8 @@ func (c *ClientProvider) createComputeClient(region string, ociAuthConfigProvide } computeClient.SetRegion(region) //https://dyn.slack.com/archives/C7MS7QWC8/p1675719244230459?thread_ts=1675460644.801049&cid=C7MS7QWC8 - if c.ociClientHostUrls != nil && c.ociClientHostUrls.ComputeClientHost != nil { - computeClient.Host = *c.ociClientHostUrls.ComputeClientHost + if c.ociClientOverrides != nil && c.ociClientOverrides.ComputeClientUrl != nil { + computeClient.Host = *c.ociClientOverrides.ComputeClientUrl } computeClient.Interceptor = setVersionHeader() @@ -247,8 +256,8 @@ func (c *ClientProvider) createComputeManagementClient(region string, ociAuthCon return nil, err } computeManagementClient.SetRegion(region) - if c.ociClientHostUrls != nil && c.ociClientHostUrls.ComputeManagementClientHost != nil { - computeManagementClient.Host = *c.ociClientHostUrls.ComputeManagementClientHost + if c.ociClientOverrides != nil && c.ociClientOverrides.ComputeManagementClientUrl != nil { + computeManagementClient.Host = *c.ociClientOverrides.ComputeManagementClientUrl } computeManagementClient.Interceptor = setVersionHeader() @@ -262,8 +271,8 @@ func (c *ClientProvider) createContainerEngineClient(region string, ociAuthConfi return nil, err } containerEngineClient.SetRegion(region) - if c.ociClientHostUrls != nil && c.ociClientHostUrls.ContainerEngineClientHost != nil { - containerEngineClient.Host = *c.ociClientHostUrls.ContainerEngineClientHost + if c.ociClientOverrides != nil && c.ociClientOverrides.ContainerEngineClientUrl != nil { + containerEngineClient.Host = *c.ociClientOverrides.ContainerEngineClientUrl } containerEngineClient.Interceptor = setVersionHeader() diff --git a/cloud/scope/clients_test.go b/cloud/scope/clients_test.go index 318f2e11..661697f3 100644 --- a/cloud/scope/clients_test.go +++ b/cloud/scope/clients_test.go @@ -21,8 +21,10 @@ import ( "testing" "github.com/golang/mock/gomock" + "github.com/oracle/cluster-api-provider-oci/api/v1beta2" "github.com/oracle/cluster-api-provider-oci/cloud/config" "github.com/oracle/cluster-api-provider-oci/cloud/services/vcn/mock_vcn" + "github.com/oracle/oci-go-sdk/v65/common" ) func TestClients_NewClientProvider(t *testing.T) { @@ -37,7 +39,9 @@ func TestClients_NewClientProvider(t *testing.T) { } - clientProvider, err := NewClientProvider(ociAuthConfigProvider, nil) + clientProvider, err := NewClientProvider(ClientProviderParams{ + ociAuthConfigProvider, + nil}) if err != nil { t.Errorf("Expected %v to equal nil", err) } @@ -47,9 +51,83 @@ func TestClients_NewClientProvider(t *testing.T) { } } -func TestClients_NewClientProviderWithBadAuthConfig(t *testing.T) { +func TestClients_NewClientProviderWithClientOverrides(t *testing.T) { + authConfig, err := MockAuthConfig() + if err != nil { + t.Errorf("Expected error:%v to not equal nil", err) + } + + ociAuthConfigProvider, err := config.NewConfigurationProvider(&authConfig) + if err != nil { + t.Errorf("Expected error:%v to not equal nil", err) + } + + clientOverrides := &v1beta2.ClientOverrides{ + ComputeClientUrl: common.String("ComputeClientUrl"), + ComputeManagementClientUrl: common.String("ComputeManagementClientUrl"), + VCNClientUrl: common.String("VCNClientUrl"), + LoadBalancerClientUrl: common.String("LoadBalancerClientUrl"), + IdentityClientUrl: common.String("IdentityClientUrl"), + ContainerEngineClientUrl: common.String("ContainerEngineClientUrl"), + } + + clientProvider, err := NewClientProvider(ClientProviderParams{ + ociAuthConfigProvider, + clientOverrides}) + if err != nil { + t.Errorf("Expected error:%v to not equal nil", err) + } - clientProvider, err := NewClientProvider(nil, nil) + if clientProvider == nil { + t.Errorf("Expected clientProvider:%v to equal nil", clientProvider) + } + + if !reflect.DeepEqual(clientProvider.ociClientOverrides, clientOverrides) { + t.Errorf("clientProvider.ociClientOverrides: %v doesn't equal clientOverrides: %v", clientProvider.ociClientOverrides, clientOverrides) + } +} + +func TestClients_NewClientProviderWithMissingOverrides(t *testing.T) { + // Wanting to test that no errors are thrown with nil values for + // missing client overrides + + authConfig, err := MockAuthConfig() + if err != nil { + t.Errorf("Expected error:%v to not equal nil", err) + } + + ociAuthConfigProvider, err := config.NewConfigurationProvider(&authConfig) + if err != nil { + t.Errorf("Expected error:%v to not equal nil", err) + } + + clientOverrides := &v1beta2.ClientOverrides{ + ComputeClientUrl: common.String("ComputeClientUrl"), + ComputeManagementClientUrl: common.String("ComputeManagementClientUrl"), + //VCNClientUrl is missing, + LoadBalancerClientUrl: common.String("LoadBalancerClientUrl"), + //IdentityClientUrl is missing, + ContainerEngineClientUrl: common.String("ContainerEngineClientUrl"), + } + + clientProvider, err := NewClientProvider(ClientProviderParams{ + ociAuthConfigProvider, + clientOverrides}) + if err != nil { + t.Errorf("Expected error:%v to not equal nil", err) + } + + if clientProvider == nil { + t.Errorf("Expected clientProvider:%v to equal nil", clientProvider) + } + + if !reflect.DeepEqual(clientProvider.ociClientOverrides, clientOverrides) { + t.Errorf("clientProvider.ociClientOverrides: %v doesn't equal clientOverrides: %v", clientProvider.ociClientOverrides, clientOverrides) + } +} + +func TestClients_NewClientProviderWithBadAuthConfig(t *testing.T) { + clientProvider, err := NewClientProvider(ClientProviderParams{nil, nil}) if err == nil { t.Errorf("Expected error:%v to not equal nil", err) } @@ -118,3 +196,26 @@ func TestClients_ReuseClients(t *testing.T) { t.Errorf("Expected %v to equal %v", secondClients.VCNClient, firstClients.VCNClient) } } + +func TestClients_GetAuthProvider(t *testing.T) { + authConfig, err := MockAuthConfig() + if err != nil { + t.Errorf("Expected error:%v to not equal nil", err) + } + + ociAuthConfigProvider, err := config.NewConfigurationProvider(&authConfig) + if err != nil { + t.Errorf("Expected error:%v to not equal nil", err) + } + + clientProvider, err := NewClientProvider(ClientProviderParams{ + ociAuthConfigProvider, + nil}) + if err != nil { + t.Errorf("Expected %v to equal nil", err) + } + + if clientProvider.GetAuthProvider() != ociAuthConfigProvider { + t.Errorf("returned authprovider %v doesn't equal: %v", clientProvider.GetAuthProvider(), ociAuthConfigProvider) + } +} diff --git a/cloud/scope/cluster_accessor.go b/cloud/scope/cluster_accessor.go index 3d02661d..6b10f339 100644 --- a/cloud/scope/cluster_accessor.go +++ b/cloud/scope/cluster_accessor.go @@ -42,8 +42,8 @@ type OCIClusterAccessor interface { GetNameSpace() string // GetRegion returns the region of the cluster, if specified in the spec. GetRegion() string - // GetClientHostUrls returns the client host url overrides for the cluster - GetClientHostUrls() *infrastructurev1beta2.ClusterClientHostUrls + // GetClientOverrides returns the client host url overrides for the cluster + GetClientOverrides() *infrastructurev1beta2.ClientOverrides // GetNetworkSpec returns the NetworkSpec of the cluster. GetNetworkSpec() *infrastructurev1beta2.NetworkSpec // SetControlPlaneEndpoint sets the control plane endpoint of the cluster. diff --git a/cloud/scope/oci_managed_cluster.go b/cloud/scope/oci_managed_cluster.go index a29dcef2..5c4a60ce 100644 --- a/cloud/scope/oci_managed_cluster.go +++ b/cloud/scope/oci_managed_cluster.go @@ -37,8 +37,8 @@ func (c OCIManagedCluster) GetRegion() string { return c.OCIManagedCluster.Spec.Region } -func (c OCIManagedCluster) GetClientHostUrls() *infrastructurev1beta2.ClusterClientHostUrls { - return c.OCIManagedCluster.Spec.ClientHostUrls +func (c OCIManagedCluster) GetClientOverrides() *infrastructurev1beta2.ClientOverrides { + return c.OCIManagedCluster.Spec.ClientOverrides } func (c OCIManagedCluster) MarkConditionFalse(t clusterv1.ConditionType, reason string, severity clusterv1.ConditionSeverity, messageFormat string, messageArgs ...interface{}) { diff --git a/cloud/scope/oci_selfmanaged_cluster.go b/cloud/scope/oci_selfmanaged_cluster.go index 1b89192a..c9e825d9 100644 --- a/cloud/scope/oci_selfmanaged_cluster.go +++ b/cloud/scope/oci_selfmanaged_cluster.go @@ -36,8 +36,8 @@ func (c OCISelfManagedCluster) GetRegion() string { return c.OCICluster.Spec.Region } -func (c OCISelfManagedCluster) GetClientHostUrls() *infrastructurev1beta2.ClusterClientHostUrls { - return c.OCICluster.Spec.ClientHostUrls +func (c OCISelfManagedCluster) GetClientOverrides() *infrastructurev1beta2.ClientOverrides { + return c.OCICluster.Spec.ClientOverrides } func (c OCISelfManagedCluster) GetIdentityRef() *corev1.ObjectReference { diff --git a/cloud/util/util.go b/cloud/util/util.go index 93486088..435cd8c9 100644 --- a/cloud/util/util.go +++ b/cloud/util/util.go @@ -51,7 +51,7 @@ func GetClusterIdentityFromRef(ctx context.Context, c client.Client, ociClusterN } // GetOrBuildClientFromIdentity creates ClientProvider from OCIClusterIdentity object -func GetOrBuildClientFromIdentity(ctx context.Context, c client.Client, identity *infrastructurev1beta2.OCIClusterIdentity, defaultRegion string, clientHostUrls *infrastructurev1beta2.ClusterClientHostUrls) (*scope.ClientProvider, error) { +func GetOrBuildClientFromIdentity(ctx context.Context, c client.Client, identity *infrastructurev1beta2.OCIClusterIdentity, defaultRegion string, clientOverrides *infrastructurev1beta2.ClientOverrides) (*scope.ClientProvider, error) { if identity.Spec.Type == infrastructurev1beta2.UserPrincipal { secretRef := identity.Spec.PrincipalSecret key := types.NamespacedName{ @@ -82,7 +82,9 @@ func GetOrBuildClientFromIdentity(ctx context.Context, c client.Client, identity privatekey, common.String(passphrase)) - clientProvider, err := scope.NewClientProvider(conf, clientHostUrls) + clientProvider, err := scope.NewClientProvider(scope.ClientProviderParams{ + OciAuthConfigProvider: conf, + ClientOverrides: clientOverrides}) if err != nil { return nil, err } @@ -155,10 +157,12 @@ func InitClientsAndRegion(ctx context.Context, client client.Client, defaultRegi return nil, "", scope.OCIClients{}, err } clusterRegion = region - } else if clusterAccessor.GetClientHostUrls() != nil { + } else if clusterAccessor.GetClientOverrides() != nil { // IdentityRef provider will be created with client host url overrides // but if no identityRef we will want to create a new client provider with the overrides - clientProvider, err = scope.NewClientProvider(defaultClientProvider.GetAuthProvider(), clusterAccessor.GetClientHostUrls()) + clientProvider, err = scope.NewClientProvider(scope.ClientProviderParams{ + OciAuthConfigProvider: defaultClientProvider.GetAuthProvider(), + ClientOverrides: clusterAccessor.GetClientOverrides()}) if err != nil { return nil, "", scope.OCIClients{}, err } @@ -196,7 +200,7 @@ func CreateClientProviderFromClusterIdentity(ctx context.Context, client client. return nil, errors.Errorf("OCIClusterIdentity list of allowed namespaces doesn't include current cluster namespace %s", namespace) } - clientProvider, err := GetOrBuildClientFromIdentity(ctx, client, identity, defaultRegion, clusterAccessor.GetClientHostUrls()) + clientProvider, err := GetOrBuildClientFromIdentity(ctx, client, identity, defaultRegion, clusterAccessor.GetClientOverrides()) if err != nil { return nil, err } diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_ociclusters.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_ociclusters.yaml index 64bd3d81..e842863c 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_ociclusters.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_ociclusters.yaml @@ -1124,37 +1124,38 @@ spec: Domain (AD) information in a map where the map key is the AD name and the struct is details about the AD. type: object - clientHostUrls: - description: HostUrls allows the default client SDK URLs to be changed. + clientOverrides: + description: ClientOverrides allows the default client SDK URLs to + be changed. nullable: true properties: - computeClientHost: - description: ComputeClientHost allows the default compute SDK - client URL to be changed. + computeClientUrl: + description: ComputeClientUrl allows the default compute SDK client + URL to be changed. nullable: true type: string - computeManagementClientHost: - description: ComputeManagementClientHost allows the default compute + computeManagementClientUrl: + description: ComputeManagementClientUrl allows the default compute management SDK client URL to be changed. nullable: true type: string - containerEngineClientHost: - description: ContainerEngineClientHost allows the default container + containerEngineClientUrl: + description: ContainerEngineClientUrl allows the default container engine SDK client URL to be changed. nullable: true type: string - identityClientHost: - description: IdentityClientHost allows the default identity SDK + identityClientUrl: + description: IdentityClientUrl allows the default identity SDK client URL to be changed. nullable: true type: string - loadBalancerClientHost: - description: LoadBalancerClientHost allows the default load balancer + loadBalancerClientUrl: + description: LoadBalancerClientUrl allows the default load balancer SDK client URL to be changed. nullable: true type: string - vCNClientHost: - description: VCNClientHost allows the default vcn SDK client URL + vCNClientUrl: + description: VCNClientUrl allows the default vcn SDK client URL to be changed. nullable: true type: string diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_ociclustertemplates.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_ociclustertemplates.yaml index da6a331e..995fdd77 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_ociclustertemplates.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_ociclustertemplates.yaml @@ -1177,39 +1177,39 @@ spec: map key is the AD name and the struct is details about the AD. type: object - clientHostUrls: - description: HostUrls allows the default client SDK URLs to - be changed. + clientOverrides: + description: ClientOverrides allows the default client SDK + URLs to be changed. nullable: true properties: - computeClientHost: - description: ComputeClientHost allows the default compute + computeClientUrl: + description: ComputeClientUrl allows the default compute SDK client URL to be changed. nullable: true type: string - computeManagementClientHost: - description: ComputeManagementClientHost allows the default + computeManagementClientUrl: + description: ComputeManagementClientUrl allows the default compute management SDK client URL to be changed. nullable: true type: string - containerEngineClientHost: - description: ContainerEngineClientHost allows the default + containerEngineClientUrl: + description: ContainerEngineClientUrl allows the default container engine SDK client URL to be changed. nullable: true type: string - identityClientHost: - description: IdentityClientHost allows the default identity + identityClientUrl: + description: IdentityClientUrl allows the default identity SDK client URL to be changed. nullable: true type: string - loadBalancerClientHost: - description: LoadBalancerClientHost allows the default + loadBalancerClientUrl: + description: LoadBalancerClientUrl allows the default load balancer SDK client URL to be changed. nullable: true type: string - vCNClientHost: - description: VCNClientHost allows the default vcn SDK - client URL to be changed. + vCNClientUrl: + description: VCNClientUrl allows the default vcn SDK client + URL to be changed. nullable: true type: string type: object diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_ocimanagedclusters.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_ocimanagedclusters.yaml index ab7a2c4c..6b76da9a 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_ocimanagedclusters.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_ocimanagedclusters.yaml @@ -1163,36 +1163,37 @@ spec: description: Free-form tags for this resource. type: object hostUrl: - description: HostUrls allows the default client SDK URLs to be changed. + description: ClientOverrides allows the default client SDK URLs to + be changed. nullable: true properties: - computeClientHost: - description: ComputeClientHost allows the default compute SDK - client URL to be changed. + computeClientUrl: + description: ComputeClientUrl allows the default compute SDK client + URL to be changed. nullable: true type: string - computeManagementClientHost: - description: ComputeManagementClientHost allows the default compute + computeManagementClientUrl: + description: ComputeManagementClientUrl allows the default compute management SDK client URL to be changed. nullable: true type: string - containerEngineClientHost: - description: ContainerEngineClientHost allows the default container + containerEngineClientUrl: + description: ContainerEngineClientUrl allows the default container engine SDK client URL to be changed. nullable: true type: string - identityClientHost: - description: IdentityClientHost allows the default identity SDK + identityClientUrl: + description: IdentityClientUrl allows the default identity SDK client URL to be changed. nullable: true type: string - loadBalancerClientHost: - description: LoadBalancerClientHost allows the default load balancer + loadBalancerClientUrl: + description: LoadBalancerClientUrl allows the default load balancer SDK client URL to be changed. nullable: true type: string - vCNClientHost: - description: VCNClientHost allows the default vcn SDK client URL + vCNClientUrl: + description: VCNClientUrl allows the default vcn SDK client URL to be changed. nullable: true type: string diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_ocimanagedclustertemplates.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_ocimanagedclustertemplates.yaml index a690ce3d..a3fb0328 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_ocimanagedclustertemplates.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_ocimanagedclustertemplates.yaml @@ -1220,38 +1220,38 @@ spec: description: Free-form tags for this resource. type: object hostUrl: - description: HostUrls allows the default client SDK URLs to - be changed. + description: ClientOverrides allows the default client SDK + URLs to be changed. nullable: true properties: - computeClientHost: - description: ComputeClientHost allows the default compute + computeClientUrl: + description: ComputeClientUrl allows the default compute SDK client URL to be changed. nullable: true type: string - computeManagementClientHost: - description: ComputeManagementClientHost allows the default + computeManagementClientUrl: + description: ComputeManagementClientUrl allows the default compute management SDK client URL to be changed. nullable: true type: string - containerEngineClientHost: - description: ContainerEngineClientHost allows the default + containerEngineClientUrl: + description: ContainerEngineClientUrl allows the default container engine SDK client URL to be changed. nullable: true type: string - identityClientHost: - description: IdentityClientHost allows the default identity + identityClientUrl: + description: IdentityClientUrl allows the default identity SDK client URL to be changed. nullable: true type: string - loadBalancerClientHost: - description: LoadBalancerClientHost allows the default + loadBalancerClientUrl: + description: LoadBalancerClientUrl allows the default load balancer SDK client URL to be changed. nullable: true type: string - vCNClientHost: - description: VCNClientHost allows the default vcn SDK - client URL to be changed. + vCNClientUrl: + description: VCNClientUrl allows the default vcn SDK client + URL to be changed. nullable: true type: string type: object diff --git a/exp/api/v1beta1/ocimanagedcluster_conversion.go b/exp/api/v1beta1/ocimanagedcluster_conversion.go index 1a37c53d..e13c49dc 100644 --- a/exp/api/v1beta1/ocimanagedcluster_conversion.go +++ b/exp/api/v1beta1/ocimanagedcluster_conversion.go @@ -49,7 +49,7 @@ func (src *OCIManagedCluster) ConvertTo(dstRaw conversion.Hub) error { dst.Spec.NetworkSpec.Vcn.InternetGateway.Skip = restored.Spec.NetworkSpec.Vcn.InternetGateway.Skip dst.Spec.NetworkSpec.Vcn.RouteTable.Skip = restored.Spec.NetworkSpec.Vcn.RouteTable.Skip dst.Spec.NetworkSpec.APIServerLB.LoadBalancerType = restored.Spec.NetworkSpec.APIServerLB.LoadBalancerType - dst.Spec.ClientHostUrls = restored.Spec.ClientHostUrls + dst.Spec.ClientOverrides = restored.Spec.ClientOverrides return nil } diff --git a/exp/api/v1beta1/zz_generated.conversion.go b/exp/api/v1beta1/zz_generated.conversion.go index af159c79..43fea9c1 100644 --- a/exp/api/v1beta1/zz_generated.conversion.go +++ b/exp/api/v1beta1/zz_generated.conversion.go @@ -1254,7 +1254,7 @@ func autoConvert_v1beta2_OCIManagedClusterSpec_To_v1beta1_OCIManagedClusterSpec( out.Region = in.Region out.ControlPlaneEndpoint = in.ControlPlaneEndpoint // WARNING: in.AvailabilityDomains requires manual conversion: does not exist in peer-type - // WARNING: in.ClientHostUrls requires manual conversion: does not exist in peer-type + // WARNING: in.ClientOverrides requires manual conversion: does not exist in peer-type return nil } diff --git a/exp/api/v1beta2/ocimanagedcluster_types.go b/exp/api/v1beta2/ocimanagedcluster_types.go index 5983db92..2a75cc2f 100644 --- a/exp/api/v1beta2/ocimanagedcluster_types.go +++ b/exp/api/v1beta2/ocimanagedcluster_types.go @@ -72,11 +72,11 @@ type OCIManagedClusterSpec struct { // +optional AvailabilityDomains map[string]infrastructurev1beta2.OCIAvailabilityDomain `json:"availabilityDomains,omitempty"` - // HostUrls allows the default client SDK URLs to be changed. + // ClientOverrides allows the default client SDK URLs to be changed. // // +optional // +nullable - ClientHostUrls *infrastructurev1beta2.ClusterClientHostUrls `json:"hostUrl,omitempty"` + ClientOverrides *infrastructurev1beta2.ClientOverrides `json:"hostUrl,omitempty"` } // OCIManagedClusterStatus defines the observed state of OCICluster diff --git a/exp/api/v1beta2/zz_generated.deepcopy.go b/exp/api/v1beta2/zz_generated.deepcopy.go index 30eafa0c..84a5c343 100644 --- a/exp/api/v1beta2/zz_generated.deepcopy.go +++ b/exp/api/v1beta2/zz_generated.deepcopy.go @@ -770,9 +770,9 @@ func (in *OCIManagedClusterSpec) DeepCopyInto(out *OCIManagedClusterSpec) { (*out)[key] = *val.DeepCopy() } } - if in.ClientHostUrls != nil { - in, out := &in.ClientHostUrls, &out.ClientHostUrls - *out = new(apiv1beta2.ClusterClientHostUrls) + if in.ClientOverrides != nil { + in, out := &in.ClientOverrides, &out.ClientOverrides + *out = new(apiv1beta2.ClientOverrides) (*in).DeepCopyInto(*out) } } diff --git a/main.go b/main.go index e269b726..8578e77c 100644 --- a/main.go +++ b/main.go @@ -185,7 +185,8 @@ func main() { os.Exit(1) } - clientProvider, err = scope.NewClientProvider(ociAuthConfigProvider, nil) + clientProvider, err = scope.NewClientProvider(scope.ClientProviderParams{ + OciAuthConfigProvider: ociAuthConfigProvider}) if err != nil { setupLog.Error(err, "unable to create OCI ClientProvider") os.Exit(1) diff --git a/test/e2e/e2e_suite_test.go b/test/e2e/e2e_suite_test.go index 09b41b6c..fa642c09 100644 --- a/test/e2e/e2e_suite_test.go +++ b/test/e2e/e2e_suite_test.go @@ -226,7 +226,9 @@ var _ = SynchronizedBeforeSuite(func() []byte { By("Using user principal as auth provider") } - clientProvider, err := scope.NewClientProvider(ociAuthConfigProvider, nil) + clientProvider, err := scope.NewClientProvider(scope.ClientProviderParams{ + ociAuthConfigProvider, + nil}) Expect(err).NotTo(HaveOccurred()) region, err := ociAuthConfigProvider.Region() From 207cd1e322cfb316dddc57ab59841349ad4aee44 Mon Sep 17 00:00:00 2001 From: Joe Kratzat Date: Wed, 26 Apr 2023 08:55:25 -0400 Subject: [PATCH 3/3] add NLB client override support --- api/v1beta2/ocicluster_types.go | 6 ++++++ api/v1beta2/zz_generated.deepcopy.go | 5 +++++ cloud/scope/clients.go | 4 +++- cloud/scope/clients_test.go | 14 ++++++++------ ...nfrastructure.cluster.x-k8s.io_ociclusters.yaml | 5 +++++ ...cture.cluster.x-k8s.io_ociclustertemplates.yaml | 5 +++++ ...ucture.cluster.x-k8s.io_ocimanagedclusters.yaml | 5 +++++ ...luster.x-k8s.io_ocimanagedclustertemplates.yaml | 5 +++++ 8 files changed, 42 insertions(+), 7 deletions(-) diff --git a/api/v1beta2/ocicluster_types.go b/api/v1beta2/ocicluster_types.go index 513e8da0..4858aeb2 100644 --- a/api/v1beta2/ocicluster_types.go +++ b/api/v1beta2/ocicluster_types.go @@ -153,6 +153,12 @@ type ClientOverrides struct { // +nullable LoadBalancerClientUrl *string `json:"loadBalancerClientUrl,omitempty"` + // NetworkLoadBalancerClientUrl allows the default NLB SDK client URL to be changed. + // + // +optional + // +nullable + NetworkLoadBalancerClientUrl *string `json:"networkLoadBalancerClientUrl,omitempty"` + // IdentityClientUrl allows the default identity SDK client URL to be changed. // // +optional diff --git a/api/v1beta2/zz_generated.deepcopy.go b/api/v1beta2/zz_generated.deepcopy.go index 87542b81..110af64e 100644 --- a/api/v1beta2/zz_generated.deepcopy.go +++ b/api/v1beta2/zz_generated.deepcopy.go @@ -287,6 +287,11 @@ func (in *ClientOverrides) DeepCopyInto(out *ClientOverrides) { *out = new(string) **out = **in } + if in.NetworkLoadBalancerClientUrl != nil { + in, out := &in.NetworkLoadBalancerClientUrl, &out.NetworkLoadBalancerClientUrl + *out = new(string) + **out = **in + } if in.IdentityClientUrl != nil { in, out := &in.IdentityClientUrl, &out.IdentityClientUrl *out = new(string) diff --git a/cloud/scope/clients.go b/cloud/scope/clients.go index 6ab4a8d3..f966ee84 100644 --- a/cloud/scope/clients.go +++ b/cloud/scope/clients.go @@ -197,6 +197,9 @@ func (c *ClientProvider) createNLbClient(region string, ociAuthConfigProvider co return nil, err } nlbClient.SetRegion(region) + if c.ociClientOverrides != nil && c.ociClientOverrides.NetworkLoadBalancerClientUrl != nil { + nlbClient.Host = *c.ociClientOverrides.NetworkLoadBalancerClientUrl + } nlbClient.Interceptor = setVersionHeader() return &nlbClient, nil @@ -240,7 +243,6 @@ func (c *ClientProvider) createComputeClient(region string, ociAuthConfigProvide return nil, err } computeClient.SetRegion(region) - //https://dyn.slack.com/archives/C7MS7QWC8/p1675719244230459?thread_ts=1675460644.801049&cid=C7MS7QWC8 if c.ociClientOverrides != nil && c.ociClientOverrides.ComputeClientUrl != nil { computeClient.Host = *c.ociClientOverrides.ComputeClientUrl } diff --git a/cloud/scope/clients_test.go b/cloud/scope/clients_test.go index 661697f3..6007eee0 100644 --- a/cloud/scope/clients_test.go +++ b/cloud/scope/clients_test.go @@ -63,12 +63,13 @@ func TestClients_NewClientProviderWithClientOverrides(t *testing.T) { } clientOverrides := &v1beta2.ClientOverrides{ - ComputeClientUrl: common.String("ComputeClientUrl"), - ComputeManagementClientUrl: common.String("ComputeManagementClientUrl"), - VCNClientUrl: common.String("VCNClientUrl"), - LoadBalancerClientUrl: common.String("LoadBalancerClientUrl"), - IdentityClientUrl: common.String("IdentityClientUrl"), - ContainerEngineClientUrl: common.String("ContainerEngineClientUrl"), + ComputeClientUrl: common.String("ComputeClientUrl"), + ComputeManagementClientUrl: common.String("ComputeManagementClientUrl"), + VCNClientUrl: common.String("VCNClientUrl"), + LoadBalancerClientUrl: common.String("LoadBalancerClientUrl"), + NetworkLoadBalancerClientUrl: common.String("NetworkLoadBalancerClientUrl"), + IdentityClientUrl: common.String("IdentityClientUrl"), + ContainerEngineClientUrl: common.String("ContainerEngineClientUrl"), } clientProvider, err := NewClientProvider(ClientProviderParams{ @@ -106,6 +107,7 @@ func TestClients_NewClientProviderWithMissingOverrides(t *testing.T) { ComputeManagementClientUrl: common.String("ComputeManagementClientUrl"), //VCNClientUrl is missing, LoadBalancerClientUrl: common.String("LoadBalancerClientUrl"), + //NetworkLoadBalancerClientUrl is missing, //IdentityClientUrl is missing, ContainerEngineClientUrl: common.String("ContainerEngineClientUrl"), } diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_ociclusters.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_ociclusters.yaml index e842863c..038e2834 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_ociclusters.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_ociclusters.yaml @@ -1154,6 +1154,11 @@ spec: SDK client URL to be changed. nullable: true type: string + networkLoadBalancerClientUrl: + description: NetworkLoadBalancerClientUrl allows the default NLB + SDK client URL to be changed. + nullable: true + type: string vCNClientUrl: description: VCNClientUrl allows the default vcn SDK client URL to be changed. diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_ociclustertemplates.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_ociclustertemplates.yaml index 995fdd77..c1c353fc 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_ociclustertemplates.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_ociclustertemplates.yaml @@ -1207,6 +1207,11 @@ spec: load balancer SDK client URL to be changed. nullable: true type: string + networkLoadBalancerClientUrl: + description: NetworkLoadBalancerClientUrl allows the default + NLB SDK client URL to be changed. + nullable: true + type: string vCNClientUrl: description: VCNClientUrl allows the default vcn SDK client URL to be changed. diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_ocimanagedclusters.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_ocimanagedclusters.yaml index 6b76da9a..c6579050 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_ocimanagedclusters.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_ocimanagedclusters.yaml @@ -1192,6 +1192,11 @@ spec: SDK client URL to be changed. nullable: true type: string + networkLoadBalancerClientUrl: + description: NetworkLoadBalancerClientUrl allows the default NLB + SDK client URL to be changed. + nullable: true + type: string vCNClientUrl: description: VCNClientUrl allows the default vcn SDK client URL to be changed. diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_ocimanagedclustertemplates.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_ocimanagedclustertemplates.yaml index a3fb0328..c0503c2b 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_ocimanagedclustertemplates.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_ocimanagedclustertemplates.yaml @@ -1249,6 +1249,11 @@ spec: load balancer SDK client URL to be changed. nullable: true type: string + networkLoadBalancerClientUrl: + description: NetworkLoadBalancerClientUrl allows the default + NLB SDK client URL to be changed. + nullable: true + type: string vCNClientUrl: description: VCNClientUrl allows the default vcn SDK client URL to be changed.