Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate from kuttl to chainsaw #181

Merged
merged 10 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
61 changes: 0 additions & 61 deletions .github/workflows/build_test_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -161,67 +161,6 @@ jobs:
path: .logs/*
overwrite: true

chainsaw-test:
needs: [go-build-test, docker-build]
runs-on: ubuntu-latest
steps:
- name: Harden Runner
uses: step-security/harden-runner@v2
with:
disable-sudo: true
egress-policy: block
allowed-endpoints: >
api.linode.com:443
api.github.com:443
github.com:443
gcr.io:443
proxy.golang.org:443
sum.golang.org:443
*.githubusercontent.com:443
docker.io:443
registry-1.docker.io:443
auth.docker.io:443
production.cloudflare.docker.com:443
storage.googleapis.com:443
registry.k8s.io:443
*.pkg.dev:443
*.amazonaws.com:443
*.blob.core.windows.net:443
quay.io:443
*.quay.io:443
api.snapcraft.io:443
cloud.tilt.dev:443

- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
check-latest: true

- name: Docker cache
uses: ScribeMD/docker-cache@0.3.7
with:
key: docker-${{ runner.os }}-${{ hashFiles('go.sum') }}}

- name: Chainsaw test
run: make chainsaw-test
env:
GITHUB_TOKEN: ${{ secrets.github_token }}
LINODE_TOKEN: ${{ secrets.LINODE_TOKEN }}

- name: Copy logs
if: ${{ always() }}
run: docker cp tilt-control-plane:/var/log .logs

- uses: actions/upload-artifact@v4
if: ${{ always() }}
with:
name: logs
path: .logs/*
overwrite: true

docker-build:
runs-on: ubuntu-latest
steps:
Expand Down
26 changes: 5 additions & 21 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -137,27 +137,18 @@ test: manifests generate fmt vet envtest ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test -race -timeout 60s ./... -coverprofile cover.out

.PHONY: e2etest
e2etest:
make --no-print-directory _e2etest # Workaround to force the flag on Github Action
e2etest: manifests generate local-deploy chainsaw
$(CHAINSAW) test ./e2e

local-deploy: kind ctlptl tilt kuttl chainsaw kustomize clusterctl
local-deploy: kind ctlptl tilt kustomize clusterctl
@echo -n "LINODE_TOKEN=$(LINODE_TOKEN)" > config/default/.env.linode
$(CTLPTL) apply -f .tilt/ctlptl-config.yaml
$(TILT) ci --timeout 240s -f Tiltfile

_e2etest: manifests generate local-deploy
ROOT_DIR="$(PWD)" $(KUTTL) test --config e2e/kuttl-config.yaml

.PHONY: chainsaw-test
chainsaw-test: manifests generate local-deploy
$(CHAINSAW) test ./e2e/linodecluster-controller ./e2e/linodemachine-controller

## --------------------------------------
## Build
## --------------------------------------

##@ Build:

.PHONY: build
build: manifests generate fmt vet ## Build manager binary.
go build -ldflags="-X github.com/linode/cluster-api-provider-linode/version.version=$(VERSION)" -o bin/manager cmd/main.go
Expand Down Expand Up @@ -298,7 +289,6 @@ CLUSTERCTL ?= $(LOCALBIN)/clusterctl
CONTROLLER_GEN ?= $(CACHE_BIN)/controller-gen
TILT ?= $(LOCALBIN)/tilt
KIND ?= $(LOCALBIN)/kind
KUTTL ?= $(LOCALBIN)/kubectl-kuttl
CHAINSAW ?= $(CACHE_BIN)/chainsaw
ENVTEST ?= $(CACHE_BIN)/setup-envtest
HUSKY ?= $(LOCALBIN)/husky
Expand All @@ -313,15 +303,15 @@ CLUSTERCTL_VERSION ?= v1.5.3
CONTROLLER_TOOLS_VERSION ?= v0.14.0
TILT_VERSION ?= 0.33.6
KIND_VERSION ?= 0.20.0
KUTTL_VERSION ?= 0.15.0
CHAINSAW_VERSION ?= v0.1.7
HUSKY_VERSION ?= v0.2.16
NILAWAY_VERSION ?= latest
GOVULNC_VERSION ?= v1.0.1
MOCKGEN_VERSION ?= v0.4.0

.PHONY: tools
tools: $(KUSTOMIZE) $(CTLPTL) $(CLUSTERCTL) $(CONTROLLER_GEN) $(TILT) $(KIND) $(KUTTL) $(CHAINSAW) $(ENVTEST) $(HUSKY) $(NILAWAY) $(GOVULNC) $(MOCKGEN)
tools: $(KUSTOMIZE) $(CTLPTL) $(CLUSTERCTL) $(CONTROLLER_GEN) $(TILT) $(KIND) $(CHAINSAW) $(ENVTEST) $(HUSKY) $(NILAWAY) $(GOVULNC) $(MOCKGEN)


.PHONY: kustomize
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
Expand Down Expand Up @@ -360,12 +350,6 @@ $(KIND): $(LOCALBIN)
curl -Lso $(KIND) https://github.com/kubernetes-sigs/kind/releases/download/v$(KIND_VERSION)/kind-$(OS)-$(ARCH_SHORT)
chmod +x $(KIND)

.PHONY: kuttl
kuttl: $(KUTTL) ## Download kuttl locally if necessary.
$(KUTTL): $(LOCALBIN)
curl -Lso $(KUTTL) https://github.com/kudobuilder/kuttl/releases/download/v$(KUTTL_VERSION)/kubectl-kuttl_$(KUTTL_VERSION)_$(OS)_$(ARCH)
chmod +x $(KUTTL)

.PHONY: chainsaw
chainsaw: $(CHAINSAW) ## Download chainsaw locally if necessary.
$(CHAINSAW): $(CACHE_BIN)
Expand Down
21 changes: 7 additions & 14 deletions cloud/services/object_storage_buckets.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,22 @@ import (
utilerrors "k8s.io/apimachinery/pkg/util/errors"

"github.com/linode/cluster-api-provider-linode/cloud/scope"
"github.com/linode/cluster-api-provider-linode/util"
)

func EnsureObjectStorageBucket(ctx context.Context, bScope *scope.ObjectStorageBucketScope) (*linodego.ObjectStorageBucket, error) {
// Buckets do not have IDs so hardcode it to 0
listFilter := util.Filter{
ID: nil,
Label: *bScope.Bucket.Spec.Label,
Tags: nil,
}
buckets, err := bScope.LinodeClient.ListObjectStorageBucketsInCluster(
bucket, err := bScope.LinodeClient.GetObjectStorageBucket(
ctx,
linodego.NewListOptions(1, listFilter.String()),
bScope.Bucket.Spec.Cluster,
*bScope.Bucket.Spec.Label,
)
if err != nil {
return nil, fmt.Errorf("failed to list buckets in cluster %s: %w", bScope.Bucket.Spec.Cluster, err)
linodeErr := &linodego.Error{}
if errors.As(err, linodeErr) && linodeErr.StatusCode() != http.StatusNotFound {
return nil, fmt.Errorf("failed to get bucket from cluster %s: %w", bScope.Bucket.Spec.Cluster, err)
}
if len(buckets) == 1 {
if bucket != nil {
bScope.Logger.Info("Bucket exists")

return &buckets[0], nil
return bucket, nil
}

opts := linodego.ObjectStorageBucketCreateOptions{
Expand All @@ -41,7 +35,6 @@ func EnsureObjectStorageBucket(ctx context.Context, bScope *scope.ObjectStorageB
ACL: linodego.ACLPrivate,
}

var bucket *linodego.ObjectStorageBucket
if bucket, err = bScope.LinodeClient.CreateObjectStorageBucket(ctx, opts); err != nil {
return nil, fmt.Errorf("failed to create bucket: %w", err)
}
Expand Down
6 changes: 3 additions & 3 deletions controller/linodeobjectstoragebucket_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ type LinodeObjectStorageBucketReconciler struct {
ReconcileTimeout time.Duration
}

//+kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=linodeobjectstoragebuckets,verbs=get;list;watch;create;update;patch;delete
//+kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=linodeobjectstoragebuckets/status,verbs=get;update;patch
//+kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=linodeobjectstoragebuckets/finalizers,verbs=update
// +kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=linodeobjectstoragebuckets,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=linodeobjectstoragebuckets/status,verbs=get;update;patch
// +kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=linodeobjectstoragebuckets/finalizers,verbs=update

// +kubebuilder:rbac:groups="",resources=events,verbs=get;list;watch;create;update;patch
// +kubebuilder:rbac:groups="",resources=secrets;,verbs=get;list;watch;create;update;patch
Expand Down
24 changes: 0 additions & 24 deletions e2e/Makefile

This file was deleted.

45 changes: 0 additions & 45 deletions e2e/README.MD

This file was deleted.

2 changes: 1 addition & 1 deletion e2e/kind-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
name: kuttl
name: e2e
nodes:
- role: control-plane
image: kindest/node:v1.28.0
Expand Down
6 changes: 0 additions & 6 deletions e2e/kuttl-config.yaml

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
---
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1
kind: LinodeObjectStorageBucket
metadata:
name: linodeobjectstoragebucket-sample
name: (join('-', [$namespace, 'backups']))
spec:
cluster: us-sea-1
keyGeneration: 0
status:
ready: true
keySecretName: linodeobjectstoragebucket-sample-access-keys
keySecretName: (join('-', [$namespace, 'backups-access-keys']))
lastKeyGeneration: 0
---
apiVersion: v1
kind: Secret
metadata:
name: (join('-', [$namespace, 'backups-access-keys']))
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1
kind: LinodeObjectStorageBucket
metadata:
name: linodeobjectstoragebucket-sample
name: (join('-', [$namespace, 'backups']))
spec:
cluster: us-sea-1

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1
kind: LinodeObjectStorageBucket
metadata:
name: linodeobjectstoragebucket-sample
name: (join('-', [$namespace, 'backups']))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of computing this multiple times i would create a test level binding with the computed name

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is $namespace available at the top binding level? I am seeing this error

=== NAME  chainsaw
    | 19:35:38 | chainsaw | @main | INTERNAL  | ERROR |
        === ERROR
        <nil>: Internal error: variable not defined: $namespace

with this binding def

spec:
  template: true
  bindings:
    - name: bucketName
      value: (join('-', [$namespace, 'backups']))

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, it's a bug. Fixing it, it will be in the next release.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spec:
cluster: us-sea-1
keyGeneration: 1
status:
ready: true
keySecretName: linodeobjectstoragebucket-sample-access-keys
keySecretName: (join('-', [$namespace, 'backups-access-keys']))
lastKeyGeneration: 1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1
kind: LinodeObjectStorageBucket
metadata:
name: linodeobjectstoragebucket-sample
name: (join('-', [$namespace, 'backups']))
spec:
cluster: us-sea-1
keyGeneration: 1

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1
kind: LinodeObjectStorageBucket
metadata:
name: linodeobjectstoragebucket-sample
name: (join('-', [$namespace, 'backups']))

---
apiVersion: v1
kind: Secret
metadata:
name: linodeobjectstoragebucket-sample-access-keys
name: (join('-', [$namespace, 'backups-access-keys']))

This file was deleted.

Loading