-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Convert machineset templates to actual objects #567
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
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" | ||
) | ||
|
||
|
@@ -30,6 +37,83 @@ type MachineConfig struct { | |
Machine types.AWSMachinePoolPlatform | ||
} | ||
|
||
func createWorkerMachineSets(config *WorkerConfig) metav1.List { | ||
list := metav1.List{} | ||
list.Kind = "List" | ||
wking marked this conversation as resolved.
Show resolved
Hide 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: "", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Presumably because the upstream type is missing some
I'd rather address that with |
||
} | ||
ms.Spec.Template = template | ||
|
||
// add the machineset to items | ||
items = append(items, runtime.RawExtension{Object: &ms}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why the local list.Items = append(list.Items, runtime.RawExtension{Object: &ms}) ? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
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(` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we drop this now? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 := . -}} | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
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.