Skip to content

Commit

Permalink
Removing provider flag (#451)
Browse files Browse the repository at this point in the history
* Removing hardcoded provider support

* Changelog entry

* Removing openstack, moving kinds to internal package, fixing tests

* Adding AWSManagedCluster support

* Adding two more managed kinds
  • Loading branch information
ljakimczuk authored Feb 1, 2024
1 parent 0b7bc3e commit 87c8e02
Show file tree
Hide file tree
Showing 17 changed files with 204 additions and 182 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Removed

- Remove OpenStack support.

### Changed

- The provider information source of truth is changed from the configuration option to Cluster CRs.

## [2.18.1] - 2024-01-29

### Fixed
Expand Down
7 changes: 0 additions & 7 deletions flag/service/provider/provider.go

This file was deleted.

2 changes: 0 additions & 2 deletions flag/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

"github.com/giantswarm/cluster-apps-operator/v2/flag/service/app"
"github.com/giantswarm/cluster-apps-operator/v2/flag/service/image"
"github.com/giantswarm/cluster-apps-operator/v2/flag/service/provider"
"github.com/giantswarm/cluster-apps-operator/v2/flag/service/proxy"
"github.com/giantswarm/cluster-apps-operator/v2/flag/service/workload"
)
Expand All @@ -15,7 +14,6 @@ type Service struct {
App app.App
Image image.Image
Kubernetes kubernetes.Kubernetes
Provider provider.Provider
Workload workload.Workload
Proxy proxy.Proxy
}
2 changes: 0 additions & 2 deletions helm/cluster-apps-operator/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ data:
caFile: ''
crtFile: ''
keyFile: ''
provider:
kind: {{ .Values.provider.kind }}
proxy:
noProxy: {{ .Values.proxy.noProxy }}
http: {{ .Values.proxy.http }}
Expand Down
8 changes: 0 additions & 8 deletions helm/cluster-apps-operator/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,6 @@
}
}
},
"provider": {
"type": "object",
"properties": {
"kind": {
"type": "string"
}
}
},
"proxy": {
"type": "object",
"properties": {
Expand Down
3 changes: 0 additions & 3 deletions helm/cluster-apps-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ baseDomain: ""

managementClusterID: ""

provider:
kind: ""

proxy:
noProxy: ""
http: ""
Expand Down
2 changes: 0 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,6 @@ func mainE(ctx context.Context) error {
daemonCommand.PersistentFlags().String(f.Service.Kubernetes.TLS.CrtFile, "", "Certificate file path to use to authenticate with Kubernetes.")
daemonCommand.PersistentFlags().String(f.Service.Kubernetes.TLS.KeyFile, "", "Key file path to use to authenticate with Kubernetes.")

daemonCommand.PersistentFlags().String(f.Service.Provider.Kind, "", "Provider of management cluster this operator is running in. Used to determine provider-specific cluster values.")

daemonCommand.PersistentFlags().String(f.Service.Workload.Cluster.BaseDomain, "", "Cluster owner base domain.")
daemonCommand.PersistentFlags().String(f.Service.Workload.Cluster.Calico.CIDR, "", "Prefix length for the CIDR block used by Calico.")
daemonCommand.PersistentFlags().String(f.Service.Workload.Cluster.Calico.Subnet, "", "Network address for the CIDR block used by Calico.")
Expand Down
2 changes: 0 additions & 2 deletions service/controller/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ type ClusterConfig struct {
ClusterIPRange string
DNSIP string
ManagementClusterID string
Provider string
RegistryDomain string
Proxy proxy.Proxy
}
Expand Down Expand Up @@ -120,7 +119,6 @@ func newClusterResources(config ClusterConfig) ([]resource.Interface, error) {
ClusterIPRange: config.ClusterIPRange,
DNSIP: config.DNSIP,
ManagementClusterID: config.ManagementClusterID,
Provider: config.Provider,
RegistryDomain: config.RegistryDomain,
Proxy: config.Proxy,
}
Expand Down
41 changes: 21 additions & 20 deletions service/controller/resource/clusterconfigmap/desired.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/yaml"

capz "github.com/giantswarm/cluster-apps-operator/v2/api/capz/v1alpha4"
"github.com/giantswarm/cluster-apps-operator/v2/pkg/project"
"github.com/giantswarm/cluster-apps-operator/v2/service/controller/key"
infra "github.com/giantswarm/cluster-apps-operator/v2/service/internal/infrastructure"
"github.com/giantswarm/cluster-apps-operator/v2/service/internal/podcidr"
)

Expand Down Expand Up @@ -103,6 +103,7 @@ func (r *Resource) GetDesiredState(ctx context.Context, obj interface{}) ([]*cor
}

var (
provider = ""
// clusterCIDR is only used on azure.
clusterCIDR = ""
// gcpProject is only used on gcp.
Expand All @@ -114,19 +115,10 @@ func (r *Resource) GetDesiredState(ctx context.Context, obj interface{}) ([]*cor
{
infrastructureRef := cr.Spec.InfrastructureRef
if infrastructureRef != nil {
switch r.provider {
case "azure":
var azureCluster capz.AzureCluster
err = r.k8sClient.CtrlClient().Get(ctx, client.ObjectKey{Namespace: infrastructureRef.Namespace, Name: infrastructureRef.Name}, &azureCluster)
if err != nil {
return nil, microerror.Mask(err)
}
switch infrastructureRef.Kind {
case infra.AzureClusterKind, infra.AzureManagedClusterKind:
provider = infra.AzureClusterKindProvider

blocks := azureCluster.Spec.NetworkSpec.Vnet.CIDRBlocks
if len(blocks) > 0 {
clusterCIDR = blocks[0]
}
case "capz":
capzCluster := &unstructured.Unstructured{}
capzCluster.SetGroupVersionKind(schema.GroupVersionKind{
Group: infrastructureRef.GroupVersionKind().Group,
Expand Down Expand Up @@ -154,8 +146,9 @@ func (r *Resource) GetDesiredState(ctx context.Context, obj interface{}) ([]*cor

privateCluster = apiServerLbType == "Internal"

case "aws":
case "capa":
case infra.AWSClusterKind, infra.AWSManagedClusterKind:
provider = infra.AWSClusterKindProvider

awsCluster := &unstructured.Unstructured{}
awsCluster.SetGroupVersionKind(schema.GroupVersionKind{
Group: infrastructureRef.GroupVersionKind().Group,
Expand All @@ -176,9 +169,15 @@ func (r *Resource) GetDesiredState(ctx context.Context, obj interface{}) ([]*cor
}

privateCluster = annotationValue == annotation.AWSVPCModePrivate
case "cloud-director", "openstack", "vsphere":
case infra.VCDClusterKind:
provider = infra.VCDClusterKindProvider
privateCluster = !reflect.ValueOf(r.proxy).IsZero()
case infra.VSphereClusterKind:
provider = infra.VSphereClusterKindProvider
privateCluster = !reflect.ValueOf(r.proxy).IsZero()
case "gcp":
case infra.GCPClusterKind, infra.GCPManagedClusterKind:
provider = infra.GCPClusterKindProvider

gcpCluster := &unstructured.Unstructured{}
gcpCluster.SetGroupVersionKind(schema.GroupVersionKind{
Group: infrastructureRef.GroupVersionKind().Group,
Expand All @@ -198,8 +197,10 @@ func (r *Resource) GetDesiredState(ctx context.Context, obj interface{}) ([]*cor
return nil, fieldNotFoundOnInfrastructureTypeError
}
default:
r.logger.Debugf(ctx, "unable to extract infrastructure provider-specific clusterValues for cluster. Unsupported infrastructure kind %q", r.provider)
r.logger.Debugf(ctx, "unable to extract infrastructure provider-specific clusterValues for cluster. Unsupported infrastructure kind %q", infrastructureRef.Kind)
}
} else {
return nil, microerror.Maskf(infrastructureRefNotFoundError, "%T.spec.infrastructureRef must not be empty", cr)
}
}

Expand All @@ -209,7 +210,7 @@ func (r *Resource) GetDesiredState(ctx context.Context, obj interface{}) ([]*cor
"workloadClusterID": key.ClusterID(&cr),
},
"provider": map[string]interface{}{
"kind": r.provider,
"kind": provider,
},
"registry": map[string]interface{}{
"domain": r.registryDomain,
Expand Down Expand Up @@ -263,7 +264,7 @@ func (r *Resource) GetDesiredState(ctx context.Context, obj interface{}) ([]*cor
ClusterID: key.ClusterID(&cr),
ClusterCIDR: clusterCIDR,
GcpProject: gcpProject,
Provider: r.provider,
Provider: provider,
}

// disable boostrap mode and do not install CNI for EKS cluster
Expand Down
Loading

0 comments on commit 87c8e02

Please sign in to comment.