Skip to content
Closed
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
84 changes: 83 additions & 1 deletion Gopkg.lock

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

13 changes: 13 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,19 @@ ignored = ["github.com/openshift/installer/tests*"]
name = "k8s.io/client-go"
version = "6.0.0"

[[constraint]]
name = "sigs.k8s.io/cluster-api"
branch = "master"

[[constraint]]
name = "sigs.k8s.io/cluster-api-provider-aws"
source = "https://github.com/openshift/cluster-api-provider-aws.git"
branch = "master"

[[constraint]]
name = "github.com/openshift/cluster-api-provider-libvirt"
branch = "master"

[[constraint]]
name = "github.com/pkg/errors"
version = "0.8.0"
Expand Down
84 changes: 84 additions & 0 deletions pkg/asset/machines/aws/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@
package aws

import (
"fmt"
"text/template"

awsprovider "sigs.k8s.io/cluster-api-provider-aws/pkg/apis/awsproviderconfig/v1alpha1"
clusterapi "sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha1"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like an inconsistent indent issue here.

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"

"github.com/openshift/installer/pkg/types"
)

Expand All @@ -30,6 +37,83 @@ type MachineConfig struct {
Machine types.AWSMachinePoolPlatform
}

func createWorkerMachineSets(config *WorkerConfig) metav1.List {
list := metav1.List{}
list.Kind = "List"
Comment thread
wking marked this conversation as resolved.
items := make([]runtime.RawExtension, 0)
for i, instance := range config.Instances {
ms := clusterapi.MachineSet{}
ms.Kind = "MachineSet"
ms.Name = fmt.Sprintf("%s-worker-%d", config.ClusterName, i)
ms.Namespace = "openshift-cluster-api"
ms.Labels = map[string]string{
"sigs.k8s.io/cluster-api-cluster": config.ClusterName,
"sigs.k8s.io/cluster-api-machine-role": "worker",
"sigs.k8s.io/cluster-api-machine-type": "worker",
}
ms.Spec = clusterapi.MachineSetSpec{}
ms.Spec.Replicas = new(int32)
*ms.Spec.Replicas = int32(instance.Replicas)
ms.Spec.Selector = metav1.LabelSelector{}
ms.Spec.Selector.MatchLabels = map[string]string{
"sigs.k8s.io/cluster-api-machineset": "worker",
"sigs.k8s.io/cluster-api-cluster": config.ClusterName,
}

template := clusterapi.MachineTemplateSpec{}
template.Labels = map[string]string{
"sigs.k8s.io/cluster-api-machineset": "worker",
"sigs.k8s.io/cluster-api-cluster": config.ClusterName,
"sigs.k8s.io/cluster-api-machine-role": "worker",
"sigs.k8s.io/cluster-api-machine-type": "worker",
}
template.Spec = clusterapi.MachineSpec{}
provider := awsprovider.AWSMachineProviderConfig{}
provider.APIVersion = "aws.cluster.k8s.io/v1alpha1"
provider.InstanceType = config.Machine.InstanceType
provider.AMI = awsprovider.AWSResourceReference{ID: new(string)}
*provider.AMI.ID = config.AMIID
provider.Subnet = awsprovider.AWSResourceReference{
Filters: []awsprovider.Filter{
{
Name: "tag:Name",
Values: []string{fmt.Sprintf("%s-worker-%s", config.ClusterName, instance.AvailabilityZone)},
},
},
}
provider.Placement = awsprovider.Placement{Region: config.Region, AvailabilityZone: instance.AvailabilityZone}
provider.IAMInstanceProfile = &awsprovider.AWSResourceReference{ID: new(string)}
*provider.IAMInstanceProfile.ID = fmt.Sprintf("%s-worker-profile", config.ClusterName)
provider.Tags = make([]awsprovider.TagSpecification, 0)
for tagName, tagValue := range config.Tags {
provider.Tags = append(provider.Tags, awsprovider.TagSpecification{Name: tagName, Value: tagValue})
}
provider.SecurityGroups = []awsprovider.AWSResourceReference{
{
Filters: []awsprovider.Filter{
{
Name: "tag:Name",
Values: []string{fmt.Sprintf("%s_worker_sg", config.ClusterName)},
},
},
},
}
provider.UserDataSecret = &corev1.LocalObjectReference{Name: "worker-user-data"}

template.Spec.ProviderConfig = clusterapi.ProviderConfig{Value: &runtime.RawExtension{Object: &provider}}
template.Spec.Versions = clusterapi.MachineVersionInfo{
Kubelet: "",
ControlPlane: "",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does setting these to their zero value do anything? Do we need to populate Spec.Versions at all?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is how it was in the template. I am guessing we do want to write the correct values at some point. Next to no harm for now.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is how it was in the template.

Presumably because the upstream type is missing some omitempty.

I am guessing we do want to write the correct values at some point. Next to no harm for now.

I'd rather address that with FIXME comments in the code and/or GitHub issues to track the planned future work. Leaving empty strings here doesn't seem like an obvious way to track future work.

}
ms.Spec.Template = template

// add the machineset to items
items = append(items, runtime.RawExtension{Object: &ms})

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the local items vs.:

list.Items = append(list.Items, runtime.RawExtension{Object: &ms})

?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just logically constructing the all the structures leaf-up along. No particular reason here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just logically constructing the all the structures leaf-up along.

I'm fine with that approach if you want to shift the root type declaration down to the end of the function. But I'd rather not have both a beginning-of-the-function root declaration and leaf local variables.

}
list.Items = items
return list
}

// WorkerMachineSetsTmpl is template for worker machinesets.
var WorkerMachineSetsTmpl = template.Must(template.New("aws-worker-machinesets").Parse(`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we drop this now?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, forthcoming commit, when I tie this all up with other templates.

{{- $c := . -}}
Expand Down
21 changes: 21 additions & 0 deletions vendor/github.com/json-iterator/go/LICENSE

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

Loading