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

Add OpenStack provider #540

Merged
merged 21 commits into from
Dec 6, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

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

## [Unreleased]

### Added

- Alpha support for vSphere and OpenStack providers.

### Changed

- Usa CAPI templates for all releases from `v20.0.0-alpha1` onwards, to include alpha and beta releases.
Expand Down
61 changes: 44 additions & 17 deletions cmd/get/capi/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ import (
const (
giantswarmNamespace = "giantswarm"

providerAll = "All"
providerAWS = "AWS"
providerAzure = "Azure"
providerVMware = "VMware"
providerAll = "All"
providerAWS = "AWS"
providerAzure = "Azure"
providerOpenStack = "OpenStack"
providerVSphere = "vSphere"
)

type runner struct {
Expand All @@ -47,6 +48,7 @@ type controller struct {

var (
crds = []crd{
// All
{
DisplayName: "Cluster",
Name: "clusters.cluster.x-k8s.io",
Expand Down Expand Up @@ -102,6 +104,7 @@ var (
Name: "kubeadmconfigtemplates.bootstrap.cluster.x-k8s.io",
Provider: providerAll,
},
// AWS
{
DisplayName: "AWS Cluster",
Name: "awsclusters.infrastructure.cluster.x-k8s.io",
Expand All @@ -122,6 +125,7 @@ var (
Name: "awsmachinetemplates.infrastructure.cluster.x-k8s.io",
Provider: providerAWS,
},
// Azure
{
DisplayName: "Azure Cluster",
Name: "azureclusters.infrastructure.cluster.x-k8s.io",
Expand All @@ -142,30 +146,47 @@ var (
Name: "azuremachinetemplates.infrastructure.cluster.x-k8s.io",
Provider: providerAzure,
},
// Open Stack
{
DisplayName: "VMware Cluster",
DisplayName: "OpenStack Cluster",
Name: "vsphereclusters.infrastructure.cluster.x-k8s.io",
ericgraf marked this conversation as resolved.
Show resolved Hide resolved
Provider: providerVMware,
Provider: providerOpenStack,
},
{
DisplayName: "VMware Machine",
DisplayName: "OpenStack Machine",
Name: "vspheremachines.infrastructure.cluster.x-k8s.io",
ericgraf marked this conversation as resolved.
Show resolved Hide resolved
Provider: providerVMware,
Provider: providerOpenStack,
},
{
DisplayName: "VMware Machine Template",
DisplayName: "OpenStack Machine Template",
Name: "vspheremachinetemplates.infrastructure.cluster.x-k8s.io",
ericgraf marked this conversation as resolved.
Show resolved Hide resolved
Provider: providerVMware,
Provider: providerOpenStack,
},
// vSphere
{
DisplayName: "VMware VM",
DisplayName: "vSphere Cluster",
Name: "vsphereclusters.infrastructure.cluster.x-k8s.io",
Provider: providerVSphere,
},
{
DisplayName: "vSphere Machine",
Name: "vspheremachines.infrastructure.cluster.x-k8s.io",
Provider: providerVSphere,
},
{
DisplayName: "vSphere Machine Template",
Name: "vspheremachinetemplates.infrastructure.cluster.x-k8s.io",
Provider: providerVSphere,
},
{
DisplayName: "vSphere VM",
Name: "vspherevms.infrastructure.cluster.x-k8s.io",
Provider: providerVMware,
Provider: providerVSphere,
},
{
DisplayName: "VMware HAProxy",
DisplayName: "vSphere HAProxy",
Name: "haproxyloadbalancers.infrastructure.cluster.x-k8s.io",
Provider: providerVMware,
Provider: providerVSphere,
},
}

Expand Down Expand Up @@ -201,10 +222,16 @@ var (
Provider: providerAzure,
},
{
DisplayName: "VMWare Provider",
LabelSelector: "app.kubernetes.io/name=cluster-api-provider-vmware",
DisplayName: "OpenStack Provider",
LabelSelector: "app.kubernetes.io/name=cluster-api-provider-openstack",
ContainerName: "manager",
Provider: providerOpenStack,
},
{
DisplayName: "vSphere Provider",
LabelSelector: "app.kubernetes.io/name=cluster-api-provider-vsphere",
ContainerName: "manager",
Provider: providerVMware,
Provider: providerVSphere,
},
}
)
Expand Down
1 change: 1 addition & 0 deletions cmd/template/cluster/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ func (f *flag) Validate() error {
validProviders := []string{
key.ProviderAWS,
key.ProviderAzure,
key.ProviderOpenStack,
key.ProviderVsphere,
}
isValidProvider := false
Expand Down
60 changes: 60 additions & 0 deletions cmd/template/cluster/provider/capo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package provider

import (
"bytes"
"context"
"io"
"os"
"path/filepath"

"github.com/giantswarm/k8sclient/v5/pkg/k8sclient"
"github.com/giantswarm/microerror"

"github.com/giantswarm/kubectl-gs/cmd/template/cluster/provider/templates/openstack"
"github.com/giantswarm/kubectl-gs/internal/key"
)

func WriteCAPOTemplate(ctx context.Context, client k8sclient.Interface, out io.Writer, config ClusterCRsConfig) error {
var err error

homeDir, err := os.UserHomeDir()
if err != nil {
return microerror.Mask(err)
}

idRsaPubBytes, err := os.ReadFile(filepath.Join(homeDir, ".ssh/id_rsa.pub"))
tfussell marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return microerror.Mask(err)
}
idRsaPubBytes = bytes.TrimSpace(idRsaPubBytes)

data := struct {
Description string
KubernetesVersion string
Name string
Namespace string
Organization string
ReleaseVersion string
SSHPublicKey string
}{
Description: config.Description,
KubernetesVersion: "v1.20.1",
Name: config.Name,
Namespace: key.OrganizationNamespaceFromName(config.Organization),
Organization: config.Organization,
ReleaseVersion: config.ReleaseVersion,
SSHPublicKey: string(idRsaPubBytes),
}

var templates []templateConfig
for _, t := range openstack.GetTemplates() {
templates = append(templates, templateConfig(t))
}

err = runMutation(ctx, client, data, templates, out)
if err != nil {
return microerror.Mask(err)
}

return nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
apiVersion: cluster.x-k8s.io/v1alpha4
ericgraf marked this conversation as resolved.
Show resolved Hide resolved
kind: Cluster
metadata:
annotations:
cluster.giantswarm.io/description: {{ .Description }}
labels:
release.giantswarm.io/version: {{ .ReleaseVersion }}
giantswarm.io/cluster: {{ .Name }}
cluster.x-k8s.io/cluster-name: {{ .Name }}
giantswarm.io/organization: {{ .Organization }}
name: {{ .Name }}
namespace: {{ .Namespace }}
spec:
clusterNetwork:
pods:
tfussell marked this conversation as resolved.
Show resolved Hide resolved
cidrBlocks:
- 192.168.0.0/16
tfussell marked this conversation as resolved.
Show resolved Hide resolved
controlPlaneEndpoint:
tfussell marked this conversation as resolved.
Show resolved Hide resolved
host: 10.0.6.191
port: 6443
controlPlaneRef:
apiVersion: controlplane.cluster.x-k8s.io/v1alpha4
kind: KubeadmControlPlane
name: {{ .Name }}
infrastructureRef:
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha4
kind: OpenStackCluster
name: {{ .Name }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
apiVersion: bootstrap.cluster.x-k8s.io/v1alpha4
kind: KubeadmConfigTemplate
metadata:
metadata:
labels:
cluster.x-k8s.io/cluster-name: {{ .Name }}
giantswarm.io/cluster: {{ .Name }}
giantswarm.io/organization: {{ .Organization }}
release.giantswarm.io/version: {{ .ReleaseVersion }}
name: {{ .Name }}-md-0
namespace: {{ .Namespace }}
spec:
template:
spec:
joinConfiguration:
nodeRegistration:
criSocket: /var/run/containerd/containerd.sock
kubeletExtraArgs:
cloud-provider: external
name: '{{ `{{ ds.meta_data.hostname }}` }}'
preKubeadmCommands:
- hostname "{{ `{{ ds.meta_data.hostname }}` }}"
- echo "::1 ipv6-localhost ipv6-loopback" >/etc/hosts
- echo "127.0.0.1 localhost" >>/etc/hosts
- echo "127.0.0.1 {{ `{{ ds.meta_data.hostname }}` }}" >>/etc/hosts
- echo "{{ `{{ ds.meta_data.hostname }}` }}" >/etc/hostname
users:
tfussell marked this conversation as resolved.
Show resolved Hide resolved
- name: capo
sshAuthorizedKeys:
- "{{ .SSHPublicKey }}"
sudo: ALL=(ALL) NOPASSWD:ALL
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
apiVersion: controlplane.cluster.x-k8s.io/v1alpha4
kind: KubeadmControlPlane
metadata:
labels:
"release.giantswarm.io/version": "{{ .ReleaseVersion }}"
"giantswarm.io/cluster": "{{ .Name }}"
"cluster.x-k8s.io/cluster-name": "{{ .Name }}"
"giantswarm.io/organization": "{{ .Organization }}"
name: {{ .Name }}
namespace: {{ .Namespace }}
spec:
kubeadmConfigSpec:
clusterConfiguration:
apiServer:
extraArgs:
cloud-provider: external
controllerManager:
extraArgs:
cloud-provider: external
initConfiguration:
nodeRegistration:
criSocket: /var/run/containerd/containerd.sock
kubeletExtraArgs:
cloud-provider: external
name: '{{ `{{ ds.meta_data.hostname }}` }}'
joinConfiguration:
nodeRegistration:
criSocket: /var/run/containerd/containerd.sock
kubeletExtraArgs:
cloud-provider: external
name: '{{ `{{ ds.meta_data.hostname }}` }}'
preKubeadmCommands:
- hostname "{{ `{{ ds.meta_data.hostname }}` }}"
tfussell marked this conversation as resolved.
Show resolved Hide resolved
- echo "::1 ipv6-localhost ipv6-loopback" >/etc/hosts
- echo "127.0.0.1 localhost" >>/etc/hosts
- echo "127.0.0.1 {{ `{{ ds.meta_data.hostname }}` }}" >>/etc/hosts
- echo "{{ `{{ ds.meta_data.hostname }}` }}" >/etc/hostname
tfussell marked this conversation as resolved.
Show resolved Hide resolved
useExperimentalRetryJoin: true
users:
tfussell marked this conversation as resolved.
Show resolved Hide resolved
- name: capo
sshAuthorizedKeys:
- "{{ .SSHPublicKey }}"
sudo: ALL=(ALL) NOPASSWD:ALL
machineTemplate:
infrastructureRef:
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha4
kind: OpenStackMachineTemplate
name: {{ .Name }}
replicas: 1
tfussell marked this conversation as resolved.
Show resolved Hide resolved
version: {{ .KubernetesVersion }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
apiVersion: cluster.x-k8s.io/v1alpha4
kind: MachineDeployment
tfussell marked this conversation as resolved.
Show resolved Hide resolved
metadata:
metadata:
labels:
cluster.x-k8s.io/cluster-name: {{ .Name }}
cluster.x-k8s.io/watch-filter: capi
tfussell marked this conversation as resolved.
Show resolved Hide resolved
giantswarm.io/cluster: {{ .Name }}
giantswarm.io/organization: {{ .Organization }}
release.giantswarm.io/version: {{ .ReleaseVersion }}
name: {{ .Name }}-md
namespace: {{ .Namespace }}
spec:
clusterName: {{ .Name }}
minReadySeconds: 0
progressDeadlineSeconds: 600
replicas: 3
tfussell marked this conversation as resolved.
Show resolved Hide resolved
revisionHistoryLimit: 1
selector:
matchLabels:
cluster.x-k8s.io/cluster-name: {{ .Name }}
cluster.x-k8s.io/deployment-name: {{ .Name }}-md-0
template:
metadata:
labels:
cluster.x-k8s.io/cluster-name: {{ .Name }}
cluster.x-k8s.io/deployment-name: {{ .Name }}-md-0
spec:
bootstrap:
configRef:
apiVersion: bootstrap.cluster.x-k8s.io/v1alpha4
kind: KubeadmConfigTemplate
name: {{ .Name }}-md-0
clusterName: {{ .Name }}
failureDomain: changeme
tfussell marked this conversation as resolved.
Show resolved Hide resolved
infrastructureRef:
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha4
kind: OpenStackMachineTemplate
name: {{ .Name }}
version: {{ .KubernetesVersion }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha4
kind: OpenStackCluster
metadata:
labels:
"release.giantswarm.io/version": "{{ .ReleaseVersion }}"
"giantswarm.io/cluster": "{{ .Name }}"
"cluster.x-k8s.io/cluster-name": "{{ .Name }}"
"giantswarm.io/organization": "{{ .Organization }}"
name: {{ .Name }}
namespace: {{ .Namespace }}
spec:
cloudName: changeme
tfussell marked this conversation as resolved.
Show resolved Hide resolved
identityRef:
name: changeme
tfussell marked this conversation as resolved.
Show resolved Hide resolved
kind: Secret
managedAPIServerLoadBalancer: true
managedSecurityGroups: true
nodeCidr: 10.6.0.0/24
tfussell marked this conversation as resolved.
Show resolved Hide resolved
dnsNameservers:
- changeme
externalNetworkId: changeme
tfussell marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha4
kind: OpenStackMachineTemplate
metadata:
labels:
"release.giantswarm.io/version": "{{ .ReleaseVersion }}"
"giantswarm.io/cluster": "{{ .Name }}"
"cluster.x-k8s.io/cluster-name": "{{ .Name }}"
"giantswarm.io/organization": "{{ .Organization }}"
name: {{ .Name }}
namespace: {{ .Namespace }}
spec:
template:
spec:
flavor: changeme
tfussell marked this conversation as resolved.
Show resolved Hide resolved
image: changeme
tfussell marked this conversation as resolved.
Show resolved Hide resolved
sshKeyName: changeme
tfussell marked this conversation as resolved.
Show resolved Hide resolved
cloudName: changeme
tfussell marked this conversation as resolved.
Show resolved Hide resolved
identityRef:
name: changeme
tfussell marked this conversation as resolved.
Show resolved Hide resolved
kind: Secret