Skip to content
Merged
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
129 changes: 76 additions & 53 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,71 +1,94 @@
# See https://github.com/golangci/golangci-lint/blob/master/.golangci.example.yml
version: "2"
run:
tests: true
timeout: 5m
linters:
enable:
- asciicheck
- bidichk
- errorlint
- copyloopvar
- errorlint
- gocyclo
- goheader
- gosec
- misspell
- nilerr
- revive
- stylecheck
- staticcheck
- tparallel
- unconvert
- unparam
- gocyclo
- govet
- goimports
- goheader
- misspell
- nilerr
disable:
- prealloc
linters-settings:
gocyclo:
min-complexity: 11
govet:
enable-all: true
disable:
- fieldalignment
revive:
settings:
gocyclo:
min-complexity: 11
goheader:
template: |-
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
govet:
disable:
- fieldalignment
enable-all: true
misspell:
locale: US
revive:
rules:
- name: dot-imports
disabled: true
staticcheck:
dot-import-whitelist:
- github.com/onsi/ginkgo/v2
- github.com/onsi/gomega
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
rules:
- name: dot-imports
disabled: true
stylecheck:
dot-import-whitelist:
- "github.com/onsi/ginkgo/v2"
- "github.com/onsi/gomega"
misspell:
locale: US
ignore-words: []
goimports:
local-prefixes: github.com/aws/karpenter-provider-aws
goheader:
template: |-
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
- linters:
- goheader
path: zz_(.+)\.go
- path: (.+)\.go$
text: declaration of "(err|ctx)" shadows declaration at
paths:
- tools
- website
- hack
- charts
- designs
- third_party$
- builtin$
- examples$
issues:
fix: true
exclude: ['declaration of "(err|ctx)" shadows declaration at']
exclude-dirs:
- tools
- website
- hack
- charts
- designs
exclude-rules:
- linters:
- goheader
path: 'zz_(.+)\.go'

formatters:
enable:
- goimports
settings:
goimports:
local-prefixes:
- github.com/aws/karpenter-provider-aws
exclusions:
generated: lax
paths:
- tools
- website
- hack
- charts
- designs
- third_party$
- builtin$
- examples$
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ metadata:
{{- with .Values.additionalAnnotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
controller-gen.kubebuilder.io/version: v0.18.0
controller-gen.kubebuilder.io/version: v0.19.0
name: nodeclaims.karpenter.sh
spec:
group: karpenter.sh
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ metadata:
{{- with .Values.additionalAnnotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
controller-gen.kubebuilder.io/version: v0.18.0
controller-gen.kubebuilder.io/version: v0.19.0
name: nodepools.karpenter.sh
spec:
group: karpenter.sh
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ require (
k8s.io/klog/v2 v2.130.1
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738
sigs.k8s.io/controller-runtime v0.20.2
sigs.k8s.io/karpenter v1.3.3
sigs.k8s.io/karpenter v1.3.4-0.20251001203658-9331efba088c
sigs.k8s.io/yaml v1.4.0
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,8 @@ sigs.k8s.io/controller-runtime v0.20.2 h1:/439OZVxoEc02psi1h4QO3bHzTgu49bb347Xp4
sigs.k8s.io/controller-runtime v0.20.2/go.mod h1:xg2XB0K5ShQzAgsoujxuKN4LNXR2LfwwHsPj7Iaw+XY=
sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 h1:/Rv+M11QRah1itp8VhT6HoVx1Ray9eB4DBr+K+/sCJ8=
sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3/go.mod h1:18nIHnGi6636UCz6m8i4DhaJ65T6EruyzmoQqI2BVDo=
sigs.k8s.io/karpenter v1.3.3 h1:Kxl5PhuJjzmKlKBH0IUofwPcJf40vxDXBH/kfaZ/VbI=
sigs.k8s.io/karpenter v1.3.3/go.mod h1:jUCi3VgMmxMxvVsKNr3TUMgW03ZGyuLrifDsIsKqcAE=
sigs.k8s.io/karpenter v1.3.4-0.20251001203658-9331efba088c h1:8BL5eQ5/IoIInY8bjzvPIVAZ85o7QgqUncxbw1kIx7w=
sigs.k8s.io/karpenter v1.3.4-0.20251001203658-9331efba088c/go.mod h1:VmPwMP8oRflG6+un1lkChJxbipdWZKpgtjyXICV0FgA=
sigs.k8s.io/structured-merge-diff/v4 v4.4.2 h1:MdmvkGuXi/8io6ixD5wud3vOLwc1rj0aNqRlpuvjmwA=
sigs.k8s.io/structured-merge-diff/v4 v4.4.2/go.mod h1:N8f93tFZh9U6vpxwRArLiikrE5/2tiu1w1AGfACIGE4=
sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E=
Expand Down
5 changes: 4 additions & 1 deletion hack/toolchain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ main() {

tools() {
go install github.com/google/go-licenses@latest
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
# asciicheck is a dependency of golangci-lint that got removed so golangci changed their go.mod to use the forked version
# fix - https://github.com/golangci/golangci-lint/issues/6017
# change to latest once golangci releases new version with the fix
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@main
go install github.com/google/ko@latest
go install github.com/mikefarah/yq/v4@latest
go install github.com/norwoodj/helm-docs/cmd/helm-docs@latest
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/crds/karpenter.sh_nodeclaims.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.18.0
controller-gen.kubebuilder.io/version: v0.19.0
name: nodeclaims.karpenter.sh
spec:
group: karpenter.sh
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/crds/karpenter.sh_nodepools.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.18.0
controller-gen.kubebuilder.io/version: v0.19.0
name: nodepools.karpenter.sh
spec:
group: karpenter.sh
Expand Down
16 changes: 8 additions & 8 deletions pkg/cloudprovider/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,15 +275,15 @@ var _ = Describe("CloudProvider", func() {
cloudProviderNodeClaim, err := cloudProvider.Create(ctx, nodeClaim)
Expect(err).To(BeNil())
Expect(cloudProviderNodeClaim).ToNot(BeNil())
_, ok := cloudProviderNodeClaim.ObjectMeta.Annotations[v1.AnnotationEC2NodeClassHash]
_, ok := cloudProviderNodeClaim.Annotations[v1.AnnotationEC2NodeClassHash]
Expect(ok).To(BeTrue())
})
It("should return NodeClass Hash Version on the nodeClaim", func() {
ExpectApplied(ctx, env.Client, nodePool, nodeClass, nodeClaim)
cloudProviderNodeClaim, err := cloudProvider.Create(ctx, nodeClaim)
Expect(err).To(BeNil())
Expect(cloudProviderNodeClaim).ToNot(BeNil())
v, ok := cloudProviderNodeClaim.ObjectMeta.Annotations[v1.AnnotationEC2NodeClassHashVersion]
v, ok := cloudProviderNodeClaim.Annotations[v1.AnnotationEC2NodeClassHashVersion]
Expect(ok).To(BeTrue())
Expect(v).To(Equal(v1.EC2NodeClassHashVersion))
})
Expand Down Expand Up @@ -1101,11 +1101,11 @@ var _ = Describe("CloudProvider", func() {
Expect(isDrifted).To(BeEmpty())
})
It("should not return drifted if the NodeClaim's karpenter.k8s.aws/ec2nodeclass-hash-version annotation does not match the EC2NodeClass's", func() {
nodeClass.ObjectMeta.Annotations = map[string]string{
nodeClass.Annotations = map[string]string{
v1.AnnotationEC2NodeClassHash: "test-hash-111111",
v1.AnnotationEC2NodeClassHashVersion: "test-hash-version-1",
}
nodeClaim.ObjectMeta.Annotations = map[string]string{
nodeClaim.Annotations = map[string]string{
v1.AnnotationEC2NodeClassHash: "test-hash-222222",
v1.AnnotationEC2NodeClassHashVersion: "test-hash-version-2",
}
Expand All @@ -1115,10 +1115,10 @@ var _ = Describe("CloudProvider", func() {
Expect(isDrifted).To(BeEmpty())
})
It("should not return drifted if karpenter.k8s.aws/ec2nodeclass-hash-version annotation is not present on the NodeClass", func() {
nodeClass.ObjectMeta.Annotations = map[string]string{
nodeClass.Annotations = map[string]string{
v1.AnnotationEC2NodeClassHash: "test-hash-111111",
}
nodeClaim.ObjectMeta.Annotations = map[string]string{
nodeClaim.Annotations = map[string]string{
v1.AnnotationEC2NodeClassHash: "test-hash-222222",
v1.AnnotationEC2NodeClassHashVersion: "test-hash-version-2",
}
Expand All @@ -1132,11 +1132,11 @@ var _ = Describe("CloudProvider", func() {
Expect(isDrifted).To(BeEmpty())
})
It("should not return drifted if karpenter.k8s.aws/ec2nodeclass-hash-version annotation is not present on the NodeClaim", func() {
nodeClass.ObjectMeta.Annotations = map[string]string{
nodeClass.Annotations = map[string]string{
v1.AnnotationEC2NodeClassHash: "test-hash-111111",
v1.AnnotationEC2NodeClassHashVersion: "test-hash-version-1",
}
nodeClaim.ObjectMeta.Annotations = map[string]string{
nodeClaim.Annotations = map[string]string{
v1.AnnotationEC2NodeClassHash: "test-hash-222222",
}
// should trigger drift
Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/nodeclass/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (v *Validation) Reconcile(ctx context.Context, nodeClass *v1.EC2NodeClass)
nodeClaim := &karpv1.NodeClaim{
Spec: karpv1.NodeClaimSpec{
NodeClassRef: &karpv1.NodeClassReference{
Name: nodeClass.ObjectMeta.Name,
Name: nodeClass.Name,
},
},
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/providers/amifamily/al2.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ func (a AL2) DescribeImageQuery(ctx context.Context, ssmProvider ssm.Provider, k
func (a AL2) UserData(kubeletConfig *v1.KubeletConfiguration, taints []corev1.Taint, labels map[string]string, caBundle *string, _ []*cloudprovider.InstanceType, customUserData *string, instanceStorePolicy *v1.InstanceStorePolicy) bootstrap.Bootstrapper {
return bootstrap.EKS{
Options: bootstrap.Options{
ClusterName: a.Options.ClusterName,
ClusterEndpoint: a.Options.ClusterEndpoint,
ClusterName: a.ClusterName,
ClusterEndpoint: a.ClusterEndpoint,
KubeletConfig: kubeletConfig,
Taints: taints,
Labels: labels,
Expand Down
6 changes: 3 additions & 3 deletions pkg/providers/amifamily/al2023.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ func (a AL2023) resolvePath(architecture, variant, k8sVersion, amiVersion string
func (a AL2023) UserData(kubeletConfig *v1.KubeletConfiguration, taints []corev1.Taint, labels map[string]string, caBundle *string, _ []*cloudprovider.InstanceType, customUserData *string, instanceStorePolicy *v1.InstanceStorePolicy) bootstrap.Bootstrapper {
return bootstrap.Nodeadm{
Options: bootstrap.Options{
ClusterName: a.Options.ClusterName,
ClusterEndpoint: a.Options.ClusterEndpoint,
ClusterCIDR: a.Options.ClusterCIDR,
ClusterName: a.ClusterName,
ClusterEndpoint: a.ClusterEndpoint,
ClusterCIDR: a.ClusterCIDR,
KubeletConfig: kubeletConfig,
Taints: taints,
Labels: labels,
Expand Down
2 changes: 1 addition & 1 deletion pkg/providers/amifamily/bootstrap/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ type Custom struct {
}

func (e Custom) Script() (string, error) {
return base64.StdEncoding.EncodeToString([]byte(aws.ToString(e.Options.CustomUserData))), nil
return base64.StdEncoding.EncodeToString([]byte(aws.ToString(e.CustomUserData))), nil
}
4 changes: 2 additions & 2 deletions pkg/providers/amifamily/bottlerocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ func (b Bottlerocket) DescribeImageQuery(ctx context.Context, ssmProvider ssm.Pr
func (b Bottlerocket) UserData(kubeletConfig *v1.KubeletConfiguration, taints []corev1.Taint, labels map[string]string, caBundle *string, _ []*cloudprovider.InstanceType, customUserData *string, instanceStorePolicy *v1.InstanceStorePolicy) bootstrap.Bootstrapper {
return bootstrap.Bottlerocket{
Options: bootstrap.Options{
ClusterName: b.Options.ClusterName,
ClusterEndpoint: b.Options.ClusterEndpoint,
ClusterName: b.ClusterName,
ClusterEndpoint: b.ClusterEndpoint,
KubeletConfig: kubeletConfig,
Taints: taints,
Labels: labels,
Expand Down
4 changes: 2 additions & 2 deletions pkg/providers/amifamily/windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ func (w Windows) DescribeImageQuery(ctx context.Context, ssmProvider ssm.Provide
func (w Windows) UserData(kubeletConfig *v1.KubeletConfiguration, taints []corev1.Taint, labels map[string]string, caBundle *string, _ []*cloudprovider.InstanceType, customUserData *string, _ *v1.InstanceStorePolicy) bootstrap.Bootstrapper {
return bootstrap.Windows{
Options: bootstrap.Options{
ClusterName: w.Options.ClusterName,
ClusterEndpoint: w.Options.ClusterEndpoint,
ClusterName: w.ClusterName,
ClusterEndpoint: w.ClusterEndpoint,
KubeletConfig: kubeletConfig,
Taints: taints,
Labels: labels,
Expand Down
4 changes: 2 additions & 2 deletions pkg/providers/launchtemplate/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2470,8 +2470,8 @@ func ExpectLaunchTemplatesCreatedWithUserData(expected string) {
userData, err := base64.StdEncoding.DecodeString(*input.LaunchTemplateData.UserData)
ExpectWithOffset(2, err).To(BeNil())
// Newlines are always added for missing TOML fields, so strip them out before comparisons.
actualUserData := strings.Replace(string(userData), "\n", "", -1)
expectedUserData := strings.Replace(expected, "\n", "", -1)
actualUserData := strings.ReplaceAll(string(userData), "\n", "")
expectedUserData := strings.ReplaceAll(expected, "\n", "")
ExpectWithOffset(2, actualUserData).To(Equal(expectedUserData))
})
}
Expand Down
4 changes: 2 additions & 2 deletions test/pkg/debug/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ func (c *NodeController) Reconcile(ctx context.Context, req reconcile.Request) (
n := &corev1.Node{}
if err := c.kubeClient.Get(ctx, req.NamespacedName, n); err != nil {
if errors.IsNotFound(err) {
fmt.Printf("[DELETED %s] NODE %s\n", time.Now().Format(time.RFC3339), req.NamespacedName.String())
fmt.Printf("[DELETED %s] NODE %s\n", time.Now().Format(time.RFC3339), req.String())
}
return reconcile.Result{}, client.IgnoreNotFound(err)
}
fmt.Printf("[CREATED/UPDATED %s] NODE %s %s\n", time.Now().Format(time.RFC3339), req.NamespacedName.Name, c.GetInfo(ctx, n))
fmt.Printf("[CREATED/UPDATED %s] NODE %s %s\n", time.Now().Format(time.RFC3339), req.Name, c.GetInfo(ctx, n))
return reconcile.Result{}, nil
}

Expand Down
4 changes: 2 additions & 2 deletions test/pkg/debug/nodeclaim.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ func (c *NodeClaimController) Reconcile(ctx context.Context, req reconcile.Reque
nc := &karpv1.NodeClaim{}
if err := c.kubeClient.Get(ctx, req.NamespacedName, nc); err != nil {
if errors.IsNotFound(err) {
fmt.Printf("[DELETED %s] NODECLAIM %s\n", time.Now().Format(time.RFC3339), req.NamespacedName.String())
fmt.Printf("[DELETED %s] NODECLAIM %s\n", time.Now().Format(time.RFC3339), req.String())
}
return reconcile.Result{}, client.IgnoreNotFound(err)
}
fmt.Printf("[CREATED/UPDATED %s] NODECLAIM %s %s\n", time.Now().Format(time.RFC3339), req.NamespacedName.Name, c.GetInfo(nc))
fmt.Printf("[CREATED/UPDATED %s] NODECLAIM %s %s\n", time.Now().Format(time.RFC3339), req.Name, c.GetInfo(nc))
return reconcile.Result{}, nil
}

Expand Down
4 changes: 2 additions & 2 deletions test/pkg/debug/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ func (c *PodController) Reconcile(ctx context.Context, req reconcile.Request) (r
p := &corev1.Pod{}
if err := c.kubeClient.Get(ctx, req.NamespacedName, p); err != nil {
if errors.IsNotFound(err) {
fmt.Printf("[DELETED %s] POD %s\n", time.Now().Format(time.RFC3339), req.NamespacedName.String())
fmt.Printf("[DELETED %s] POD %s\n", time.Now().Format(time.RFC3339), req.String())
}
return reconcile.Result{}, client.IgnoreNotFound(err)
}
fmt.Printf("[CREATED/UPDATED %s] POD %s %s\n", time.Now().Format(time.RFC3339), req.NamespacedName.String(), c.GetInfo(p))
fmt.Printf("[CREATED/UPDATED %s] POD %s %s\n", time.Now().Format(time.RFC3339), req.String(), c.GetInfo(p))
return reconcile.Result{}, nil
}

Expand Down
Loading
Loading