Skip to content

Commit

Permalink
Make Ubuntu a default OS for tinkerbell and add validation for 1.29 k…
Browse files Browse the repository at this point in the history
…8s version for BR family (#7655)
  • Loading branch information
panktishah26 authored Feb 21, 2024
1 parent 82857da commit 6394dad
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/api/v1alpha1/tinkerbelldatacenterconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type TinkerbellDatacenterConfigSpec struct {
// It must include the Kubernetes version(s). For example, a URL used for Kubernetes 1.27 could
// be http://localhost:8080/ubuntu-2204-1.27.tgz
//+optional
OSImageURL string `json:"osImageURL,omitempty"`
OSImageURL string `json:"osImageURL"`
// HookImagesURLPath can be used to override the default Hook images path to pull from a local server.
HookImagesURLPath string `json:"hookImagesURLPath,omitempty"`
// SkipLoadBalancerDeployment when set to "true" can be used to skip deploying a load balancer to expose Tinkerbell stack.
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/v1alpha1/tinkerbellmachineconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func NewTinkerbellMachineConfigGenerate(name string, opts ...TinkerbellMachineCo
},
Spec: TinkerbellMachineConfigSpec{
HardwareSelector: HardwareSelector{},
OSFamily: Bottlerocket,
OSFamily: Ubuntu,
Users: []UserConfiguration{
{
Name: "ec2-user",
Expand Down
34 changes: 34 additions & 0 deletions pkg/providers/tinkerbell/assert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,40 @@ func TestAssertMachineConfigNamespaceMatchesDatacenterConfig_Different(t *testin
g.Expect(err).ToNot(gomega.Succeed())
}

func TestAssertMachineConfigK8sVersionBRCP_Error(t *testing.T) {
g := gomega.NewWithT(t)
builder := NewDefaultValidClusterSpecBuilder()
clusterSpec := builder.Build()
clusterSpec.Spec.Cluster.Spec.ExternalEtcdConfiguration = nil
clusterSpec.Spec.Cluster.Spec.KubernetesVersion = eksav1alpha1.Kube129
clusterSpec.MachineConfigs[builder.ControlPlaneMachineName].Spec.OSFamily = "bottlerocket"
err := tinkerbell.AssertOsFamilyValid(clusterSpec)
g.Expect(err).ToNot(gomega.Succeed())
}

func TestAssertMachineConfigK8sVersionBRWorker_Error(t *testing.T) {
g := gomega.NewWithT(t)
builder := NewDefaultValidClusterSpecBuilder()
clusterSpec := builder.Build()
clusterSpec.Spec.Cluster.Spec.ExternalEtcdConfiguration = nil
clusterSpec.Spec.Cluster.Spec.KubernetesVersion = eksav1alpha1.Kube129
clusterSpec.MachineConfigs[builder.WorkerNodeGroupMachineName].Spec.OSFamily = "bottlerocket"
err := tinkerbell.AssertOsFamilyValid(clusterSpec)
g.Expect(err).ToNot(gomega.Succeed())
}

func TestAssertMachineConfigK8sVersionBR_Success(t *testing.T) {
g := gomega.NewWithT(t)
builder := NewDefaultValidClusterSpecBuilder()
clusterSpec := builder.Build()
clusterSpec.Spec.Cluster.Spec.ExternalEtcdConfiguration = nil
clusterSpec.Spec.Cluster.Spec.KubernetesVersion = eksav1alpha1.Kube128
clusterSpec.MachineConfigs[builder.ControlPlaneMachineName].Spec.OSFamily = "bottlerocket"
clusterSpec.MachineConfigs[builder.WorkerNodeGroupMachineName].Spec.OSFamily = "bottlerocket"
err := tinkerbell.AssertOsFamilyValid(clusterSpec)
g.Expect(err).To(gomega.Succeed())
}

func TestAssertMachineConfigOSImageURL_Error(t *testing.T) {
g := gomega.NewWithT(t)
builder := NewDefaultValidClusterSpecBuilder()
Expand Down
25 changes: 25 additions & 0 deletions pkg/providers/tinkerbell/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/aws/eks-anywhere/pkg/api/v1alpha1"
"github.com/aws/eks-anywhere/pkg/networkutils"
"github.com/aws/eks-anywhere/pkg/providers/tinkerbell/hardware"
"github.com/aws/eks-anywhere/pkg/semver"
)

func validateOsFamily(spec *ClusterSpec) error {
Expand All @@ -23,11 +24,22 @@ func validateOsFamily(spec *ClusterSpec) error {
}
}

if controlPlaneOsFamily == v1alpha1.Bottlerocket {
if err := validateK8sVersionForBottleRocketOS(string(spec.Cluster.Spec.KubernetesVersion)); err != nil {
return fmt.Errorf("machineGroupRef %s: %v", controlPlaneRef.Name, err)
}
}

for _, group := range spec.Cluster.Spec.WorkerNodeGroupConfigurations {
groupRef := group.MachineGroupRef
if spec.MachineConfigs[groupRef.Name].OSFamily() != controlPlaneOsFamily {
return errors.New("worker node group osFamily cannot be different from control plane osFamily")
}
if group.KubernetesVersion != nil && *group.KubernetesVersion != "" && spec.MachineConfigs[groupRef.Name].OSFamily() == v1alpha1.Bottlerocket {
if err := validateK8sVersionForBottleRocketOS(string(*group.KubernetesVersion)); err != nil {
return fmt.Errorf("machineGroupRef %s: %v", groupRef.Name, err)
}
}
}

if controlPlaneOsFamily != v1alpha1.Bottlerocket && spec.DatacenterConfig.Spec.OSImageURL == "" && spec.ControlPlaneMachineConfig().Spec.OSImageURL == "" {
Expand All @@ -37,6 +49,19 @@ func validateOsFamily(spec *ClusterSpec) error {
return nil
}

func validateK8sVersionForBottleRocketOS(kubernetesVersion string) error {
kubeVersionSemver, err := semver.New(kubernetesVersion + ".0")
if err != nil {
return fmt.Errorf("converting kubeVersion %v to semver %v", kubernetesVersion, err)
}

kube128Semver, _ := semver.New(string(v1alpha1.Kube128) + ".0")
if kubeVersionSemver.GreaterThan(kube128Semver) {
return errors.New("tinkerbell provider does not support K8s version 1.29+ for BottleRocket OS")
}
return nil
}

func validateUpgradeRolloutStrategy(spec *ClusterSpec) error {
cpUpgradeRolloutStrategyType := v1alpha1.RollingUpdateStrategyType

Expand Down

0 comments on commit 6394dad

Please sign in to comment.