Skip to content

Commit

Permalink
Replace ProviderConfig with ProviderSpec
Browse files Browse the repository at this point in the history
Make sure .providerConfig field of machine object is still available until
all consumers migrate to .providerSpec field.
The .providerSpec field is the default field now and .providerConfig is used only
when both .providerSpec.Value and .providerSpec.ValueFrom are nil.
  • Loading branch information
ingvagabund committed Jan 3, 2019
1 parent 1ea2e44 commit 5b512aa
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 41 deletions.
10 changes: 9 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,15 @@ build-e2e:
.PHONY: k8s-e2e
k8s-e2e: ## Run k8s specific e2e test
# KUBECONFIG and SSH_PK dirs needs to be mounted inside a container if tests are run in containers
go test -timeout 20m -v sigs.k8s.io/cluster-api-provider-aws/test/machines -kubeconfig $${KUBECONFIG:-~/.kube/config} -ssh-key $${SSH_PK:-~/.ssh/id_rsa} -actuator-image $${ACTUATOR_IMAGE:-gcr.io/k8s-cluster-api/aws-machine-controller:0.0.1} -cluster-id $${ENVIRONMENT_ID:-""} -ginkgo.v
go test -timeout 20m \
-v sigs.k8s.io/cluster-api-provider-aws/test/machines \
-kubeconfig $${KUBECONFIG:-~/.kube/config} \
-ssh-key $${SSH_PK:-~/.ssh/id_rsa} \
-machine-controller-image $${ACTUATOR_IMAGE:-gcr.io/k8s-cluster-api/aws-machine-controller:0.0.1} \
-machine-manager-image $${ACTUATOR_IMAGE:-gcr.io/k8s-cluster-api/aws-machine-controller:0.0.1} \
-nodelink-controller-image $$(docker run registry.svc.ci.openshift.org/openshift/origin-release:v4.0 image machine-api-operator) \
-cluster-id $${ENVIRONMENT_ID:-""} \
-ginkgo.v

.PHONY: test-e2e
validate-e2e: ## Run e2e validation/gating test
Expand Down
6 changes: 5 additions & 1 deletion cmd/aws-actuator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,10 @@ func bootstrapCommand() *cobra.Command {
glog.Info(msg)
}

clusterFramework.MachineControllerImage = "openshift/origin-aws-machine-controllers:v4.0.0"
clusterFramework.MachineManagerImage = "openshift/origin-aws-machine-controllers:v4.0.0"
clusterFramework.NodelinkControllerImage = "registry.svc.ci.openshift.org/openshift/origin-v4.0-2019-01-03-031244@sha256:152c0a4ea7cda1731e45af87e33909421dcde7a8fcf4e973cd098a8bae892c50"

glog.Info("Waiting for all nodes to come up")
err = clusterFramework.WaitForNodesToGetReady(1)
if err != nil {
Expand All @@ -366,7 +370,7 @@ func bootstrapCommand() *cobra.Command {
return err
}

clusterFramework.DeployClusterAPIStack(testNamespace.Name, "openshift/origin-aws-machine-controllers:v4.0.0", "")
clusterFramework.DeployClusterAPIStack(testNamespace.Name, "")
clusterFramework.CreateClusterAndWait(testCluster)
createSecretAndWait(clusterFramework, awsCredentialsSecret)

Expand Down
10 changes: 5 additions & 5 deletions pkg/apis/awsproviderconfig/v1alpha1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ func NewCodec() (*AWSProviderConfigCodec, error) {
}

// DecodeProviderConfig deserialises an object from the provider config
func (codec *AWSProviderConfigCodec) DecodeProviderConfig(providerConfig *clusterv1.ProviderConfig, out runtime.Object) error {
if providerConfig.Value != nil {
_, _, err := codec.decoder.Decode(providerConfig.Value.Raw, nil, out)
func (codec *AWSProviderConfigCodec) DecodeProviderConfig(providerSpec *clusterv1.ProviderSpec, out runtime.Object) error {
if providerSpec.Value != nil {
_, _, err := codec.decoder.Decode(providerSpec.Value.Raw, nil, out)
if err != nil {
return fmt.Errorf("decoding failure: %v", err)
}
Expand All @@ -85,12 +85,12 @@ func (codec *AWSProviderConfigCodec) DecodeProviderConfig(providerConfig *cluste
}

// EncodeProviderConfig serialises an object to the provider config
func (codec *AWSProviderConfigCodec) EncodeProviderConfig(in runtime.Object) (*clusterv1.ProviderConfig, error) {
func (codec *AWSProviderConfigCodec) EncodeProviderConfig(in runtime.Object) (*clusterv1.ProviderSpec, error) {
var buf bytes.Buffer
if err := codec.encoder.Encode(in, &buf); err != nil {
return nil, fmt.Errorf("encoding failed: %v", err)
}
return &clusterv1.ProviderConfig{
return &clusterv1.ProviderSpec{
Value: &runtime.RawExtension{Raw: buf.Bytes()},
}, nil
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/cloud/aws/actuators/machine/actuator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ func TestMachineEvents(t *testing.T) {
}

machineInvalidProviderConfig := machine.DeepCopy()
machineInvalidProviderConfig.Spec.ProviderConfig.Value = nil
machineInvalidProviderConfig.Spec.ProviderConfig.ValueFrom = nil
machineInvalidProviderConfig.Spec.ProviderSpec.Value = nil
machineInvalidProviderConfig.Spec.ProviderSpec.ValueFrom = nil

workerMachine := machine.DeepCopy()
workerMachine.Labels[providerconfigv1.MachineTypeLabel] = "worker"
Expand Down Expand Up @@ -228,8 +228,8 @@ func TestActuator(t *testing.T) {
}

machineInvalidProviderConfig := machine.DeepCopy()
machineInvalidProviderConfig.Spec.ProviderConfig.Value = nil
machineInvalidProviderConfig.Spec.ProviderConfig.ValueFrom = nil
machineInvalidProviderConfig.Spec.ProviderSpec.Value = nil
machineInvalidProviderConfig.Spec.ProviderSpec.ValueFrom = nil

machineNoClusterID := machine.DeepCopy()
delete(machineNoClusterID.Labels, providerconfigv1.ClusterIDLabel)
Expand Down Expand Up @@ -636,7 +636,7 @@ func TestAvailabiltyZone(t *testing.T) {
}

machinePc := &providerconfigv1.AWSMachineProviderConfig{}
if err = codec.DecodeProviderConfig(&machine.Spec.ProviderConfig, machinePc); err != nil {
if err = codec.DecodeProviderConfig(&machine.Spec.ProviderSpec, machinePc); err != nil {
t.Fatal(err)
}

Expand All @@ -654,7 +654,7 @@ func TestAvailabiltyZone(t *testing.T) {
if err != nil {
t.Fatal(err)
}
machine.Spec.ProviderConfig = *config
machine.Spec.ProviderSpec = *config

fakeKubeClient := kubernetesfake.NewSimpleClientset(awsCredentialsSecret, userDataSecret)

Expand Down
2 changes: 1 addition & 1 deletion pkg/cloud/aws/actuators/machine/stubs.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func stubMachine() (*clusterv1.Machine, *providerconfigv1.AWSMachineProviderConf
},

Spec: clusterv1.MachineSpec{
ProviderConfig: *config,
ProviderSpec: *config,
},
}

Expand Down
30 changes: 20 additions & 10 deletions pkg/cloud/aws/actuators/machine/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,32 +139,42 @@ func terminateInstances(client awsclient.Client, instances []*ec2.Instance) erro
// ProviderConfigFromMachine gets the machine provider config MachineSetSpec from the
// specified cluster-api MachineSpec.
func ProviderConfigFromMachine(client client.Client, machine *clusterv1.Machine, codec *providerconfigv1.AWSProviderConfigCodec) (*providerconfigv1.AWSMachineProviderConfig, error) {
var providerConfig runtime.RawExtension
var providerSpecRawExtention runtime.RawExtension

// TODO(jchaloup): Remove providerConfig once all consumers migrate to providerSpec
providerSpec := machine.Spec.ProviderConfig
// providerSpec has higher priority over providerConfig
if machine.Spec.ProviderSpec.Value != nil || machine.Spec.ProviderSpec.ValueFrom != nil {
providerSpec = machine.Spec.ProviderSpec
glog.Infof("Falling to default providerSpec\n")
} else {
glog.Infof("Falling to providerConfig\n")
}

if machine.Spec.ProviderConfig.Value == nil && machine.Spec.ProviderConfig.ValueFrom == nil {
if providerSpec.Value == nil && providerSpec.ValueFrom == nil {
return nil, fmt.Errorf("unable to find machine provider config: neither Spec.ProviderConfig.Value nor Spec.ProviderConfig.ValueFrom set")
}

// If no machine.Spec.ProviderConfig.Value then we lookup for machineClass
if machine.Spec.ProviderConfig.Value != nil {
providerConfig = *machine.Spec.ProviderConfig.Value
// If no providerSpec.Value then we lookup for machineClass
if providerSpec.Value != nil {
providerSpecRawExtention = *providerSpec.Value
} else {
if machine.Spec.ProviderConfig.ValueFrom.MachineClass == nil {
if providerSpec.ValueFrom.MachineClass == nil {
return nil, fmt.Errorf("unable to find MachineClass on Spec.ProviderConfig.ValueFrom")
}
machineClass := &clusterv1.MachineClass{}
key := types.NamespacedName{
Namespace: machine.Spec.ProviderConfig.ValueFrom.MachineClass.Namespace,
Name: machine.Spec.ProviderConfig.ValueFrom.MachineClass.Name,
Namespace: providerSpec.ValueFrom.MachineClass.Namespace,
Name: providerSpec.ValueFrom.MachineClass.Name,
}
if err := client.Get(context.Background(), key, machineClass); err != nil {
return nil, err
}
providerConfig = machineClass.ProviderConfig
providerSpecRawExtention = machineClass.ProviderSpec
}

var config providerconfigv1.AWSMachineProviderConfig
if err := codec.DecodeProviderConfig(&clusterv1.ProviderConfig{Value: &providerConfig}, &config); err != nil {
if err := codec.DecodeProviderConfig(&clusterv1.ProviderSpec{Value: &providerSpecRawExtention}, &config); err != nil {
return nil, err
}
return &config, nil
Expand Down
8 changes: 4 additions & 4 deletions pkg/cloud/aws/actuators/machine/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func TestProviderConfigFromMachine(t *testing.T) {
Namespace: "openshift-cluster-api",
Name: "testClass",
},
ProviderConfig: *encodedProviderConfig.Value,
ProviderSpec: *encodedProviderConfig.Value,
}

testCases := []struct {
Expand All @@ -79,7 +79,7 @@ func TestProviderConfigFromMachine(t *testing.T) {
Kind: "Machine",
},
Spec: clusterv1.MachineSpec{
ProviderConfig: *encodedProviderConfig,
ProviderSpec: *encodedProviderConfig,
},
},
},
Expand All @@ -96,8 +96,8 @@ func TestProviderConfigFromMachine(t *testing.T) {
Kind: "Machine",
},
Spec: clusterv1.MachineSpec{
ProviderConfig: clusterv1.ProviderConfig{
ValueFrom: &clusterv1.ProviderConfigSource{
ProviderSpec: clusterv1.ProviderSpec{
ValueFrom: &clusterv1.ProviderSpecSource{
MachineClass: &clusterv1.MachineClassRef{
ObjectReference: &corev1.ObjectReference{
Kind: "MachineClass",
Expand Down
12 changes: 8 additions & 4 deletions test/machines/machines_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ var _ = framework.SigKubeDescribe("Machines", func() {
_, err = f.KubeClient.CoreV1().Namespaces().Create(testNamespace)
Expect(err).NotTo(HaveOccurred())

f.DeployClusterAPIStack(testNamespace.Name, f.ActuatorImage, "")
f.DeployClusterAPIStack(testNamespace.Name, "")
})

AfterEach(func() {
// Make sure all machine(set)s are deleted before deleting its namespace
machinesToDelete.Delete()

if testNamespace != nil {
f.DestroyClusterAPIStack(testNamespace.Name, f.ActuatorImage, "")
f.DestroyClusterAPIStack(testNamespace.Name, "")
log.Infof(testNamespace.Name+": %#v", testNamespace)
By(fmt.Sprintf("Destroying %q namespace", testNamespace.Name))
f.KubeClient.CoreV1().Namespaces().Delete(testNamespace.Name, &metav1.DeleteOptions{})
Expand Down Expand Up @@ -243,8 +243,12 @@ var _ = framework.SigKubeDescribe("Machines", func() {
dnsName, err := acw.GetPublicDNSName(masterMachine)
Expect(err).NotTo(HaveOccurred())

err = f.UploadDockerImageToInstance(f.ActuatorImage, dnsName)
err = f.UploadDockerImageToInstance(f.MachineControllerImage, dnsName)
Expect(err).NotTo(HaveOccurred())
if f.MachineManagerImage != f.MachineControllerImage {
err = f.UploadDockerImageToInstance(f.MachineManagerImage, dnsName)
Expect(err).NotTo(HaveOccurred())
}

// Deploy the cluster API stack inside the master machine
sshConfig, err := framework.DefaultSSHConfig()
Expand All @@ -255,7 +259,7 @@ var _ = framework.SigKubeDescribe("Machines", func() {
_, err = clusterFramework.KubeClient.CoreV1().Namespaces().Create(testNamespace)
Expect(err).NotTo(HaveOccurred())

clusterFramework.DeployClusterAPIStack(testNamespace.Name, f.ActuatorImage, "")
clusterFramework.DeployClusterAPIStack(testNamespace.Name, "")

By("Deploy worker nodes through machineset")
masterPrivateIP, err := acw.GetPrivateIP(masterMachine)
Expand Down
18 changes: 9 additions & 9 deletions test/utils/manifests.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func GenerateAwsCredentialsSecretFromEnv(secretName, namespace string) *apiv1.Se
}
}

func TestingMachineProviderConfig(awsCredentialsSecretName string, clusterID string) (clusterv1alpha1.ProviderConfig, error) {
func TestingMachineProviderConfig(awsCredentialsSecretName string, clusterID string) (clusterv1alpha1.ProviderSpec, error) {
publicIP := true
machinePc := &providerconfigv1.AWSMachineProviderConfig{
AMI: providerconfigv1.AWSResourceReference{
Expand Down Expand Up @@ -89,16 +89,16 @@ func TestingMachineProviderConfig(awsCredentialsSecretName string, clusterID str

codec, err := providerconfigv1.NewCodec()
if err != nil {
return clusterv1alpha1.ProviderConfig{}, fmt.Errorf("failed creating codec: %v", err)
return clusterv1alpha1.ProviderSpec{}, fmt.Errorf("failed creating codec: %v", err)
}
config, err := codec.EncodeProviderConfig(machinePc)
if err != nil {
return clusterv1alpha1.ProviderConfig{}, fmt.Errorf("EncodeToProviderConfig failed: %v", err)
return clusterv1alpha1.ProviderSpec{}, fmt.Errorf("EncodeToProviderConfig failed: %v", err)
}
return *config, nil
}

func MasterMachineProviderConfig(awsCredentialsSecretName, masterUserDataSecretName, clusterID string) (clusterv1alpha1.ProviderConfig, error) {
func MasterMachineProviderConfig(awsCredentialsSecretName, masterUserDataSecretName, clusterID string) (clusterv1alpha1.ProviderSpec, error) {
publicIP := true
machinePc := &providerconfigv1.AWSMachineProviderConfig{
AMI: providerconfigv1.AWSResourceReference{
Expand Down Expand Up @@ -151,16 +151,16 @@ func MasterMachineProviderConfig(awsCredentialsSecretName, masterUserDataSecretN

codec, err := providerconfigv1.NewCodec()
if err != nil {
return clusterv1alpha1.ProviderConfig{}, fmt.Errorf("failed creating codec: %v", err)
return clusterv1alpha1.ProviderSpec{}, fmt.Errorf("failed creating codec: %v", err)
}
config, err := codec.EncodeProviderConfig(machinePc)
if err != nil {
return clusterv1alpha1.ProviderConfig{}, fmt.Errorf("EncodeToProviderConfig failed: %v", err)
return clusterv1alpha1.ProviderSpec{}, fmt.Errorf("EncodeToProviderConfig failed: %v", err)
}
return *config, nil
}

func WorkerMachineSetProviderConfig(awsCredentialsSecretName, workerUserDataSecretName, clusterID string) (clusterv1alpha1.ProviderConfig, error) {
func WorkerMachineSetProviderConfig(awsCredentialsSecretName, workerUserDataSecretName, clusterID string) (clusterv1alpha1.ProviderSpec, error) {
publicIP := true
machinePc := &providerconfigv1.AWSMachineProviderConfig{
AMI: providerconfigv1.AWSResourceReference{
Expand Down Expand Up @@ -213,11 +213,11 @@ func WorkerMachineSetProviderConfig(awsCredentialsSecretName, workerUserDataSecr

codec, err := providerconfigv1.NewCodec()
if err != nil {
return clusterv1alpha1.ProviderConfig{}, fmt.Errorf("failed creating codec: %v", err)
return clusterv1alpha1.ProviderSpec{}, fmt.Errorf("failed creating codec: %v", err)
}
config, err := codec.EncodeProviderConfig(machinePc)
if err != nil {
return clusterv1alpha1.ProviderConfig{}, fmt.Errorf("EncodeToProviderConfig failed: %v", err)
return clusterv1alpha1.ProviderSpec{}, fmt.Errorf("EncodeToProviderConfig failed: %v", err)
}
return *config, nil
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5b512aa

Please sign in to comment.