Skip to content
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
22 changes: 17 additions & 5 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"flag"
"fmt"
"io/ioutil"
"time"

Expand Down Expand Up @@ -35,6 +36,11 @@ func init() {
flag.Parse()
}

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

func main() {

// Hack to deploy cluster and machineSet objects
Expand Down Expand Up @@ -84,7 +90,6 @@ func deployMachineSet() {
if err != nil {
glog.Fatalf("Error building kube config %#v", err)
}

client, err := clientset.NewForConfig(config)
clusterApiScheme.AddToScheme(scheme.Scheme)
decode := scheme.Codecs.UniversalDeserializer().Decode
Expand All @@ -95,8 +100,15 @@ func deployMachineSet() {
glog.Fatalf("Error reading machine-api-operator config: %v", err)
}

var machinesFolder string
if operatorConfig.Provider == providerAWS {
machinesFolder = "machines/aws"
} else if operatorConfig.Provider == providerLibvirt {
machinesFolder = "machines/libvirt"
}

// Create Cluster object
clusterTemplateData, err := ioutil.ReadFile("machines/cluster.yaml") // just pass the file name
clusterTemplateData, err := ioutil.ReadFile(fmt.Sprintf("%s/cluster.yaml", machinesFolder)) // just pass the file name
if err != nil {
glog.Fatalf("Error reading %#v", err)
}
Expand All @@ -113,7 +125,7 @@ func deployMachineSet() {
cluster := clusterObj.(*clusterv1.Cluster)

// Create MachineSet object
machineSetTemplateData, err := ioutil.ReadFile("machines/machine-set.yaml") // just pass the file name
machineSetTemplateData, err := ioutil.ReadFile(fmt.Sprintf("%s/machine-set.yaml", machinesFolder)) // just pass the file name
if err != nil {
glog.Fatalf("Error reading %#v", err)
}
Expand All @@ -131,14 +143,14 @@ func deployMachineSet() {

for {
glog.Info("Trying to deploy Cluster object")
if _, err := v1alphaClient.Clusters("test").Create(cluster); err != nil {
if _, err := v1alphaClient.Clusters("default").Create(cluster); err != nil {
glog.Infof("Cannot create cluster, retrying in 5 secs: %v", err)
} else {
glog.Info("Created Cluster object")
}

glog.Info("Trying to deploy MachineSet object")
_, err = v1alphaClient.MachineSets("test").Create(machineSet)
_, err = v1alphaClient.MachineSets("default").Create(machineSet)
if err != nil {
glog.Infof("Cannot create MachineSet, retrying in 5 secs: %v", err)
} else {
Expand Down
10 changes: 10 additions & 0 deletions examples/machine-api-operator-config-aws.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: v1
kind: machineAPIOperatorConfig
provider: aws
aws:
clusterName: meh
clusterID: b302cf66-f5ff-4d5d-1cc1-0ab2755d2065
image: ami-0e502f54daeb8686e
region: eu-west-1
availabilityZone: eu-west-1a
replicas: 1
5 changes: 5 additions & 0 deletions examples/machine-api-operator-config-libvirt.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: v1
kind: machineAPIOperatorConfig
provider: libvirt
libvirt:
uri: qemu+tcp://host_private_ip/system
15 changes: 15 additions & 0 deletions machines/aws/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: {{.AWS.ClusterName}}
namespace: default
spec:
clusterNetwork:
services:
cidrBlocks:
- "10.0.0.1/24"
pods:
cidrBlocks:
- "10.0.0.2/24"
serviceDomain: unused
56 changes: 56 additions & 0 deletions machines/aws/machine-set.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
apiVersion: cluster.k8s.io/v1alpha1
kind: MachineSet
metadata:
name: worker
namespace: default
labels:
sigs.k8s.io/cluster-api-cluster: {{.AWS.ClusterName}}
sigs.k8s.io/cluster-api-machine-role: worker
sigs.k8s.io/cluster-api-machine-type: worker
spec:
replicas: {{.AWS.Replicas}}
selector:
matchLabels:
sigs.k8s.io/cluster-api-machineset: worker
sigs.k8s.io/cluster-api-cluster: {{.AWS.ClusterName}}
template:
metadata:
labels:
sigs.k8s.io/cluster-api-machineset: worker
sigs.k8s.io/cluster-api-cluster: {{.AWS.ClusterName}}
sigs.k8s.io/cluster-api-machine-role: worker
sigs.k8s.io/cluster-api-machine-type: worker
spec:
providerConfig:
value:
apiVersion: aws.cluster.k8s.io/v1alpha1
kind: AWSMachineProviderConfig
ami:
id: {{.AWS.Image}}
instanceType: m4.large
placement:
region: {{.AWS.Region}}
availabilityZone: {{.AWS.AvailabilityZone}}
subnet:
filters:
- name: "tag:Name"
values:
- {{.AWS.ClusterName}}-worker-{{.AWS.AvailabilityZone}}
publicIp: true
iamInstanceProfile:
id: {{.AWS.ClusterName}}-master-profile
keyName: tectonic
tags:
- name: tectonicClusterID
value: {{.AWS.ClusterID}}
securityGroups:
- filters:
- name: "tag:Name"
values:
- {{.AWS.ClusterName}}_worker_sg
userDataSecret:
name: ignition-worker
versions:
kubelet: ""
controlPlane: ""
39 changes: 0 additions & 39 deletions machines/cluster.yaml

This file was deleted.

15 changes: 15 additions & 0 deletions machines/libvirt/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: {{.Libvirt.ClusterName}}
namespace: default
spec:
clusterNetwork:
services:
cidrBlocks:
- "10.0.0.1/24"
pods:
cidrBlocks:
- "10.0.0.2/24"
serviceDomain: unused
43 changes: 43 additions & 0 deletions machines/libvirt/machine-set.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
apiVersion: cluster.k8s.io/v1alpha1
kind: MachineSet
metadata:
name: worker
namespace: default
labels:
sigs.k8s.io/cluster-api-cluster: {{.Libvirt.ClusterName}}
sigs.k8s.io/cluster-api-machine-role: worker
sigs.k8s.io/cluster-api-machine-type: worker
spec:
replicas: {{.Libvirt.Replicas}}
selector:
matchLabels:
sigs.k8s.io/cluster-api-machineset: worker
sigs.k8s.io/cluster-api-cluster: {{.Libvirt.ClusterName}}
sigs.k8s.io/cluster-api-machine-role: worker
sigs.k8s.io/cluster-api-machine-type: worker
template:
metadata:
labels:
sigs.k8s.io/cluster-api-machineset: worker
sigs.k8s.io/cluster-api-cluster: {{.Libvirt.ClusterName}}
sigs.k8s.io/cluster-api-machine-role: infra
sigs.k8s.io/cluster-api-machine-type: worker
spec:
providerConfig:
value:
apiVersion: libvirtproviderconfig/v1alpha1
kind: LibvirtMachineProviderConfig
domainMemory: 2048
domainVcpu: 2
ignKey: /var/lib/libvirt/images/worker.ign
volume:
poolName: default
baseVolumeID: /var/lib/libvirt/images/coreos_base
networkInterfaceName: tectonic
networkInterfaceAddress: 192.168.124.12
autostart: false
uri: {{.Libvirt.URI}}
versions:
kubelet: ""
controlPlane: ""
40 changes: 0 additions & 40 deletions machines/machine-set.yaml

This file was deleted.

14 changes: 11 additions & 3 deletions manifests/clusterapi-controller.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: clusterapi-controllers
namespace: default
namespace: kube-system
labels:
api: clusterapi
k8s-app: controller
tectonic-operators.coreos.com/managed-by: machine-api-operator
spec:
securityContext:
runAsNonRoot: true
runAsUser: 65534
selector:
matchLabels:
api: clusterapi
Expand Down Expand Up @@ -44,15 +47,20 @@ spec:
limits:
cpu: 100m
memory: 30Mi
{{- if .AWS }}
- name: aws-machine-controller
image: quay.io/alberto_lamela/aws-machine-controller:mvp # TODO: move this to openshift org
image: quay.io/alberto_lamela/aws-machine-controller:dev # TODO: move this to openshift org
{{- else if .Libvirt}}
- name: libvirt-machine-controller
image: quay.io/alberto_lamela/libvirt-machine-controller:0.0.1-dev # TODO: move this to openshift org
{{- end}}
env:
- name: NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
command:
- /opt/services/aws-machine-controller
- /machine-controller
args:
- --log-level=debug
resources:
Expand Down
24 changes: 18 additions & 6 deletions pkg/render/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,22 @@ const (
// OperatorConfig contains configuration for KAO managed add-ons
type OperatorConfig struct {
metav1.TypeMeta `json:",inline"`
VpcName string `json:"vpcName"`
SshKey string `json:"sshKey"`
ClusterName string `json:"clusterName"`
ClusterDomain string `json:"clusterDomain"`
Region string `json:"region"`
Image string `json:"image"`
Provider string `json:"provider"`
AWS *awsConfig `json:"aws"`
Libvirt *libvirtConfig `json:"libvirt"`
}

type libvirtConfig struct {
URI string `json:"uri"`
ClusterName string `json:"clusterName"`
Replicas string `json:"replicas"`
}

type awsConfig struct {
ClusterName string `json:"clusterName"`
ClusterID string `json:"clusterID"`
Region string `json:"region"`
AvailabilityZone string `json:"availabilityZone"`
Image string `json:"image"`
Replicas string `json:"replicas"`
}
6 changes: 0 additions & 6 deletions pkg/render/machine-api-operator-config.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion pkg/render/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package render
import (
"bytes"
"fmt"
"html/template"
"io/ioutil"
"os"
"path/filepath"
"text/template"

"github.com/ghodss/yaml"
"github.com/golang/glog"
Expand Down
Loading