Skip to content

Commit

Permalink
Add OpenStack as a supported platform
Browse files Browse the repository at this point in the history
  • Loading branch information
flaper87 committed Oct 10, 2018
1 parent 7c322f8 commit 9021207
Show file tree
Hide file tree
Showing 11 changed files with 206 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
An Operator for managing the cluster-api stack and the Openshift owned machineSets:
- Aggregated API server
- Controller manager
- Machine controller (AWS/Libvirt actuator)
- Machine controller (AWS/OpenStack/Libvirt actuator)

# Manual deployment (for Kubernetes cluster)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ metadata:
name: machine-api-operator-images
namespace: openshift-cluster-api
data:
images.json: '{"clusterAPIControllerAWS": "openshift/origin-aws-machine-controllers:v4.0.0", "clusterAPIControllerManagerAWS": "openshift/origin-aws-machine-controllers:v4.0.0" , "clusterAPIControllerManagerLibvirt": "gcr.io/k8s-cluster-api/controller-manager:0.0.7", "clusterAPIControllerLibvirt": "quay.io/coreos/cluster-api-provider-libvirt:cd386e4", "clusterAPIServer": "gcr.io/k8s-cluster-api/cluster-apiserver:0.0.6", "Etcd": "quay.io/coreos/etcd:latest"}'
images.json: '{"clusterAPIControllerAWS": "openshift/origin-aws-machine-controllers:v4.0.0", "clusterAPIControllerManagerAWS": "openshift/origin-aws-machine-controllers:v4.0.0", "clusterAPIControllerOpenStack": "openshift/origin-openstack-machine-controllers:v4.0.0", "clusterAPIControllerManagerOpenStack": "openshift/origin-openstack-machine-controllers:v4.0.0", "clusterAPIControllerManagerLibvirt": "gcr.io/k8s-cluster-api/controller-manager:0.0.7", "clusterAPIControllerLibvirt": "quay.io/coreos/cluster-api-provider-libvirt:cd386e4", "clusterAPIServer": "gcr.io/k8s-cluster-api/cluster-apiserver:0.0.6", "Etcd": "quay.io/coreos/etcd:latest"}'
6 changes: 5 additions & 1 deletion install/image-references
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ spec:
from:
kind: DockerImage
name: docker.io/openshift/origin-aws-machine-controllers:v4.0.0
- name: openstack-machine-controllers
from:
kind: DockerImage
name: docker.io/openshift/origin-openstack-machine-controllers:v4.0.0
- name: libvirt-machine-controllers
from:
kind: DockerImage
name: docker.io/openshift/origin-libvirt-machine-controllers:v4.0.0
name: docker.io/openshift/origin-libvirt-machine-controllers:v4.0.0
15 changes: 15 additions & 0 deletions machines/openstack/cluster.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
apiVersion: "cluster.k8s.io/v1alpha1"
kind: Cluster
metadata:
name: {{.OpenStack.ClusterName}}
namespace: {{ .TargetNamespace }}
spec:
clusterNetwork:
services:
cidrBlocks:
- "10.0.0.1/24"
pods:
cidrBlocks:
- "10.0.0.2/24"
serviceDomain: unused
45 changes: 45 additions & 0 deletions machines/openstack/worker.machineset.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
apiVersion: cluster.k8s.io/v1alpha1
kind: MachineSet
metadata:
name: worker
namespace: {{ .TargetNamespace }}
labels:
sigs.k8s.io/cluster-api-cluster: {{.OpenStack.ClusterName}}
sigs.k8s.io/cluster-api-machine-role: worker
sigs.k8s.io/cluster-api-machine-type: worker
set: worker
spec:
replicas: {{.OpenStack.Replicas}}
selector:
matchLabels:
sigs.k8s.io/cluster-api-machineset: worker
sigs.k8s.io/cluster-api-cluster: {{.OpenStack.ClusterName}}
template:
metadata:
labels:
sigs.k8s.io/cluster-api-machineset: worker
sigs.k8s.io/cluster-api-cluster: {{.OpenStack.ClusterName}}
sigs.k8s.io/cluster-api-machine-role: worker
sigs.k8s.io/cluster-api-machine-type: worker
spec:
providerConfig:
value:
apiVersion: openstack.cluster.k8s.io/v1alpha1
kind: OpenStackMachineProviderConfig
flavor: m4.large
image: {{.OpenStack.Image}}
availability_zone: {{.OpenStack.AvailabilityZone}}
{{- if .OpenStack.Networks}}
networks:
{{- range .OpenStack.Networks}}
- uuid: {{.UUID}}
{{- end}}
{{- end}}
floatingIP: {{.OpenStack.FloatingIP}}
{{- if .OpenStack.SecurityGroups}}
security_groups: {{.OpenStack.SecurityGroups}}
{{- end}}
versions:
kubelet: ""
controlPlane: ""
5 changes: 5 additions & 0 deletions owned-manifests/clusterapi-controller.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ spec:
- name: controller-manager
{{- if .AWS }}
image: {{ .Images.ClusterAPIControllerManagerAWS }}
{{- else if .OpenStack}}
image: {{ .Images.ClusterAPIControllerManagerOpenStack }}
{{- else if .Libvirt}}
image: {{ .Images.ClusterAPIControllerManagerLibvirt }}
{{- end}}
Expand All @@ -54,6 +56,9 @@ spec:
{{- if .AWS }}
- name: aws-machine-controller
image: {{ .Images.ClusterAPIControllerAWS }}
{{- else if .OpenStack }}
- name: openstack-machine-controller
image: {{ .Images.ClusterAPIControllerOpenStack }}
{{- else if .Libvirt}}
- name: libvirt-machine-controller
image: {{ .Images.ClusterAPIControllerLibvirt }}
Expand Down
1 change: 1 addition & 0 deletions pkg/operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const (
// 5ms, 10ms, 20ms, 40ms, 80ms, 160ms, 320ms, 640ms, 1.3s, 2.6s, 5.1s, 10.2s, 20.4s, 41s, 82s
maxRetries = 15
providerAWS = "aws"
providerOpenStack = "openstack"
providerLibvirt = "libvirt"
ownedManifestsDir = "owned-manifests"
)
Expand Down
8 changes: 8 additions & 0 deletions pkg/operator/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ func (optr *Operator) syncMachineSets(config render.OperatorConfig) error {
machineSets = []string{
"machines/aws/worker.machineset.yaml",
}
case providerOpenStack:
machineSets = []string{
"machines/openstack/worker.machineset.yaml",
}
case providerLibvirt:
machineSets = []string{
"machines/libvirt/worker.machineset.yaml",
Expand Down Expand Up @@ -116,6 +120,10 @@ func (optr *Operator) syncCluster(config render.OperatorConfig) error {
clusters = []string{
"machines/aws/cluster.yaml",
}
case providerOpenStack:
clusters = []string{
"machines/openstack/cluster.yaml",
}
case providerLibvirt:
clusters = []string{
"machines/libvirt/cluster.yaml",
Expand Down
49 changes: 37 additions & 12 deletions pkg/render/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ const (
// OperatorConfig contains configuration for MAO
type OperatorConfig struct {
metav1.TypeMeta `json:",inline"`
TargetNamespace string `json:"targetNamespace"`
APIServiceCA string `json:"apiServiceCA"`
Provider string `json:"provider"`
AWS *AWSConfig `json:"aws"`
Libvirt *LibvirtConfig `json:"libvirt"`
Images *Images `json:"images"`
TargetNamespace string `json:"targetNamespace"`
APIServiceCA string `json:"apiServiceCA"`
Provider string `json:"provider"`
AWS *AWSConfig `json:"aws"`
OpenStack *OpenStackConfig `json:"openstack"`
Libvirt *LibvirtConfig `json:"libvirt"`
Images *Images `json:"images"`
}

// LibvirtConfig contains specific config for Libvirt
Expand All @@ -29,6 +30,28 @@ type LibvirtConfig struct {
Replicas string `json:"replicas"`
}

// OpenStackConfig contains specific config for OpenStack
type OpenStackConfig struct {
ClusterName string `json:"clusterName"`
ClusterID string `json:"clusterID"`
AvailabilityZone string `json:"availabilityZone"`
Image string `json:"image"`
Replicas string `json:"replicas"`
FloatingIP string `json:"floatingIP,omitempty"`
Networks []OpenStackNetworkParam `json:"networks,omitempty"`
SecurityGroups []string `json:"securityGroups,omitempty"`
}

// We should switch to predictable names/filters as soon as
// it is available in the OpenStack actuator.
type OpenStackNetworkParam struct {
// The UUID of the network. Required if you omit the port attribute.
UUID string `json:"uuid,omitempty"`
// A fixed IPv4 address for the NIC.
FixedIp string `json:"fixed_ip,omitempty"`
}


// AWSConfig contains specific config for AWS
type AWSConfig struct {
ClusterName string `json:"clusterName"`
Expand All @@ -44,10 +67,12 @@ type AWSConfig struct {

// Images allows build systems to inject images for MAO components.
type Images struct {
ClusterAPIControllerAWS string `json:"clusterAPIControllerAWS"`
ClusterAPIControllerLibvirt string `json:"clusterAPIControllerLibvirt"`
ClusterAPIControllerManagerAWS string `json:"clusterAPIControllerManagerAWS"`
ClusterAPIControllerManagerLibvirt string `json:"clusterAPIControllerManagerLibvirt"`
ClusterAPIServer string `json:"clusterAPIServer"`
Etcd string `json:"Etcd"`
ClusterAPIControllerAWS string `json:"clusterAPIControllerAWS"`
ClusterAPIControllerOpenStack string `json:"clusterAPIControllerOpenStack"`
ClusterAPIControllerLibvirt string `json:"clusterAPIControllerLibvirt"`
ClusterAPIControllerManagerAWS string `json:"clusterAPIControllerManagerAWS"`
ClusterAPIControllerManagerOpenStack string `json:"clusterAPIControllerManagerOpenStack"`
ClusterAPIControllerManagerLibvirt string `json:"clusterAPIControllerManagerLibvirt"`
ClusterAPIServer string `json:"clusterAPIServer"`
Etcd string `json:"Etcd"`
}
5 changes: 3 additions & 2 deletions pkg/render/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import (
)

const (
providerAWS = "aws"
providerLibvirt = "libvirt"
providerAWS = "aws"
providerOpenStack = "openstack"
providerLibvirt = "libvirt"
)

// Manifests takes the config object that contains the templated value,
Expand Down
85 changes: 85 additions & 0 deletions pkg/render/render_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,91 @@ spec:
controlPlane: ""`)
}

func TestClusterOpenStackManifest(t *testing.T) {
config := OperatorConfig{
TargetNamespace: "go-test",
Provider: "OpenStack",
OpenStack: &OpenStackConfig{
ClusterName: "TestClusterManifest-ClusterName",
ClusterID: "TestClusterManifest-ClusterID",
AvailabilityZone: "TestClusterManifest-AvailabilityZone",
Image: "TestClusterManifest-Image",
Replicas: "TestClusterManifest-Replicas",
},
}

testRenderManifest(t, "../../machines/openstack/cluster.yaml", &config, `
---
apiVersion: "cluster.k8s.io/v1alpha1"
kind: Cluster
metadata:
name: TestClusterManifest-ClusterName
namespace: go-test
spec:
clusterNetwork:
services:
cidrBlocks:
- "10.0.0.1/24"
pods:
cidrBlocks:
- "10.0.0.2/24"
serviceDomain: unused
`)
}

func TestMachineSetOpenStackManifest(t *testing.T) {
config := OperatorConfig{
TargetNamespace: "go-test",
Provider: "openstack",
OpenStack: &OpenStackConfig{
ClusterName: "TestClusterManifest-ClusterName",
ClusterID: "TestClusterManifest-ClusterID",
AvailabilityZone: "TestClusterManifest-AvailabilityZone",
Image: "TestClusterManifest-Image",
Replicas: "TestClusterManifest-Replicas",
FloatingIP: "192.168.1.1",
},
}

testRenderManifest(t, "../../machines/openstack/worker.machineset.yaml", &config, `
---
apiVersion: cluster.k8s.io/v1alpha1
kind: MachineSet
metadata:
name: worker
namespace: go-test
labels:
sigs.k8s.io/cluster-api-cluster: TestClusterManifest-ClusterName
sigs.k8s.io/cluster-api-machine-role: worker
sigs.k8s.io/cluster-api-machine-type: worker
set: worker
spec:
replicas: TestClusterManifest-Replicas
selector:
matchLabels:
sigs.k8s.io/cluster-api-machineset: worker
sigs.k8s.io/cluster-api-cluster: TestClusterManifest-ClusterName
template:
metadata:
labels:
sigs.k8s.io/cluster-api-machineset: worker
sigs.k8s.io/cluster-api-cluster: TestClusterManifest-ClusterName
sigs.k8s.io/cluster-api-machine-role: worker
sigs.k8s.io/cluster-api-machine-type: worker
spec:
providerConfig:
value:
apiVersion: openstack.cluster.k8s.io/v1alpha1
kind: OpenStackMachineProviderConfig
flavor: m4.large
image: TestClusterManifest-Image
availability_zone: TestClusterManifest-AvailabilityZone
floatingIP: 192.168.1.1
versions:
kubelet: ""
controlPlane: ""`)
}

func TestMachineSetLibvirtManifest(t *testing.T) {
config := OperatorConfig{
TargetNamespace: "go-test",
Expand Down

0 comments on commit 9021207

Please sign in to comment.