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
47 changes: 47 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: codeql

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
schedule:
- cron: '16 16 * * 4'

jobs:
analyze:
name: Analyze (${{ matrix.language }})
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
permissions:
security-events: write
packages: read
actions: read
contents: read

strategy:
fail-fast: false
matrix:
include:
- language: actions
build-mode: none
- language: go
build-mode: autobuild
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Go 1.x
uses: actions/setup-go@v5
with:
go-version: 1.24

- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
build-mode: ${{ matrix.build-mode }}

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{matrix.language}}"
43 changes: 43 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: golangci-lint
permissions:
contents: read
pull-requests: write

on:
pull_request:
push:
branches: [ "master" ]

env:
GO_VERSION: stable
GOLANGCI_LINT_VERSION: v2.1.1

jobs:
detect-modules:
runs-on: ubuntu-latest
outputs:
modules: ${{ steps.set-modules.outputs.modules }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- id: set-modules
run: echo "modules=$(go list -m -json | jq -s '.' | jq -c '[.[].Dir]')" >> $GITHUB_OUTPUT

golangci-lint:
needs: detect-modules
runs-on: ubuntu-latest
strategy:
matrix:
modules: ${{ fromJSON(needs.detect-modules.outputs.modules) }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- name: golangci-lint ${{ matrix.modules }}
uses: golangci/golangci-lint-action@v7
with:
version: ${{ env.GOLANGCI_LINT_VERSION }}
working-directory: ${{ matrix.modules }}
16 changes: 8 additions & 8 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push:
branches: [ master ]
tags:
- '*'
- "v*.*.*"

jobs:
push:
Expand All @@ -21,12 +21,6 @@ jobs:
with:
go-version: 1.24

- name: Run golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.55.2
args: --timeout=3m

- name: Test
run: |
make test
Expand Down Expand Up @@ -65,12 +59,18 @@ jobs:
uses: docker/metadata-action@v5
with:
images: ${{ github.repository_owner }}/instance-manager,ghcr.io/${{ github.repository_owner }}/instance-manager
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}

-
name: Build and push
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm/v7,linux/arm64
push: true
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.docker_meta.outputs.tags }}
14 changes: 0 additions & 14 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,9 @@ jobs:
- name: Check out code into the Go module directory
uses: actions/checkout@v4

- name: Run golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.64.8
args: --timeout=3m

- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: go

- name: Build
run: |
make manager

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3

- name: Test
run: |
Expand Down
24 changes: 19 additions & 5 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
---
version: "2"
linters:
enable:
- govet
- gosimple
- ineffassign
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
paths:
- third_party$
- builtin$
- examples$
formatters:
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
12 changes: 9 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ all: check-go lint test clean manager

# Run tests
.PHONY: test
test: generate fmt vet manifests lint
test: generate fmt vet manifests
go test ./controllers/... ./api/... -coverprofile coverage.txt

.PHONY: bdd
Expand Down Expand Up @@ -117,16 +117,22 @@ controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessar
$(CONTROLLER_GEN): $(LOCALBIN)
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_GEN_VERSION)

GOLANGCI_LINT_VERSION := v2.1.1
GOLANGCI_LINT = $(shell pwd)/bin/golangci-lint
.PHONY: golangci-lint
$(GOLANGCI_LINT): $(LOCALBIN)
GOBIN=$(LOCALBIN) go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)

.PHONY: check-go
check-go:
ifeq ($(GO_VERSION_CHECK),0)
$(error go 1.20 or higher is required)
endif

.PHONY: lint
lint: check-go
lint: check-go $(GOLANGCI_LINT)
@echo "Running golangci-lint"
golangci-lint run ./...
$(GOLANGCI_LINT) run ./...

.PHONY: clean
clean:
Expand Down
13 changes: 6 additions & 7 deletions controllers/instancegroup_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,12 @@ const (

func (r *InstanceGroupReconciler) Finalize(instanceGroup *v1alpha1.InstanceGroup) {
// Resource is being deleted
meta := &instanceGroup.ObjectMeta
deletionTimestamp := meta.GetDeletionTimestamp()
deletionTimestamp := instanceGroup.DeletionTimestamp
if !deletionTimestamp.IsZero() {
// And state is "Deleted"
if instanceGroup.GetState() == v1alpha1.ReconcileDeleted {
// remove all finalizers
meta.SetFinalizers([]string{})
instanceGroup.Finalizers = []string{}
if err := r.Update(context.Background(), instanceGroup); err != nil {
// avoid update errors for already deleted resources
if kubeprovider.IsStorageError(err) {
Expand All @@ -95,11 +94,11 @@ func (r *InstanceGroupReconciler) Finalize(instanceGroup *v1alpha1.InstanceGroup

func (r *InstanceGroupReconciler) SetFinalizer(instanceGroup *v1alpha1.InstanceGroup) {
// Resource is not being deleted
if instanceGroup.ObjectMeta.DeletionTimestamp.IsZero() {
if instanceGroup.DeletionTimestamp.IsZero() {
// And does not contain finalizer
if !common.ContainsString(instanceGroup.ObjectMeta.Finalizers, FinalizerStr) {
if !common.ContainsString(instanceGroup.Finalizers, FinalizerStr) {
// Set Finalizer
instanceGroup.ObjectMeta.Finalizers = append(instanceGroup.ObjectMeta.Finalizers, FinalizerStr)
instanceGroup.Finalizers = append(instanceGroup.Finalizers, FinalizerStr)
if err := r.Update(context.Background(), instanceGroup); err != nil {
r.Log.Error(err, "failed to update custom resource")
}
Expand Down Expand Up @@ -127,7 +126,7 @@ func (r *InstanceGroupReconciler) Reconcile(ctxt context.Context, req ctrl.Reque
return ctrl.Result{}, nil
}
r.Log.Error(err, "reconcile failed", "instancegroup", req.NamespacedName)
r.Metrics.IncFail(req.NamespacedName.String(), ErrorReasonGetFailed)
r.Metrics.IncFail(req.String(), ErrorReasonGetFailed)
return ctrl.Result{}, err
}
statusPatch := kubeprovider.MergePatch(*instanceGroup)
Expand Down
12 changes: 5 additions & 7 deletions controllers/providers/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,8 @@ type AwsWorker struct {
}

func (w *AwsWorker) WithRetries(f func() bool) error {
var counter int
for {
if counter >= DefaultWaiterRetries {
break
}
counter := 0
for counter < DefaultWaiterRetries {
if f() {
return nil
}
Expand All @@ -145,9 +142,10 @@ func (w *AwsWorker) compactTags(tags []map[string]string) map[string]string {
value string
)
for t, v := range tagSet {
if t == "key" {
switch t {
case "key":
key = v
} else if t == "value" {
case "value":
value = v
}
}
Expand Down
6 changes: 3 additions & 3 deletions controllers/providers/aws/eks.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,16 @@ func (w *AwsWorker) DescribeEKSCluster(clusterName string) (*eks.Cluster, error)
}

// TODO: Rename - GetNodeGroup
func (w *AwsWorker) GetSelfNodeGroup() (error, *eks.Nodegroup) {
func (w *AwsWorker) GetSelfNodeGroup() (*eks.Nodegroup, error) {
input := &eks.DescribeNodegroupInput{
ClusterName: aws.String(w.Parameters["ClusterName"].(string)),
NodegroupName: aws.String(w.Parameters["NodegroupName"].(string)),
}
output, err := w.EksClient.DescribeNodegroup(input)
if err != nil {
return err, &eks.Nodegroup{}
return &eks.Nodegroup{}, err
}
return nil, output.Nodegroup
return output.Nodegroup, nil
}

func (w *AwsWorker) DeleteManagedNodeGroup() error {
Expand Down
4 changes: 2 additions & 2 deletions controllers/provisioners/eks/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -1236,7 +1236,7 @@ func (ctx *EksInstanceGroupContext) GetEksLatestAmi() (string, error) {
supportedArchitectures := awsprovider.GetInstanceTypeArchitectures(state.GetInstanceTypeInfo(), configuration.InstanceType)
arch := FilterSupportedArch(supportedArchitectures)
if arch == "" {
return "", fmt.Errorf("No supported CPU architecture found for instance type %s", configuration.InstanceType)
return "", fmt.Errorf("no supported CPU architecture found for instance type %s", configuration.InstanceType)
}

return ctx.AwsWorker.GetEksLatestAmi(OSFamily, arch, clusterVersion)
Expand All @@ -1254,7 +1254,7 @@ func (ctx *EksInstanceGroupContext) GetEksSsmAmi(id string) (string, error) {
supportedArchitectures := awsprovider.GetInstanceTypeArchitectures(state.GetInstanceTypeInfo(), configuration.InstanceType)
arch := FilterSupportedArch(supportedArchitectures)
if arch == "" {
return "", fmt.Errorf("No supported CPU architecture found for instance type %s", configuration.InstanceType)
return "", fmt.Errorf("no supported CPU architecture found for instance type %s", configuration.InstanceType)
}

return ctx.AwsWorker.GetEksSsmAmi(osFamily, arch, clusterVersion, id)
Expand Down
2 changes: 1 addition & 1 deletion controllers/provisioners/eks/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1272,7 +1272,7 @@ func TestGetEksLatestAmi(t *testing.T) {
name: "AmazonLinux2-noarch",
OSFamily: "amazonlinux2",
arch: "noarch",
expectedError: fmt.Errorf("No supported CPU architecture found for instance type %s", instanceType),
expectedError: fmt.Errorf("no supported CPU architecture found for instance type %s", instanceType),
},
}

Expand Down
2 changes: 1 addition & 1 deletion controllers/provisioners/eks/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (ctx *EksInstanceGroupContext) StateDiscovery() {
}

var deleted bool
if !ctx.InstanceGroup.ObjectMeta.DeletionTimestamp.IsZero() {
if !ctx.InstanceGroup.DeletionTimestamp.IsZero() {
deleted = true
}

Expand Down
2 changes: 1 addition & 1 deletion controllers/provisioners/eksfargate/eksfargate.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ func (ctx *FargateInstanceGroupContext) StateDiscovery() {
instanceGroup := ctx.GetInstanceGroup()
if instanceGroup.GetState() == v1alpha1.ReconcileInit {

if instanceGroup.ObjectMeta.DeletionTimestamp.IsZero() {
if instanceGroup.GetObjectMeta().GetDeletionTimestamp().IsZero() {
if ctx.GetDiscoveredState().IsProvisioned() {
// Role exists and the Profile exists in some form (creating)
if awsprovider.IsProfileInConditionState(ctx.GetDiscoveredState().GetProfileStatus(), OngoingStateString) {
Expand Down
Loading
Loading