Skip to content
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

cluster template for vsphere #1129

Merged
merged 6 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .nancy-ignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ CVE-2022-29153 until=2023-11-01
# # This is present in the current latest v0.26.0 as well
CVE-2020-8561 until=2023-11-01

# pkg:golang/golang.org/x/net@v0.13.0 the security fix hasn't been backported to golang@1.19 yet - https://github.com/golang/go/issues/63417
CVE-2023-39325 until=2023-12-01

4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ and this project's packages adheres to [Semantic Versioning](http://semver.org/s

- `kubectl-gs login`: listen only on localhost for callbacks

### Added

- `cluster template` for up-to-date vsphere cluster app.

## [2.43.0] - 2023-10-11

### Added
Expand Down
1 change: 1 addition & 0 deletions cmd/gitops/add/base/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func supportedProviders() []string {
key.ProviderCAPZ,
key.ProviderGCP,
key.ProviderOpenStack,
key.ProviderVSphere,
}
}

Expand Down
45 changes: 45 additions & 0 deletions cmd/gitops/add/base/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

templateapp "github.com/giantswarm/kubectl-gs/v2/pkg/template/app"

"github.com/giantswarm/kubectl-gs/v2/cmd/template/cluster/provider/templates/capv"
"github.com/giantswarm/kubectl-gs/v2/cmd/template/cluster/provider/templates/capz"
"github.com/giantswarm/kubectl-gs/v2/cmd/template/cluster/provider/templates/openstack"
"github.com/giantswarm/kubectl-gs/v2/internal/gitops/filesystem/creator"
Expand Down Expand Up @@ -102,6 +103,8 @@ func generateClusterBaseTemplates(config common.StructureConfig) (common.Cluster
return generateCapGClusterBaseTemplates(config)
case key.ProviderOpenStack:
return generateCapOClusterBaseTemplates(config)
case key.ProviderVSphere:
return generateCapVClusterBaseTemplates(config)
}

return common.ClusterBaseTemplates{}, invalidProviderError
Expand Down Expand Up @@ -285,6 +288,48 @@ func generateCapOClusterBaseTemplates(structureConfig common.StructureConfig) (c
return clusterBaseTemplates, nil
}

func generateCapVClusterBaseTemplates(structureConfig common.StructureConfig) (common.ClusterBaseTemplates, error) {
clusterBaseTemplates := common.ClusterBaseTemplates{}

clusterAppCr, err := generateClusterAppCrTemplate("cluster-vsphere")

if err != nil {
return clusterBaseTemplates, err
}

clusterConfig := providers.BuildCapvClusterConfig(providers.ClusterConfig{
Name: "${cluster_name}",
Organization: "${organization}",
})
clusterValues, err := capv.GenerateClusterValues(clusterConfig)

if err != nil {
return clusterBaseTemplates, err
}

defaultAppsAppCr, err := generateDefaultAppsAppCrTemplate("default-apps-vsphere")

if err != nil {
return clusterBaseTemplates, err
}

defaultAppsValues, err := capv.GenerateDefaultAppsValues(capv.DefaultAppsConfig{
ClusterName: "${cluster_name}",
Organization: "${organization}",
})

if err != nil {
return clusterBaseTemplates, err
}

clusterBaseTemplates.ClusterAppCr = clusterAppCr
clusterBaseTemplates.ClusterValues = clusterValues
clusterBaseTemplates.DefaultAppsAppCr = defaultAppsAppCr
clusterBaseTemplates.DefaultAppsValues = defaultAppsValues

return clusterBaseTemplates, nil
}

func generateCapZClusterBaseTemplates(structureConfig common.StructureConfig) (common.ClusterBaseTemplates, error) {
clusterBaseTemplates := common.ClusterBaseTemplates{}

Expand Down
60 changes: 58 additions & 2 deletions cmd/template/cluster/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,23 @@ const (
flagOpenStackWorkerMachineFlavor = "worker-machine-flavor"
flagOpenStackWorkerReplicas = "worker-replicas"

// VSphere only.
flagVSphereControlPlaneIP = "vsphere-control-plane-ip"
flagVSphereServiceLoadBalancerCIDR = "vsphere-service-load-balancer-cidr"
flagVSphereNetworkName = "vsphere-network-name"
flagVSphereControlPlaneDiskGiB = "vsphere-control-plane-disk-gib"
flagVSphereControlPlaneIpPool = "vsphere-control-plane-ip-pool"
flagVSphereControlPlaneMemoryMiB = "vsphere-control-plane-memory-mib"
flagVSphereControlPlaneNumCPUs = "vsphere-control-plane-num-cpus"
flagVSphereControlPlaneReplicas = "vsphere-control-plane-replicas"
flagVSphereWorkerDiskGiB = "vsphere-worker-disk-gib"
flagVSphereWorkerMemoryMiB = "vsphere-worker-memory-mib"
flagVSphereWorkerNumCPUs = "vsphere-worker-num-cpus"
flagVSphereWorkerReplicas = "vsphere-worker-replicas"
flagVSphereResourcePool = "vsphere-resource-pool"
flagVSphereImageTemplate = "vsphere-image-template"
flagVSphereCredentialsSecretName = "vsphere-credentials-secret-name" // #nosec G101

// Common.
flagRegion = "region"
flagBastionInstanceType = "bastion-instance-type"
Expand All @@ -110,6 +127,10 @@ const (
flagRelease = "release"
flagLabel = "label"
flagServicePriority = "service-priority"

// defaults
defaultKubernetesVersion = "v1.20.9"
defaultVSphereKubernetesVersion = "v1.24.11"
)

type flag struct {
Expand Down Expand Up @@ -137,6 +158,7 @@ type flag struct {
Azure provider.AzureConfig
GCP provider.GCPConfig
OpenStack provider.OpenStackConfig
VSphere provider.VSphereConfig
App provider.AppConfig
OIDC provider.OIDC

Expand Down Expand Up @@ -216,6 +238,23 @@ func (f *flag) Init(cmd *cobra.Command) {
cmd.Flags().StringVar(&f.OpenStack.Worker.Flavor, flagOpenStackWorkerMachineFlavor, "", "Default worker node pool machine flavor (OpenStack only).")
cmd.Flags().IntVar(&f.OpenStack.WorkerReplicas, flagOpenStackWorkerReplicas, 0, "Default worker node pool replicas (OpenStack only).")

// VSphere only
cmd.Flags().StringVar(&f.VSphere.ControlPlane.IP, flagVSphereControlPlaneIP, "", "Control plane IP, leave empty for auto allocation.")
cmd.Flags().StringVar(&f.VSphere.ServiceLoadBalancerCIDR, flagVSphereServiceLoadBalancerCIDR, "", "CIDR for Service LB for new cluster")
cmd.Flags().StringVar(&f.VSphere.NetworkName, flagVSphereNetworkName, "grasshopper-capv", "Network name in vcenter that should be used for the new VMs")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't pick it up but we should probably remove grasshopper-capv as a default value 🙂

cmd.Flags().StringVar(&f.VSphere.ControlPlane.IPPoolName, flagVSphereControlPlaneIpPool, "wc-cp-ips", "Name of `GlobalInClusterIpPool` CR from which the IP for CP is taken")
cmd.Flags().IntVar(&f.VSphere.ControlPlane.DiskGiB, flagVSphereControlPlaneDiskGiB, 50, "Disk size in GiB for control individual plane nodes")
cmd.Flags().IntVar(&f.VSphere.ControlPlane.MemoryMiB, flagVSphereControlPlaneMemoryMiB, 8096, "Memory size in MiB for individual control plane nodes")
cmd.Flags().IntVar(&f.VSphere.ControlPlane.NumCPUs, flagVSphereControlPlaneNumCPUs, 4, "Number of CPUs for individual control plane nodes")
cmd.Flags().IntVar(&f.VSphere.ControlPlane.Replicas, flagVSphereControlPlaneReplicas, 3, "Number of control plane replicas (use odd number)")
cmd.Flags().IntVar(&f.VSphere.Worker.DiskGiB, flagVSphereWorkerDiskGiB, 50, "Disk size in GiB for control individual worker nodes")
cmd.Flags().IntVar(&f.VSphere.Worker.MemoryMiB, flagVSphereWorkerMemoryMiB, 14144, "Memory size in MiB for individual worker plane nodes")
cmd.Flags().IntVar(&f.VSphere.Worker.NumCPUs, flagVSphereWorkerNumCPUs, 6, "Number of CPUs for individual worker plane nodes")
cmd.Flags().IntVar(&f.VSphere.Worker.Replicas, flagVSphereWorkerReplicas, 3, "Number of worker plane replicas")
cmd.Flags().StringVar(&f.VSphere.ResourcePool, flagVSphereResourcePool, "grasshopper", "What resource pool in vsphere should be used")
cmd.Flags().StringVar(&f.VSphere.ImageTemplate, flagVSphereImageTemplate, "ubuntu-2004-kube-%s", "OS images with Kubernetes that should be used for VMs. The '%s' will be replaced with correct Kubernetes version.")
cmd.Flags().StringVar(&f.VSphere.CredentialsSecretName, flagVSphereCredentialsSecretName, "vsphere-credentials", "Name of the secret in K8s that should be associated to cluster app. It should exist in the organization's namesapce and should contain the credentials for vsphere.")

// App-based clusters only.
cmd.Flags().StringVar(&f.App.ClusterCatalog, flagClusterCatalog, "cluster", "Catalog for cluster app.")
cmd.Flags().StringVar(&f.App.ClusterVersion, flagClusterVersion, "", "Version of cluster to be created.")
Expand Down Expand Up @@ -283,7 +322,7 @@ func (f *flag) Init(cmd *cobra.Command) {
cmd.Flags().StringSliceVar(&f.ControlPlaneAZ, flagControlPlaneAZ, nil, "Availability zone(s) to use by control plane nodes. Azure only supports one.")
cmd.Flags().StringVar(&f.ControlPlaneInstanceType, flagControlPlaneInstanceType, "", "Instance type used for Control plane nodes")
cmd.Flags().StringVar(&f.Description, flagDescription, "", "User-friendly description of the cluster's purpose (formerly called name).")
cmd.Flags().StringVar(&f.KubernetesVersion, flagKubernetesVersion, "v1.20.9", "Cluster Kubernetes version.")
cmd.Flags().StringVar(&f.KubernetesVersion, flagKubernetesVersion, defaultKubernetesVersion, "Cluster Kubernetes version.")
cmd.Flags().StringVar(&f.Name, flagName, "", "Unique identifier of the cluster (formerly called ID).")
cmd.Flags().StringVar(&f.OIDC.IssuerURL, flagOIDCIssuerURL, "", "OIDC issuer URL.")
cmd.Flags().StringVar(&f.OIDC.CAFile, flagOIDCCAFile, "", "Path to CA file used to verify OIDC issuer (optional, OpenStack only).")
Expand Down Expand Up @@ -312,7 +351,7 @@ func (f *flag) Init(cmd *cobra.Command) {
f.print.AddFlags(cmd)
}

func (f *flag) Validate() error {
func (f *flag) Validate(cmd *cobra.Command) error {
var err error
validProviders := []string{
key.ProviderAWS,
Expand Down Expand Up @@ -388,6 +427,23 @@ func (f *flag) Validate() error {
if len(f.ControlPlaneAZ) > 1 {
return microerror.Maskf(invalidFlagError, "--%s supports one availability zone only", flagControlPlaneAZ)
}
case key.ProviderVSphere:
if f.VSphere.ServiceLoadBalancerCIDR == "" {
return microerror.Maskf(invalidFlagError, "CIDR range from which the public IPs for Services of type LoadBalancer are taken (required) (--%s)", flagVSphereServiceLoadBalancerCIDR)
}
if !validateCIDR(f.VSphere.ServiceLoadBalancerCIDR) {
return microerror.Maskf(invalidFlagError, "--%s must be a valid CIDR", flagVSphereServiceLoadBalancerCIDR)
}
ver, err := cmd.Flags().GetString(flagKubernetesVersion)
if err != nil || ver == "" {
f.KubernetesVersion = defaultVSphereKubernetesVersion
}
if f.VSphere.Worker.Replicas < 1 {
return microerror.Maskf(invalidFlagError, "--%s must be greater than 0", flagVSphereWorkerReplicas)
}
if f.VSphere.ControlPlane.Replicas < 1 {
return microerror.Maskf(invalidFlagError, "--%s must be greater than 0", flagVSphereControlPlaneReplicas)
}
case key.ProviderOpenStack:
if f.OpenStack.Cloud == "" {
return microerror.Maskf(invalidFlagError, "--%s is required", flagOpenStackCloud)
Expand Down
Loading