Skip to content
Open
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
7 changes: 7 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ linters:
- govet
- ineffassign
- misspell
- modernize
- revive
- staticcheck
- unused
Expand Down Expand Up @@ -74,6 +75,12 @@ linters:

# tab width in spaces. Default to 1.
tab-width: 1
modernize:
disable:
- any
- stringsbuilder
- omitzero
- waitgroup
nakedret:
# make an issue if func has more lines of code than this setting and it has naked returns; default is 30
max-func-lines: 30
Expand Down
8 changes: 3 additions & 5 deletions cmd/ec2geninfo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"
"regexp"
"slices"
"text/template"

"github.com/aws/aws-sdk-go-v2/aws"
Expand Down Expand Up @@ -157,11 +158,8 @@ func getEC2Instances(region string, instances map[string]InstanceInfo) (map[stri

cbrSupported := false
if inst.SupportedUsageClasses != nil {
for _, usageClass := range inst.SupportedUsageClasses {
if usageClass == types.UsageClassTypeCapacityBlock {
cbrSupported = true
break
}
if slices.Contains(inst.SupportedUsageClasses, types.UsageClassTypeCapacityBlock) {
cbrSupported = true
}
}

Expand Down
4 changes: 2 additions & 2 deletions integration/tests/crud/creategetdelete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,8 +492,8 @@ var _ = Describe("(Integration) Create, Get, Scale & Delete", func() {
Expect(js).To(ContainElement(HavePrefix("AWS_SESSION_OBJECT=")))

for _, envVar := range js {
if strings.HasPrefix(envVar, "AWS_SESSION_OBJECT=") {
err := json.Unmarshal([]byte(strings.TrimPrefix(envVar, "AWS_SESSION_OBJECT=")), &so)
if after, ok := strings.CutPrefix(envVar, "AWS_SESSION_OBJECT="); ok {
err := json.Unmarshal([]byte(after), &so)
Expect(err).ShouldNot(HaveOccurred())
}
}
Expand Down
2 changes: 1 addition & 1 deletion integration/tests/dry_run/dry_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ var _ = Describe("(Integration) [Dry-Run test]", func() {
parseOutput := func(output []byte) (*api.ClusterConfig, *api.ClusterConfig) {
actual, err := eks.ParseConfig(output)
Expect(err).NotTo(HaveOccurred())
defaultConfig, err := eks.ParseConfig([]byte(fmt.Sprintf(defaultClusterConfig, params.ClusterName)))
defaultConfig, err := eks.ParseConfig(fmt.Appendf(nil, defaultClusterConfig, params.ClusterName))
Expect(err).NotTo(HaveOccurred())
return actual, defaultConfig
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/actions/accessentry/creator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@ var _ = Describe("Access Entry", func() {
s.CreateStackStub = func(ctx context.Context, stackName string, r builder.ResourceSetReader, tags map[string]string, parameters map[string]string, errorCh chan error) error {
defer close(errorCh)
prefix := fmt.Sprintf("eksctl-%s-accessentry-", ae.clusterName)
idx := strings.Index(stackName, prefix)
if idx < 0 {
_, suffix, ok := strings.Cut(stackName, prefix)
if !ok {
return fmt.Errorf("expected stack name to have prefix %q", prefix)
}
suffix := stackName[idx+len(prefix):]
_, err := base32.StdEncoding.WithPadding(base32.NoPadding).DecodeString(suffix)
if err != nil {
return fmt.Errorf("expected stack name to have a base32-encoded suffix: %w", err)
Expand Down
5 changes: 2 additions & 3 deletions pkg/actions/accessentry/migrator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,10 @@ var _ = Describe("Migrate Access Entry", func() {
s.CreateStackStub = func(ctx context.Context, stackName string, r builder.ResourceSetReader, tags map[string]string, parameters map[string]string, errorCh chan error) error {
defer close(errorCh)
prefix := fmt.Sprintf("eksctl-%s-accessentry-", clusterName)
idx := strings.Index(stackName, prefix)
if idx < 0 {
_, suffix, ok := strings.Cut(stackName, prefix)
if !ok {
return fmt.Errorf("expected stack name to have prefix %q", prefix)
}
suffix := stackName[idx+len(prefix):]
_, err := base32.StdEncoding.WithPadding(base32.NoPadding).DecodeString(suffix)
if err != nil {
return fmt.Errorf("expected stack name to have a base32-encoded suffix: %w", err)
Expand Down
4 changes: 2 additions & 2 deletions pkg/actions/addon/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ func (a *Manager) patchAWSNodeSA(ctx context.Context) error {
return nil
}

_, err = serviceAccounts.Patch(ctx, "aws-node", types.JSONPatchType, []byte(fmt.Sprintf(`[{"op": "remove", "path": "/metadata/managedFields/%d"}]`, managerIndex)), metav1.PatchOptions{})
_, err = serviceAccounts.Patch(ctx, "aws-node", types.JSONPatchType, fmt.Appendf(nil, `[{"op": "remove", "path": "/metadata/managedFields/%d"}]`, managerIndex), metav1.PatchOptions{})
if err != nil {
return fmt.Errorf("failed to patch sa: %w", err)
}
Expand Down Expand Up @@ -387,7 +387,7 @@ func (a *Manager) patchAWSNodeDaemonSet(ctx context.Context) error {
}
}

_, err = daemonSets.Patch(ctx, "aws-node", types.JSONPatchType, []byte(fmt.Sprintf(`[{"op": "remove", "path": "/metadata/managedFields/%d"}]`, managerIndex)), metav1.PatchOptions{})
_, err = daemonSets.Patch(ctx, "aws-node", types.JSONPatchType, fmt.Appendf(nil, `[{"op": "remove", "path": "/metadata/managedFields/%d"}]`, managerIndex), metav1.PatchOptions{})
if err != nil {
return fmt.Errorf("failed to patch daemon set: %w", err)
}
Expand Down
7 changes: 3 additions & 4 deletions pkg/actions/anywhere/anywhere.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"
"os/exec"
"slices"

"github.com/weaveworks/eksctl/pkg/version"
)
Expand All @@ -26,10 +27,8 @@ func IsAnywhereCommand(args []string) (bool, error) {

// if they have any args/flags before the anywhere command we should error
// e.g. eksctl --foo=bar anywhere should error
for _, arg := range args {
if arg == "anywhere" {
return false, fmt.Errorf("flags cannot be placed before the anywhere command")
}
if slices.Contains(args, "anywhere") {
return false, fmt.Errorf("flags cannot be placed before the anywhere command")
}

return false, nil
Expand Down
9 changes: 3 additions & 6 deletions pkg/actions/capability/creator.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/base32"
"errors"
"fmt"
"maps"
"strings"
"time"

Expand Down Expand Up @@ -128,9 +129,7 @@ func (c *Creator) createCapabilityStack(ctx context.Context, capability *api.Cap
api.ClusterNameTag: c.clusterName,
api.CapabilityNameTag: capability.Name,
}
for k, v := range capability.Tags {
tags[k] = v
}
maps.Copy(tags, capability.Tags)
if err := c.stackCreator.CreateStack(ctx, stackName, rs, tags, nil, stackErrCh); err != nil {
return err
}
Expand All @@ -154,9 +153,7 @@ func (c *Creator) createIAMRoleStack(ctx context.Context, capability *api.Capabi
api.CapabilityIAMRoleTag: capability.Name,
}

for k, v := range capability.Tags {
tags[k] = v
}
maps.Copy(tags, capability.Tags)

stackCh := make(chan error)
if err := c.stackCreator.CreateStack(ctx, stackName, rs, tags, nil, stackCh); err != nil {
Expand Down
8 changes: 2 additions & 6 deletions pkg/actions/karpenter/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"net"
"slices"

awseks "github.com/aws/aws-sdk-go-v2/service/eks"
ekstypes "github.com/aws/aws-sdk-go-v2/service/eks/types"
Expand Down Expand Up @@ -451,12 +452,7 @@ var _ = Describe("Create", func() {
Cluster: fakeCluster,
}, nil)
p.MockEC2().On("CreateTags", mock.Anything, mock.MatchedBy(func(input *ec2.CreateTagsInput) bool {
for _, r := range input.Resources {
if r == "sg-cluster-1234" {
return true
}
}
return false
return slices.Contains(input.Resources, "sg-cluster-1234")
})).Return(nil, errors.New("tag failed"))
})
It("errors", func() {
Expand Down
1 change: 0 additions & 1 deletion pkg/actions/nodegroup/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ var _ = Describe("Delete", func() {
deleteNgTaskRuns atomic.Uint32
)
for _, stack := range dt.stacks {
stack := stack
deleteNgTasks = append(deleteNgTasks, &taskfakes.FakeTask{
DescribeStub: func() string {
return "delete " + stack.NodeGroupName
Expand Down
1 change: 0 additions & 1 deletion pkg/actions/nodegroup/drain.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ func (d *Drainer) Drain(ctx context.Context, input *DrainInput) error {

g, ctx := errgroup.WithContext(ctx)
for _, nodegroup := range input.NodeGroups {
nodegroup := nodegroup
g.Go(func() error {
nodeGroupDrainer := drain.NewNodeGroupDrainer(d.ClientSet, nodegroup, input.MaxGracePeriod, input.NodeDrainWaitPeriod, input.PodEvictionWaitPeriod, input.Undo, input.DisableEviction, input.Parallel)
return nodeGroupDrainer.Drain(ctx, sem)
Expand Down
1 change: 0 additions & 1 deletion pkg/actions/podidentityassociation/creator.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ func (c *Creator) CreateTasks(ctx context.Context, podIdentityAssociations []api
Parallel: true,
}
for _, pia := range podIdentityAssociations {
pia := pia
piaCreationTasks := &tasks.TaskTree{
Parallel: false,
IsSubTask: true,
Expand Down
1 change: 0 additions & 1 deletion pkg/actions/podidentityassociation/deleter.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ func (d *Deleter) DeleteTasks(ctx context.Context, podIDs []Identifier) (*tasks.
}

for _, podID := range podIDs {
podID := podID
piaDeletionTasks := &tasks.TaskTree{
Parallel: false,
IsSubTask: true,
Expand Down
7 changes: 3 additions & 4 deletions pkg/addons/default/addons.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package defaultaddons
import (
"context"
"fmt"
"slices"

"github.com/aws/aws-sdk-go-v2/service/eks"

Expand Down Expand Up @@ -66,10 +67,8 @@ func supportsMultiArch(podSec corev1.PodSpec) bool {
for _, nodeSelectorTerm := range podSec.Affinity.NodeAffinity.RequiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms {
for _, me := range nodeSelectorTerm.MatchExpressions {
if me.Key == corev1.LabelArchStable && me.Operator == corev1.NodeSelectorOpIn {
for _, val := range me.Values {
if val == "arm64" {
return true
}
if slices.Contains(me.Values, "arm64") {
return true
}
}
}
Expand Down
18 changes: 7 additions & 11 deletions pkg/apis/eksctl.io/v1alpha5/nodegroups.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package v1alpha5

import "fmt"
import (
"fmt"
"slices"
)

// HasInstanceType returns whether some node in the group fulfils the type check
func HasInstanceType(nodeGroup *NodeGroup, hasType func(string) bool) bool {
if hasType(nodeGroup.InstanceType) {
return true
}
if nodeGroup.InstancesDistribution != nil {
for _, instanceType := range nodeGroup.InstancesDistribution.InstanceTypes {
if hasType(instanceType) {
return true
}
if slices.ContainsFunc(nodeGroup.InstancesDistribution.InstanceTypes, hasType) {
return true
}
}
return false
Expand All @@ -22,12 +23,7 @@ func HasInstanceTypeManaged(nodeGroup *ManagedNodeGroup, hasType func(string) bo
if hasType(nodeGroup.InstanceType) {
return true
}
for _, instanceType := range nodeGroup.InstanceTypes {
if hasType(instanceType) {
return true
}
}
return false
return slices.ContainsFunc(nodeGroup.InstanceTypes, hasType)
}

// ClusterHasInstanceType checks all nodegroups and managed nodegroups for a specific instance type
Expand Down
11 changes: 6 additions & 5 deletions pkg/apis/eksctl.io/v1alpha5/partitions.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package v1alpha5

import "fmt"
import (
"fmt"
"slices"
)

// Partitions.
const (
Expand Down Expand Up @@ -153,10 +156,8 @@ var Partitions = partitions{

func (p partitions) partitionFromRegion(region string) *partition {
for _, pt := range p {
for _, r := range pt.regions {
if r == region {
return &pt
}
if slices.Contains(pt.regions, region) {
return &pt
}
}
return nil
Expand Down
7 changes: 3 additions & 4 deletions pkg/apis/eksctl.io/v1alpha5/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"encoding/json"
"errors"
"fmt"
"slices"
"strings"
"time"

Expand Down Expand Up @@ -1214,10 +1215,8 @@ func NewClusterIAM() *ClusterIAM {

// AppendAvailabilityZone appends a new AZ to the set
func (c *ClusterConfig) AppendAvailabilityZone(newAZ string) {
for _, az := range c.AvailabilityZones {
if az == newAZ {
return
}
if slices.Contains(c.AvailabilityZones, newAZ) {
return
}
c.AvailabilityZones = append(c.AvailabilityZones, newAZ)
}
Expand Down
22 changes: 4 additions & 18 deletions pkg/apis/eksctl.io/v1alpha5/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,10 +385,8 @@ func validateCloudWatchLogging(clusterConfig *ClusterConfig) error {
}
}
if logRetentionDays := clusterConfig.CloudWatch.ClusterLogging.LogRetentionInDays; logRetentionDays != 0 {
for _, v := range LogRetentionInDaysValues {
if v == logRetentionDays {
return nil
}
if slices.Contains(LogRetentionInDaysValues, logRetentionDays) {
return nil
}
return fmt.Errorf("invalid value %d for logRetentionInDays; supported values are %v", logRetentionDays, LogRetentionInDaysValues)
}
Expand Down Expand Up @@ -468,14 +466,7 @@ func (c *ClusterConfig) ValidateVPCConfig() error {
return errors.New("vpc.hostnameType is not supported with a pre-existing VPC")
}
var hostnameType ec2types.HostnameType
found := false
for _, h := range hostnameType.Values() {
if h == ec2types.HostnameType(c.VPC.HostnameType) {
found = true
break
}
}
if !found {
if !slices.Contains(hostnameType.Values(), ec2types.HostnameType(c.VPC.HostnameType)) {
return fmt.Errorf("invalid value %q for vpc.hostnameType; supported values are %v", c.VPC.HostnameType, hostnameType.Values())
}
}
Expand Down Expand Up @@ -1614,12 +1605,7 @@ func validateNodeGroupKubeletExtraConfig(kubeletConfig *InlineDocument) error {
}

func isSupportedAMIFamily(imageFamily string) bool {
for _, image := range SupportedAMIFamilies() {
if imageFamily == image {
return true
}
}
return false
return slices.Contains(SupportedAMIFamilies(), imageFamily)
}

func supportedAMIFamiliesForOS(isOSImage func(string) bool) []string {
Expand Down
8 changes: 4 additions & 4 deletions pkg/az/az.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import (
"context"
"fmt"
"math/rand"
gostrings "strings"
"slices"
"strings"
"time"

"github.com/aws/aws-sdk-go-v2/aws"
Expand All @@ -15,7 +16,6 @@ import (
api "github.com/weaveworks/eksctl/pkg/apis/eksctl.io/v1alpha5"
"github.com/weaveworks/eksctl/pkg/awsapi"
"github.com/weaveworks/eksctl/pkg/utils/nodes"
"github.com/weaveworks/eksctl/pkg/utils/strings"
)

var zoneIDsToAvoid = map[string][]string{
Expand Down Expand Up @@ -115,7 +115,7 @@ func FilterBasedOnAvailability(ctx context.Context, zones []string, np []api.Nod
if len(noSupport) == 0 {
filteredList = append(filteredList, zone)
} else {
logger.Info("skipping %s from selection because it doesn't support the following instance type(s): %s", zone, gostrings.Join(noSupport, ","))
logger.Info("skipping %s from selection because it doesn't support the following instance type(s): %s", zone, strings.Join(noSupport, ","))
}
}
return filteredList, nil
Expand Down Expand Up @@ -162,7 +162,7 @@ func filterZones(region string, zones []ec2types.AvailabilityZone) []string {
var filteredZones []string
azsToAvoid := zoneIDsToAvoid[region]
for _, z := range zones {
if !strings.Contains(azsToAvoid, *z.ZoneId) {
if !slices.Contains(azsToAvoid, *z.ZoneId) {
filteredZones = append(filteredZones, *z.ZoneName)
}
}
Expand Down
Loading
Loading