Skip to content

Commit

Permalink
more pr review
Browse files Browse the repository at this point in the history
  • Loading branch information
jmdeal committed Apr 29, 2024
1 parent f59eff2 commit 2f62523
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 17 deletions.
32 changes: 20 additions & 12 deletions cmd/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ limitations under the License.
package main

import (
"context"
"fmt"
"strings"

"github.com/samber/lo"
Expand All @@ -26,6 +28,7 @@ import (
"github.com/aws/karpenter-provider-aws/pkg/operator"
"github.com/aws/karpenter-provider-aws/pkg/webhooks"

"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/karpenter/pkg/cloudprovider/metrics"
corecontrollers "sigs.k8s.io/karpenter/pkg/controllers"
"sigs.k8s.io/karpenter/pkg/controllers/state"
Expand All @@ -47,18 +50,8 @@ func main() {
lo.Must0(op.AddHealthzCheck("cloud-provider", awsCloudProvider.LivenessProbe))
cloudProvider := metrics.Decorate(awsCloudProvider)

client := op.Manager.GetAPIReader()
nodeClassList := v1beta1.EC2NodeClassList{}
err := client.List(ctx, &nodeClassList)
if err != nil {
logging.FromContext(ctx).Fatalf("failed to list EC2NodeClasses on startup, %s", err.Error())
}

invalidNodeClasses := lo.FilterMap(nodeClassList.Items, func(nc v1beta1.EC2NodeClass, _ int) (string, bool) {
return nc.Name, len(nc.Spec.AMISelectorTerms) == 0
})
if len(invalidNodeClasses) != 0 {
logging.FromContext(ctx).With("ec2nodeclasses", strings.Join(invalidNodeClasses, ",")).Fatalf("detected EC2NodeClasses with un-set AMISelectorTerms. Upgrade your EC2NodeClasses to include AMISelectorTerms to continue.")
if err := validateEC2NodeClasses(ctx, op.GetAPIReader()); err != nil {
logging.FromContext(ctx).Fatalf("validating EC2NodeClasses, %s", err)
}

op.
Expand Down Expand Up @@ -90,3 +83,18 @@ func main() {
WithWebhooks(ctx, webhooks.NewWebhooks()...).
Start(ctx)
}

// validateEC2NodeClasses ensures all EC2NodeClasses specify AMISelectorTerms (required as of v0.37.0)
func validateEC2NodeClasses(ctx context.Context, reader client.Reader) error {
nodeClassList := v1beta1.EC2NodeClassList{}
err := reader.List(ctx, &nodeClassList)
if err != nil {
return fmt.Errorf("listing EC2NodeClasses on startup, %s", err.Error())
}
if invalidNodeClasses := lo.FilterMap(nodeClassList.Items, func(nc v1beta1.EC2NodeClass, _ int) (string, bool) {
return nc.Name, len(nc.Spec.AMISelectorTerms) == 0
}); len(invalidNodeClasses) != 0 {
return fmt.Errorf("detected EC2NodeClasses with un-set AMISelectorTerms (%s), refer to the 0.37.0+ upgrade guide: https://karpenter.sh/upgrading/upgrade-guide/#upgrading-to-0370.", strings.Join(invalidNodeClasses, ","))

Check failure on line 97 in cmd/controller/main.go

View workflow job for this annotation

GitHub Actions / ci

ST1005: error strings should not end with punctuation or newlines (stylecheck)
}
return nil
}
4 changes: 2 additions & 2 deletions pkg/apis/v1beta1/ec2nodeclass_validation_cel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ var _ = Describe("CEL/Validation", func() {
Expect(env.Client.Create(ctx, nc)).ToNot(Succeed())
})
DescribeTable(
"should succeed with a valid eksOptimized familiy",
"should succeed with a valid eksOptimized family",
func(family string) {
nc.Spec.AMIFamily = &family
nc.Spec.AMISelectorTerms = []v1beta1.AMISelectorTerm{{
Expand Down Expand Up @@ -402,7 +402,7 @@ var _ = Describe("CEL/Validation", func() {
}
}
})
It("should succed when the eksOptimized family matches amiFamily", func() {
It("should succeed when the eksOptimized family matches amiFamily", func() {
for _, family := range []string{
v1beta1.AMIFamilyAL2,
v1beta1.AMIFamilyAL2023,
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/v1beta1/ec2nodeclass_validation_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ var _ = Describe("Webhook/Validation", func() {
Expect(nc.Validate(ctx)).ToNot(Succeed())
})
DescribeTable(
"should succeed with a valid eksOptimized familiy",
"should succeed with a valid eksOptimized family",
func(family string) {
nc.Spec.AMIFamily = &family
nc.Spec.AMISelectorTerms = []v1beta1.AMISelectorTerm{{
Expand Down Expand Up @@ -414,7 +414,7 @@ var _ = Describe("Webhook/Validation", func() {
}
}
})
It("should succed when the eksOptimized family matches amiFamily", func() {
It("should succeed when the eksOptimized family matches amiFamily", func() {
for _, family := range []string{
v1beta1.AMIFamilyAL2,
v1beta1.AMIFamilyAL2023,
Expand Down
1 change: 0 additions & 1 deletion pkg/providers/launchtemplate/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1773,7 +1773,6 @@ var _ = Describe("LaunchTemplate Provider", func() {
)
It("should fail to create launch templates if cluster CIDR is unresolved", func() {
awsEnv.LaunchTemplateProvider.ClusterCIDR.Store(nil)
fmt.Printf("nodeClass: %s\n", string(lo.Must(json.Marshal(nodeClass))))
ExpectApplied(ctx, env.Client, nodeClass, nodePool)
pod := coretest.UnschedulablePod()
ExpectProvisioned(ctx, env.Client, cluster, cloudProvider, prov, pod)
Expand Down
12 changes: 12 additions & 0 deletions website/content/en/preview/upgrading/upgrade-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ WHEN CREATING A NEW SECTION OF THE UPGRADE GUIDANCE FOR NEWER VERSIONS, ENSURE T

### Upgrading to `0.37.0`+

{{% alert title="Warning" color="warning" %}}
`0.33.0`+ _only_ supports Karpenter v1beta1 APIs and will not work with existing Provisioner, AWSNodeTemplate or Machine alpha APIs. Do not upgrade to `0.36.0`+ without first [upgrading to `0.32.x`]({{<ref "#upgrading-to-0320" >}}). This version supports both the alpha and beta APIs, allowing you to migrate all of your existing APIs to beta APIs without experiencing downtime.
{{% /alert %}}

{{% alert title="Warning" color="warning" %}}
v0.36.x introduces update to drift that restricts rollback. When rolling back from >=v0.36.0, note that v0.32.9+, v0.33.4+, v0.34.5+, v0.35.4+ are the patch versions that support rollback. If Karpenter is rolled back to an older patch version, Karpenter can potentially drift all the nodes in the cluster.
{{% /alert %}}

{{% alert title="Warning" color="warning" %}}
Starting at `v0.37.0`, the `ec2nodeclass.spec.amiSelectorTerms` field is required. When upgrading from previous Karpetner versions, the controller will continue to panic until `amiSelectorTerms` have been specified for all `EC2NodeClasses` applied to the cluster. Please refer to the [`AMISelectorTerms` documentation]({{<ref "../concepts/nodeclasses#spec-amiFamily" >}}) for more details.
{{% /alert %}}

* Karpenter updated the NodeClass controller naming in the following way: `nodeclass` -> `nodeclass.status`, `nodeclass.hash`, `nodeclass.termination`

### Upgrading to `0.36.0`+
Expand Down

0 comments on commit 2f62523

Please sign in to comment.