Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit d4f116b

Browse files
authored
Merge pull request #7 from PatrickLaabs/6
✨ overall refactoring and linter fixes
2 parents 320a371 + 7247e9f commit d4f116b

File tree

807 files changed

+64271
-3595
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

807 files changed

+64271
-3595
lines changed

.github/workflows/golangci-lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ jobs:
2727
- name: golangci-lint
2828
uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # tag=v8.0.0
2929
with:
30-
version: v1.61.0
30+
version: v2.1.0
3131
working-directory: ${{matrix.working-directory}}
3232
args: --timeout=5m

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,7 @@ _artifacts
3737
`
3838

3939
# Temp files
40-
tmp/
40+
tmp/
41+
42+
# Release Files
43+
out/

.golangci.bck.yaml

Lines changed: 0 additions & 138 deletions
This file was deleted.

Dockerfile

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ ARG ARCH
2828
# It's an invalid finding since the image is explicitly set in the Makefile.
2929
# https://github.com/hadolint/hadolint/wiki/DL3006
3030
# hadolint ignore=DL3006
31-
FROM ${builder_image} as builder
31+
FROM ${builder_image} AS builder
3232
WORKDIR /workspace
3333

3434
# Run this with docker build --build-arg goproxy=$(go env GOPROXY) to override the goproxy
@@ -71,34 +71,31 @@ RUN --mount=type=cache,target=/root/.cache/go-build \
7171
# Production image
7272
FROM ${deployment_base_image}:${deployment_base_image_tag}
7373

74+
# Set shell with pipefail option for better error handling
75+
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
76+
7477
# Install Node.js and cdk8s-cli directly
78+
# hadolint ignore=DL3015
7579
RUN apt-get update && \
76-
apt-get install -y ca-certificates curl wget && \
80+
apt-get install -y --no-install-recommends ca-certificates=20240203~22.04.1 curl=7.81.0-1ubuntu1.20 && \
7781
curl -fsSL https://deb.nodesource.com/setup_18.x | bash - && \
78-
apt-get install -y nodejs && \
79-
npm install -g cdk8s-cli && \
80-
wget https://go.dev/dl/go1.21.5.linux-amd64.tar.gz && \
81-
tar -C /usr/local -xzf go1.21.5.linux-amd64.tar.gz && \
82-
rm go1.21.5.linux-amd64.tar.gz && \
82+
apt-get install -y nodejs=18.19.1-1nodesource1 && \
83+
npm install -g cdk8s-cli@2.200.97 && \
84+
curl -fsSL -o go1.24.4.linux-amd64.tar.gz https://go.dev/dl/go1.24.4.linux-amd64.tar.gz && \
85+
tar -C /usr/local -xzf go1.24.4.linux-amd64.tar.gz && \
86+
rm go1.24.4.linux-amd64.tar.gz && \
8387
apt-get clean && \
8488
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
8589

86-
# Set Go environment variables
90+
# Set Go environment variables
8791
ENV PATH=$PATH:/usr/local/go/bin
8892
ENV GOROOT=/usr/local/go
8993

90-
RUN cdk8s --version && go version
91-
9294
WORKDIR /
9395
COPY --from=builder /workspace/manager .
9496

9597
# Create non-root user
9698
RUN useradd --uid 65532 --create-home --shell /bin/bash nonroot
97-
98-
# Ensure the non-root user can access Go by setting up their environment
99-
RUN echo 'export PATH=$PATH:/usr/local/go/bin' >> /home/nonroot/.bashrc && \
100-
echo 'export GOROOT=/usr/local/go' >> /home/nonroot/.bashrc && \
101-
echo 'export PATH=$PATH:/usr/local/go/bin' >> /home/nonroot/.profile
10299

103100
# Switch back to non-root user (this line should already exist)
104101
# USER root # This was part of the removed direct install, ensure it's not re-added here unless needed for COPY permissions

Makefile

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ export GO111MODULE=on
4545
# Base docker images
4646

4747
DOCKERFILE_CONTAINER_IMAGE ?= docker.io/docker/dockerfile:1.4
48-
# DEPLOYMENT_BASE_IMAGE ?= gcr.io/distroless/static
49-
# DEPLOYMENT_BASE_IMAGE_TAG ?= nonroot-${ARCH}
5048
DEPLOYMENT_BASE_IMAGE ?= ubuntu
5149
DEPLOYMENT_BASE_IMAGE_TAG ?= 22.04
5250
BUILD_CONTAINER_ADDITIONAL_ARGS ?=
@@ -220,7 +218,7 @@ endif
220218

221219
PROD_REGISTRY ?= ghcr.io/patricklaabs/cluster-api-addon-provider-cdk8s
222220

223-
STAGING_REGISTRY ?= ghcr.io/patricklaabs/k8s-staging-cluster-api-cdk8s
221+
STAGING_REGISTRY ?= ghcr.io/patricklaabs/cluster-api-addon-provider-cdk8s
224222
STAGING_BUCKET ?= artifacts.k8s-staging-cluster-api-cdk8s.appspot.com
225223

226224
# core
@@ -232,7 +230,7 @@ CAPI_KIND_CLUSTER_NAME ?= capi-test
232230

233231
# It is set by Prow GIT_TAG, a git-based tag of the form vYYYYMMDD-hash, e.g., v20210120-v0.3.10-308-gc61521971
234232

235-
TAG ?= v0.2.4-alpha
233+
TAG ?= v0.2.11-preview
236234
ARCH ?= $(shell go env GOARCH)
237235
ALL_ARCH = amd64 arm arm64
238236

@@ -594,7 +592,7 @@ release-staging: ## Build and push container images to the staging bucket
594592
REGISTRY=$(STAGING_REGISTRY) $(MAKE) docker-build-all docker-push-all release-alias-tag
595593

596594
.PHONY: release-staging-nightly
597-
release-staging-nightly: ## Tag and push container images to the staging bucket. Example image tag: cluster-api-helm-controller:nightly_main_20210121
595+
release-staging-nightly: ## Tag and push container images to the staging bucket. Example image tag: cluster-api-cdk8s-controller:nightly_main_20210121
598596
$(eval NEW_RELEASE_ALIAS_TAG := nightly_$(RELEASE_ALIAS_TAG)_$(shell date +'%Y%m%d'))
599597
echo $(NEW_RELEASE_ALIAS_TAG)
600598
$(MAKE) release-alias-tag TAG=$(RELEASE_ALIAS_TAG) RELEASE_ALIAS_TAG=$(NEW_RELEASE_ALIAS_TAG)

api/v1alpha1/cdk8sappproxy_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ type GitRepositorySpec struct {
4141
// containing authentication credentials for the Git repository.
4242
// The secret must contain 'username' and 'password' fields.
4343
// +kubebuilder:validation:Optional
44-
AuthSecretRef *corev1.LocalObjectReference `json:"authSecretRef,omitempty"` // New field
44+
AuthSecretRef *corev1.LocalObjectReference `json:"authSecretRef,omitempty"`
4545
}
4646

4747
// Cdk8sAppProxySpec defines the desired state of Cdk8sAppProxy.

api/v1alpha1/cdk8sappproxy_webhook_test.go

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package v1alpha1
22

33
import (
4-
"context"
54
"testing"
65

76
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
@@ -90,12 +89,7 @@ func TestCdk8sAppProxy_Default(t *testing.T) {
9089

9190
for _, tt := range tests {
9291
t.Run(tt.name, func(t *testing.T) {
93-
ctx := context.Background()
94-
err := tt.proxy.Default(ctx, tt.proxy)
95-
if err != nil {
96-
t.Errorf("Default() error = %v", err)
97-
return
98-
}
92+
tt.proxy.Default()
9993

10094
if tt.proxy.Spec.GitRepository != nil && tt.expected.Spec.GitRepository != nil {
10195
if tt.proxy.Spec.GitRepository.Reference != tt.expected.Spec.GitRepository.Reference {
@@ -177,21 +171,19 @@ func TestCdk8sAppProxy_ValidateCreate(t *testing.T) {
177171

178172
for _, tt := range tests {
179173
t.Run(tt.name, func(t *testing.T) {
180-
ctx := context.Background()
181-
warnings, err := tt.proxy.ValidateCreate(ctx, tt.proxy)
174+
warnings, err := tt.proxy.ValidateCreate()
182175

183176
if tt.wantError {
184177
if err == nil {
185178
t.Errorf("ValidateCreate() expected error, got nil")
179+
186180
return
187181
}
188182
if tt.errorMsg != "" && err.Error() != "validation failed: ["+tt.errorMsg+"]" {
189183
t.Errorf("ValidateCreate() error = %v, want error containing %v", err.Error(), tt.errorMsg)
190184
}
191-
} else {
192-
if err != nil {
193-
t.Errorf("ValidateCreate() unexpected error = %v", err)
194-
}
185+
} else if err != nil {
186+
t.Errorf("ValidateCreate() unexpected error = %v", err)
195187
}
196188

197189
// Warnings should always be nil in our implementation
@@ -248,8 +240,7 @@ func TestCdk8sAppProxy_ValidateUpdate(t *testing.T) {
248240

249241
for _, tt := range tests {
250242
t.Run(tt.name, func(t *testing.T) {
251-
ctx := context.Background()
252-
warnings, err := tt.newProxy.ValidateUpdate(ctx, tt.oldProxy, tt.newProxy)
243+
warnings, err := tt.newProxy.ValidateUpdate(tt.oldProxy)
253244

254245
if tt.wantError {
255246
if err == nil {
@@ -278,8 +269,7 @@ func TestCdk8sAppProxy_ValidateDelete(t *testing.T) {
278269
},
279270
}
280271

281-
ctx := context.Background()
282-
warnings, err := proxy.ValidateDelete(ctx, proxy)
272+
warnings, err := proxy.ValidateDelete()
283273

284274
if err != nil {
285275
t.Errorf("ValidateDelete() unexpected error = %v", err)
@@ -335,15 +325,17 @@ func TestCdk8sAppProxy_validateCdk8sAppProxy(t *testing.T) {
335325

336326
if (err != nil) != tt.wantError {
337327
t.Errorf("validateCdk8sAppProxy() error = %v, wantError %v", err, tt.wantError)
328+
338329
return
339330
}
340331

341332
// Compare warnings properly
342-
if tt.wantWarnings == nil && warnings != nil {
333+
switch {
334+
case tt.wantWarnings == nil && warnings != nil:
343335
t.Errorf("validateCdk8sAppProxy() warnings = %v, want nil", warnings)
344-
} else if tt.wantWarnings != nil && warnings == nil {
336+
case tt.wantWarnings != nil && warnings == nil:
345337
t.Errorf("validateCdk8sAppProxy() warnings = nil, want %v", tt.wantWarnings)
346-
} else if tt.wantWarnings != nil && warnings != nil {
338+
case tt.wantWarnings != nil && warnings != nil:
347339
if len(warnings) != len(tt.wantWarnings) {
348340
t.Errorf("validateCdk8sAppProxy() warnings length = %d, want %d", len(warnings), len(tt.wantWarnings))
349341
} else {

0 commit comments

Comments
 (0)