From c7fafbd7e564803a07d6e6e940846b99c86bafd5 Mon Sep 17 00:00:00 2001 From: Brad Ison Date: Fri, 24 Aug 2018 16:36:25 -0400 Subject: [PATCH] Update configuration to work with new actuator This updates the configuration to allow working with an up-to-date AWS actuator image. This is only a starting point. It does not cover the complete set of options available in the provider config types. --- README.md | 2 +- examples/machine-api-operator-config.yaml | 12 ++ machines/cluster.yaml | 27 +-- machines/machine-set.yaml | 59 +++--- manifests/clusterapi-controller.yaml | 4 +- pkg/render/config.go | 26 ++- pkg/render/machine-api-operator-config.yaml | 6 - pkg/render/render_test.go | 190 +++++++++++--------- 8 files changed, 179 insertions(+), 147 deletions(-) create mode 100644 examples/machine-api-operator-config.yaml delete mode 100644 pkg/render/machine-api-operator-config.yaml diff --git a/README.md b/README.md index bbd19ba4e..e10ff68e6 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ In order to deploy the machine-api-operator from scratch, one needs to: ``` and run the `machine-api-operator` binary: ```sh - ./bin/machine-api-operator --kubeconfig ${HOME}/.kube/config --config pkg/render/machine-api-operator-config.yaml --manifest-dir manifests + ./bin/machine-api-operator --kubeconfig ${HOME}/.kube/config --config examples/machine-api-operator-config.yaml --manifest-dir manifests ``` # CI & tests diff --git a/examples/machine-api-operator-config.yaml b/examples/machine-api-operator-config.yaml new file mode 100644 index 000000000..0a5346c20 --- /dev/null +++ b/examples/machine-api-operator-config.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: machineAPIOperatorConfig +clusterConfig: + vpcName: "test" + keyPairName: "test" + region: "us-east-1" +machineConfig: + ami: "ami-00cc4337762ba4a52" + availabilityZone: "us-east-1a" + iamInstanceProfile: "test" + subnet: "subnet-864ff9ce" + securityGroups: ["sg-105fda6e"] diff --git a/machines/cluster.yaml b/machines/cluster.yaml index 3044bc1ef..1a5f671ce 100644 --- a/machines/cluster.yaml +++ b/machines/cluster.yaml @@ -1,4 +1,5 @@ -apiVersion: "cluster.k8s.io/v1alpha1" +--- +apiVersion: cluster.k8s.io/v1alpha1 kind: Cluster metadata: name: test @@ -16,24 +17,6 @@ spec: value: apiVersion: awsproviderconfig/v1alpha1 kind: AWSClusterProviderConfig - clusterId: {{.VpcName}} - clusterVersionRef: - namespace: test - name: test - hardware: - aws: - region: {{.Region}} - keyPairName: {{.SshKey}} - defaultHardwareSpec: - aws: - instanceType: m4.large - machineSets: - - nodeType: Master - size: 1 - - shortName: infra - nodeType: Compute - infra: true - size: 1 - - shortName: compute - nodeType: Compute - size: 1 + region: "{{ .ClusterConfig.Region }}" + keyPairName: "{{ .ClusterConfig.KeyPairName }}" + vpcName: "{{ .ClusterConfig.VPCName }}" diff --git a/machines/machine-set.yaml b/machines/machine-set.yaml index 7ed7359ca..196a23227 100644 --- a/machines/machine-set.yaml +++ b/machines/machine-set.yaml @@ -1,40 +1,55 @@ +--- apiVersion: cluster.k8s.io/v1alpha1 kind: MachineSet metadata: name: worker namespace: test labels: - machineapioperator.openshift.io/cluster: test + sigs.k8s.io/cluster-api-cluster: test + sigs.k8s.io/cluster-api-machine-role: worker + sigs.k8s.io/cluster-api-machine-type: worker spec: replicas: 3 selector: matchLabels: - machineapioperator.openshift.io/machineset: worker - machineapioperator.openshift.io/cluster: test + sigs.k8s.io/cluster-api-machineset: worker + sigs.k8s.io/cluster-api-cluster: test template: metadata: labels: - machineapioperator.openshift.io/machineset: worker - machineapioperator.openshift.io/cluster: test + sigs.k8s.io/cluster-api-machineset: worker + sigs.k8s.io/cluster-api-cluster: test + sigs.k8s.io/cluster-api-machine-role: worker + sigs.k8s.io/cluster-api-machine-type: worker spec: providerConfig: value: apiVersion: awsproviderconfig/v1alpha1 kind: AWSMachineProviderConfig - clusterId: {{.VpcName}} - clusterHardware: - aws: - keyPairName: {{.SshKey}} - region: {{.Region}} - hardware: - aws: - instanceType: m4.large - infra: false - vmImage: - awsImage: {{.Image}} - versions: - kubelet: 0.0.0 - controlPlane: 0.0.0 - roles: - - Master - + ami: + id: "{{ .MachineConfig.AMI }}" + {{- if .AWSCredentialsSecret }} + credentialsSecret: + name: "{{ .AWSCredentialsSecret }}" + {{- end }} + instanceType: m4.xlarge + placement: + region: "{{ .ClusterConfig.Region }}" + availabilityZone: "{{ .MachineConfig.AvailabilityZone }}" + subnet: + id: "{{ .MachineConfig.Subnet }}" + iamInstanceProfile: + id: "{{ .MachineConfig.IAMInstanceProfile }}" + keyName: "{{ .ClusterConfig.KeyPairName }}" + tags: + - name: openshift-node-group-config + value: node-config-worker + - name: host-type + value: worker + - name: sub-host-type + value: default + securityGroups: + {{- range .MachineConfig.SecurityGroups }} + - id: "{{ . }}" + {{- end }} + publicIP: true diff --git a/manifests/clusterapi-controller.yaml b/manifests/clusterapi-controller.yaml index a804120d4..3f099b7c2 100644 --- a/manifests/clusterapi-controller.yaml +++ b/manifests/clusterapi-controller.yaml @@ -45,14 +45,14 @@ spec: cpu: 100m memory: 30Mi - name: aws-machine-controller - image: quay.io/alberto_lamela/aws-machine-controller:mvp # TODO: move this to openshift org + image: quay.io/bison/aws-machine-controller:cfc14e5 # TODO: move this to openshift org env: - name: NODE_NAME valueFrom: fieldRef: fieldPath: spec.nodeName command: - - /opt/services/aws-machine-controller + - /machine-controller args: - --log-level=debug resources: diff --git a/pkg/render/config.go b/pkg/render/config.go index 78ecd2a88..7df161bcf 100644 --- a/pkg/render/config.go +++ b/pkg/render/config.go @@ -5,6 +5,7 @@ import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" const ( // Kind is the TypeMeta.Kind for the OperatorConfig. Kind = "MachineAPIOperatorConfig" + // APIVersion is the TypeMeta.APIVersion for the OperatorConfig. APIVersion = "v1" ) @@ -12,10 +13,23 @@ 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"` + + AWSCredentialsSecret string `json:"awsCredentialsSecret"` + + ClusterConfig ClusterConfig `json:"clusterConfig"` + MachineConfig MachineConfig `json:"machineConfig"` +} + +type ClusterConfig struct { + KeyPairName string `json:"keyPairName"` + Region string `json:"region"` + VPCName string `json:"vpcName,omitempty"` +} + +type MachineConfig struct { + AMI string `json:"ami"` + AvailabilityZone string `json:"availabilityZone"` + Subnet string `json:"subnet"` + IAMInstanceProfile string `json:"iamInstanceProfile"` + SecurityGroups []string `json:"securityGroups"` } diff --git a/pkg/render/machine-api-operator-config.yaml b/pkg/render/machine-api-operator-config.yaml deleted file mode 100644 index 783cb8f17..000000000 --- a/pkg/render/machine-api-operator-config.yaml +++ /dev/null @@ -1,6 +0,0 @@ -apiVersion: v1 -kind: machineAPIOperatorConfig -vpcName: "test" -sshKey: "test" -clusterName: "test" -clusterDomain: "test" diff --git a/pkg/render/render_test.go b/pkg/render/render_test.go index 58d5de782..2c6e2d836 100644 --- a/pkg/render/render_test.go +++ b/pkg/render/render_test.go @@ -2,49 +2,36 @@ package render import ( "io/ioutil" + "path" "path/filepath" "strings" "testing" ) -func testRenderManifest(t *testing.T, filename string, config *OperatorConfig, expectedConfig string) { - t.Helper() +var testConfig = OperatorConfig{ + AWSCredentialsSecret: "TestClusterManifest-AWSCredentialsSecret", - manifest, err := filepath.Abs(filename) - if err != nil { - t.Fatalf("Failed to obtain absolute path of manifest %q: %v", filename, err) - } + ClusterConfig: ClusterConfig{ + KeyPairName: "TestClusterManifest-KeyPairName", + Region: "TestClusterManifest-Region", + VPCName: "TestClusterManifest-VPCName", + }, - data, err := ioutil.ReadFile(manifest) - if err != nil { - t.Fatalf("Failed to ingest manifest %q: %v", manifest, err) - } - - actual, err := Manifests(config, data) - if err != nil { - t.Fatalf("Failed to render manifest template: %v", err) - } - - a := strings.TrimSpace(expectedConfig) - b := strings.TrimSpace(string(actual)) - - if a != b { - t.Errorf("Expected:\n%v\nGot:\n%v", a, b) - } + MachineConfig: MachineConfig{ + AMI: "TestClusterManifest-AMI", + AvailabilityZone: "TestClusterManifest-AvailabilityZone", + Subnet: "TestClusterManifest-Subnet", + IAMInstanceProfile: "TestClusterManifest-IAMInstanceProfile", + SecurityGroups: []string{ + "TestClusterManifest-SecurityGroup-0", + "TestClusterManifest-SecurityGroup-1", + }, + }, } -func TestClusterManifest(t *testing.T) { - config := OperatorConfig{ - VpcName: "TestClusterManifest-VpcName", - SshKey: "TestClusterManifest-SshKey", - ClusterName: "TestClusterManifest-ClusterName", - ClusterDomain: "TestClusterManifest.ClusterDomain", // TODO(frobware) - currently not a template value - Region: "TestClusterManifest-Region", - Image: "TestClusterManifest-Image", - } - - testRenderManifest(t, "../../machines/cluster.yaml", &config, ` -apiVersion: "cluster.k8s.io/v1alpha1" +const expectedClusterYAML = ` +--- +apiVersion: cluster.k8s.io/v1alpha1 kind: Cluster metadata: name: test @@ -62,77 +49,104 @@ spec: value: apiVersion: awsproviderconfig/v1alpha1 kind: AWSClusterProviderConfig - clusterId: TestClusterManifest-VpcName - clusterVersionRef: - namespace: test - name: test - hardware: - aws: - region: TestClusterManifest-Region - keyPairName: TestClusterManifest-SshKey - defaultHardwareSpec: - aws: - instanceType: m4.large - machineSets: - - nodeType: Master - size: 1 - - shortName: infra - nodeType: Compute - infra: true - size: 1 - - shortName: compute - nodeType: Compute - size: 1`) -} + region: "TestClusterManifest-Region" + keyPairName: "TestClusterManifest-KeyPairName" + vpcName: "TestClusterManifest-VPCName" +` -func TestMachineSetManifest(t *testing.T) { - config := OperatorConfig{ - VpcName: "TestMachineSetManifest-VpcName", - SshKey: "TestMachineSetManifest-SshKey", - ClusterName: "TestMachineSetManifest-ClusterName", - ClusterDomain: "TestMachineSetManifest.ClusterDomain", // TODO(frobware) - currently not a template value - Region: "TestMachineSetManifest-Region", - Image: "TestMachineSetManifest-Image", - } - - testRenderManifest(t, "../../machines/machine-set.yaml", &config, ` +const expectedMachineSetYAML = ` +--- apiVersion: cluster.k8s.io/v1alpha1 kind: MachineSet metadata: name: worker namespace: test labels: - machineapioperator.openshift.io/cluster: test + sigs.k8s.io/cluster-api-cluster: test + sigs.k8s.io/cluster-api-machine-role: worker + sigs.k8s.io/cluster-api-machine-type: worker spec: replicas: 3 selector: matchLabels: - machineapioperator.openshift.io/machineset: worker - machineapioperator.openshift.io/cluster: test + sigs.k8s.io/cluster-api-machineset: worker + sigs.k8s.io/cluster-api-cluster: test template: metadata: labels: - machineapioperator.openshift.io/machineset: worker - machineapioperator.openshift.io/cluster: test + sigs.k8s.io/cluster-api-machineset: worker + sigs.k8s.io/cluster-api-cluster: test + sigs.k8s.io/cluster-api-machine-role: worker + sigs.k8s.io/cluster-api-machine-type: worker spec: providerConfig: value: apiVersion: awsproviderconfig/v1alpha1 kind: AWSMachineProviderConfig - clusterId: TestMachineSetManifest-VpcName - clusterHardware: - aws: - keyPairName: TestMachineSetManifest-SshKey - region: TestMachineSetManifest-Region - hardware: - aws: - instanceType: m4.large - infra: false - vmImage: - awsImage: TestMachineSetManifest-Image - versions: - kubelet: 0.0.0 - controlPlane: 0.0.0 - roles: - - Master`) + ami: + id: "TestClusterManifest-AMI" + credentialsSecret: + name: "TestClusterManifest-AWSCredentialsSecret" + instanceType: m4.xlarge + placement: + region: "TestClusterManifest-Region" + availabilityZone: "TestClusterManifest-AvailabilityZone" + subnet: + id: "TestClusterManifest-Subnet" + iamInstanceProfile: + id: "TestClusterManifest-IAMInstanceProfile" + keyName: "TestClusterManifest-KeyPairName" + tags: + - name: openshift-node-group-config + value: node-config-worker + - name: host-type + value: worker + - name: sub-host-type + value: default + securityGroups: + - id: "TestClusterManifest-SecurityGroup-0" + - id: "TestClusterManifest-SecurityGroup-1" + publicIP: true +` + +var renderTests = []struct { + in string + out string +}{ + {"../../machines/cluster.yaml", expectedClusterYAML}, + {"../../machines/machine-set.yaml", expectedMachineSetYAML}, +} + +func testRenderManifest(t *testing.T, filename string, config *OperatorConfig, expectedConfig string) { + t.Helper() + + manifest, err := filepath.Abs(filename) + if err != nil { + t.Fatalf("Failed to obtain absolute path of manifest %q: %v", filename, err) + } + + data, err := ioutil.ReadFile(manifest) + if err != nil { + t.Fatalf("Failed to ingest manifest %q: %v", manifest, err) + } + + actual, err := Manifests(config, data) + if err != nil { + t.Fatalf("Failed to render manifest template: %v", err) + } + + a := strings.TrimSpace(expectedConfig) + b := strings.TrimSpace(string(actual)) + + if a != b { + t.Errorf("Expected:\n%v\nGot:\n%v", a, b) + } +} + +func TestRendering(t *testing.T) { + for _, tt := range renderTests { + t.Run(path.Base(tt.in), func(t *testing.T) { + testRenderManifest(t, tt.in, &testConfig, tt.out) + }) + } }