Skip to content

Commit

Permalink
omit KubeletConfiguration and Limits from Spec if empty
Browse files Browse the repository at this point in the history
  • Loading branch information
bwagner5 committed Mar 10, 2022
1 parent ba89ba8 commit b288072
Show file tree
Hide file tree
Showing 12 changed files with 22 additions and 14 deletions.
2 changes: 1 addition & 1 deletion pkg/apis/provisioning/v1alpha5/constraints.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type Constraints struct {
Requirements Requirements `json:"requirements,inline,omitempty"`
// KubeletConfiguration are options passed to the kubelet when provisioning nodes
//+optional
KubeletConfiguration KubeletConfiguration `json:"kubeletConfiguration,omitempty"`
KubeletConfiguration *KubeletConfiguration `json:"kubeletConfiguration,omitempty"`
// Provider contains fields specific to your cloudprovider.
// +kubebuilder:pruning:PreserveUnknownFields
Provider *Provider `json:"provider,omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/provisioning/v1alpha5/limits.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type Limits struct {
}

func (l *Limits) ExceededBy(resources v1.ResourceList) error {
if l.Resources == nil {
if l == nil || l.Resources == nil {
return nil
}
for resourceName, usage := range resources {
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/provisioning/v1alpha5/provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type ProvisionerSpec struct {
// +optional
TTLSecondsUntilExpired *int64 `json:"ttlSecondsUntilExpired,omitempty"`
// Limits define a set of bounds for provisioning capacity.
Limits Limits `json:"limits,omitempty"`
Limits *Limits `json:"limits,omitempty"`
}

// Provisioner is the Schema for the Provisioners API
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/provisioning/v1alpha5/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ var _ = Describe("Validation", func() {

Context("Limits", func() {
It("should allow undefined limits", func() {
provisioner.Spec.Limits = Limits{}
provisioner.Spec.Limits = &Limits{}
Expect(provisioner.Validate(ctx)).To(Succeed())
})
It("should allow empty limits", func() {
provisioner.Spec.Limits = Limits{Resources: v1.ResourceList{}}
provisioner.Spec.Limits = &Limits{Resources: v1.ResourceList{}}
Expect(provisioner.Validate(ctx)).To(Succeed())
})
})
Expand Down
12 changes: 10 additions & 2 deletions pkg/apis/provisioning/v1alpha5/zz_generated.deepcopy.go

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

2 changes: 1 addition & 1 deletion pkg/cloudprovider/aws/amifamily/al2.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (a AL2) SSMAlias(version string, instanceType cloudprovider.InstanceType) s
// even if elements of those inputs are in differing orders,
// guaranteeing it won't cause spurious hash differences.
// AL2 userdata also works on Ubuntu
func (a AL2) UserData(kubeletConfig v1alpha5.KubeletConfiguration, taints []core.Taint, labels map[string]string, caBundle *string) bootstrap.Bootstrapper {
func (a AL2) UserData(kubeletConfig *v1alpha5.KubeletConfiguration, taints []core.Taint, labels map[string]string, caBundle *string) bootstrap.Bootstrapper {
return bootstrap.EKS{
Options: bootstrap.Options{
ClusterName: a.Options.ClusterName,
Expand Down
2 changes: 1 addition & 1 deletion pkg/cloudprovider/aws/amifamily/bootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
type Options struct {
ClusterName string
ClusterEndpoint string
KubeletConfig v1alpha5.KubeletConfiguration
KubeletConfig *v1alpha5.KubeletConfiguration
Taints []core.Taint `hash:"set"`
Labels map[string]string `hash:"set"`
CABundle *string
Expand Down
2 changes: 1 addition & 1 deletion pkg/cloudprovider/aws/amifamily/bootstrap/bottlerocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (b Bottlerocket) Script() string {
NodeLabels: b.Labels,
},
}}
if len(b.KubeletConfig.ClusterDNS) > 0 {
if b.KubeletConfig != nil && len(b.KubeletConfig.ClusterDNS) > 0 {
s.Settings.Kubernetes.ClusterDNSIP = b.KubeletConfig.ClusterDNS[0]
}
if !b.AWSENILimitedPodDensity {
Expand Down
2 changes: 1 addition & 1 deletion pkg/cloudprovider/aws/amifamily/bootstrap/eksbootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (e EKS) Script() string {
if kubeletExtraArgs = strings.Trim(kubeletExtraArgs, " "); len(kubeletExtraArgs) > 0 {
userData.WriteString(fmt.Sprintf(" \\\n--kubelet-extra-args='%s'", kubeletExtraArgs))
}
if len(e.KubeletConfig.ClusterDNS) > 0 {
if e.KubeletConfig != nil && len(e.KubeletConfig.ClusterDNS) > 0 {
userData.WriteString(fmt.Sprintf(" \\\n--dns-cluster-ip='%s'", e.KubeletConfig.ClusterDNS[0]))
}
return base64.StdEncoding.EncodeToString(userData.Bytes())
Expand Down
2 changes: 1 addition & 1 deletion pkg/cloudprovider/aws/amifamily/bottlerocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (b Bottlerocket) SSMAlias(version string, instanceType cloudprovider.Instan
}

// UserData returns the default userdata script for the AMI Family
func (b Bottlerocket) UserData(kubeletConfig v1alpha5.KubeletConfiguration, taints []core.Taint, labels map[string]string, caBundle *string) bootstrap.Bootstrapper {
func (b Bottlerocket) UserData(kubeletConfig *v1alpha5.KubeletConfiguration, taints []core.Taint, labels map[string]string, caBundle *string) bootstrap.Bootstrapper {
return bootstrap.Bottlerocket{
Options: bootstrap.Options{
ClusterName: b.Options.ClusterName,
Expand Down
2 changes: 1 addition & 1 deletion pkg/cloudprovider/aws/amifamily/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ type LaunchTemplate struct {

// AMIFamily can be implemented to override the default logic for generating dynamic launch template parameters
type AMIFamily interface {
UserData(kubeletConfig v1alpha5.KubeletConfiguration, taints []core.Taint, labels map[string]string, caBundle *string) bootstrap.Bootstrapper
UserData(kubeletConfig *v1alpha5.KubeletConfiguration, taints []core.Taint, labels map[string]string, caBundle *string) bootstrap.Bootstrapper
SSMAlias(version string, instanceType cloudprovider.InstanceType) string
DefaultBlockDeviceMappings() []*v1alpha1.BlockDeviceMapping
DefaultMetadataOptions() *v1alpha1.MetadataOptions
Expand Down
2 changes: 1 addition & 1 deletion pkg/cloudprovider/aws/amifamily/ubuntu.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (u Ubuntu) SSMAlias(version string, instanceType cloudprovider.InstanceType
}

// UserData returns the default userdata script for the AMI Family
func (u Ubuntu) UserData(kubeletConfig v1alpha5.KubeletConfiguration, taints []core.Taint, labels map[string]string, caBundle *string) bootstrap.Bootstrapper {
func (u Ubuntu) UserData(kubeletConfig *v1alpha5.KubeletConfiguration, taints []core.Taint, labels map[string]string, caBundle *string) bootstrap.Bootstrapper {
return bootstrap.EKS{
Options: bootstrap.Options{
ClusterName: u.Options.ClusterName,
Expand Down

0 comments on commit b288072

Please sign in to comment.