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

Repair pipeline #6

Merged
merged 5 commits into from
Nov 8, 2024
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
30 changes: 30 additions & 0 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name-template: 'v$RESOLVED_VERSION'
tag-template: 'v$RESOLVED_VERSION'

template: |
## General Changes

$CHANGES

categories:
- title: '🚀 Features'
labels:
- 'feature'
- 'enhancement'
- title: '🐛 Bug Fixes'
labels:
- 'fix'
- 'bugfix'
- 'bug'

version-resolver:
major:
labels:
- 'major'
minor:
labels:
- 'minor'
patch:
labels:
- 'patch'
default: patch
44 changes: 44 additions & 0 deletions .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
name: Docker Build Action
on:
pull_request:
branches:
- main
release:
types:
- published
push:
branches:
- main

env:
REGISTRY: ghcr.io

jobs:
build:
name: Docker Build
runs-on: ubuntu-latest

steps:
- name: Log in to the container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.DOCKER_REGISTRY_USER }}
password: ${{ secrets.DOCKER_REGISTRY_TOKEN }}

- name: Checkout
uses: actions/checkout@v4

- name: Make tag
run: |
[ "${GITHUB_EVENT_NAME}" == 'pull_request' ] && echo "tag=${GITHUB_HEAD_REF##*/}" >> $GITHUB_ENV || true
[ "${GITHUB_EVENT_NAME}" == 'release' ] && echo "tag=${GITHUB_REF##*/}" >> $GITHUB_ENV || true
[ "${GITHUB_EVENT_NAME}" == 'push' ] && echo "tag=latest" >> $GITHUB_ENV || true

- name: Build and push image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ env.REGISTRY }}/metal-stack/capms-controller:${{ env.tag }}
11 changes: 7 additions & 4 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ name: Lint

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
lint:
Expand All @@ -15,9 +19,8 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '~1.23'
go-version-file: 'go.mod'
cache: false

- name: Run linter
- name: Run Linter
uses: golangci/golangci-lint-action@v6
with:
version: v1.59
15 changes: 15 additions & 0 deletions .github/workflows/release-drafter.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
name: Release Drafter Action

on:
push:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: release-drafter/release-drafter@v6
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6 changes: 5 additions & 1 deletion .github/workflows/test-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ name: E2E Tests

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
test-e2e:
Expand All @@ -15,7 +19,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '~1.23'
go-version-file: 'go.mod'

- name: Install the latest version of kind
run: |
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ name: Tests

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
test:
Expand All @@ -15,7 +19,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '~1.23'
go-version-file: 'go.mod'

- name: Running Tests
run: |
Expand Down
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ vet: ## Run go vet against code.
test: manifests generate fmt vet envtest ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test $$(go list ./... | grep -v /e2e) -coverprofile cover.out

# TODO(user): To use a different vendor for e2e tests, modify the setup under 'tests/e2e'.
# The default setup assumes Kind is pre-installed and builds/loads the Manager Docker image locally.
# Prometheus and CertManager are installed by default; skip with:
# - PROMETHEUS_INSTALL_SKIP=true
Expand Down Expand Up @@ -193,7 +192,7 @@ GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
KUSTOMIZE_VERSION ?= v5.4.3
CONTROLLER_TOOLS_VERSION ?= v0.16.4
ENVTEST_VERSION ?= release-0.19
GOLANGCI_LINT_VERSION ?= v1.59.1
GOLANGCI_LINT_VERSION ?= v1.61.0

.PHONY: kustomize
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
Expand Down
12 changes: 6 additions & 6 deletions config/default/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@ resources:
# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER'. 'WEBHOOK' components are required.
#- ../certmanager
# [PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'.
#- ../prometheus
- ../prometheus
# [METRICS] Expose the controller manager metrics service.
# - metrics_service.yaml
- metrics_service.yaml
# [NETWORK POLICY] Protect the /metrics endpoint and Webhook Server with NetworkPolicy.
# Only Pod(s) running a namespace labeled with 'metrics: enabled' will be able to gather the metrics.
# Only CR(s) which requires webhooks and are applied on namespaces labeled with 'webhooks: enabled' will
# be able to communicate with the Webhook Server.
#- ../network-policy

# Uncomment the patches line if you enable Metrics, and/or are using webhooks and cert-manager
# patches:
patches:
# [METRICS] The following patch will enable the metrics endpoint using HTTPS and the port :8443.
# More info: https://book.kubebuilder.io/reference/metrics
# - path: manager_metrics_patch.yaml
# target:
# kind: Deployment
- path: manager_metrics_patch.yaml
target:
kind: Deployment

# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
# crd/kustomization.yaml
Expand Down
4 changes: 2 additions & 2 deletions internal/controller/metalstackcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ func (r *MetalStackClusterReconciler) status(ctx context.Context, infraCluster *

conditionUpdates <- func() {
if err != nil {
conditions.MarkFalse(infraCluster, v1alpha1.ClusterNodeNetworkEnsured, "InternalError", clusterv1.ConditionSeverityError, err.Error())
conditions.MarkFalse(infraCluster, v1alpha1.ClusterNodeNetworkEnsured, "InternalError", clusterv1.ConditionSeverityError, "%s", err.Error())
return
}

Expand Down Expand Up @@ -417,7 +417,7 @@ func (r *MetalStackClusterReconciler) status(ctx context.Context, infraCluster *

conditionUpdates <- func() {
if err != nil && !apierrors.IsNotFound(err) {
conditions.MarkFalse(infraCluster, v1alpha1.ClusterFirewallDeploymentReady, "InternalError", clusterv1.ConditionSeverityError, err.Error())
conditions.MarkFalse(infraCluster, v1alpha1.ClusterFirewallDeploymentReady, "InternalError", clusterv1.ConditionSeverityError, "%s", err.Error())
return
}

Expand Down
24 changes: 13 additions & 11 deletions internal/controller/metalstackmachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,13 @@ func (r *MetalStackMachineReconciler) SetupWithManager(mgr ctrl.Manager) error {
Complete(r)
}

func (r *MetalStackMachineReconciler) create(ctx context.Context, log logr.Logger, infraMachine *v1alpha1.MetalStackMachine, infraCluster *v1alpha1.MetalStackCluster) error {
func (r *MetalStackMachineReconciler) create(ctx context.Context, _ logr.Logger, infraMachine *v1alpha1.MetalStackMachine, infraCluster *v1alpha1.MetalStackCluster) error {
helper, err := patch.NewHelper(infraMachine, r.Client)
if err != nil {
return err
}

//TODO: Find any existing machine by tag first
// TODO: Find any existing machine by tag first
const TagInfraMachineID = "machine.metal-stack.infrastructure.cluster.x-k8s.io/id"
infraMachineOwnerTag := fmt.Sprintf("%s=%s", TagInfraMachineID, infraMachine.GetUID())

Expand Down Expand Up @@ -218,8 +218,8 @@ func (r *MetalStackMachineReconciler) create(ctx context.Context, log logr.Logge
return nil
}

func (r *MetalStackMachineReconciler) reconcile(ctx context.Context, log logr.Logger, infraMachine *v1alpha1.MetalStackMachine, infraCluster *v1alpha1.MetalStackCluster) error {
_, err := r.findProviderMachine(ctx, infraMachine, infraCluster)
func (r *MetalStackMachineReconciler) reconcile(ctx context.Context, _ logr.Logger, infraMachine *v1alpha1.MetalStackMachine, infraCluster *v1alpha1.MetalStackCluster) error {
err := r.findProviderMachine(ctx, infraMachine, infraCluster)
if err != nil && !errors.Is(err, errProviderMachineNotFound) {
return err
}
Expand All @@ -231,7 +231,7 @@ func (r *MetalStackMachineReconciler) reconcile(ctx context.Context, log logr.Lo
}

func (r *MetalStackMachineReconciler) delete(ctx context.Context, log logr.Logger, infraMachine *v1alpha1.MetalStackMachine, infraCluster *v1alpha1.MetalStackCluster) error {
_, err := r.findProviderMachine(ctx, infraMachine, infraCluster)
err := r.findProviderMachine(ctx, infraMachine, infraCluster)
if errors.Is(err, errProviderMachineNotFound) {
// metal-stack machine already freed
return nil
Expand All @@ -248,27 +248,29 @@ func (r *MetalStackMachineReconciler) delete(ctx context.Context, log logr.Logge
return nil
}

func (r *MetalStackMachineReconciler) status(ctx context.Context, infraMachine *v1alpha1.MetalStackMachine, infraCluster *v1alpha1.MetalStackCluster) error {
func (r *MetalStackMachineReconciler) status(_ context.Context, _ *v1alpha1.MetalStackMachine, _ *v1alpha1.MetalStackCluster) error {
return nil
}

func (r *MetalStackMachineReconciler) findProviderMachine(ctx context.Context, infraMachine *v1alpha1.MetalStackMachine, infraCluster *v1alpha1.MetalStackCluster) (*models.V1MachineResponse, error) {
func (r *MetalStackMachineReconciler) findProviderMachine(ctx context.Context, infraMachine *v1alpha1.MetalStackMachine, infraCluster *v1alpha1.MetalStackCluster) error {
mfr := &models.V1MachineFindRequest{
ID: infraMachine.Spec.ProviderID,
AllocationProject: infraCluster.Spec.ProjectID,
Tags: []string{fmt.Sprintf("%s%s", tag.ClusterID, infraCluster.GetUID())},
}

resp, err := r.MetalClient.Machine().FindMachines(metalmachine.NewFindMachinesParamsWithContext(ctx).WithBody(mfr), nil)
if err != nil {
return nil, err
return err
}

switch len(resp.Payload) {
case 0:
// metal-stack machine already freed
return nil, errProviderMachineNotFound
return errProviderMachineNotFound
case 1:
return resp.Payload[0], nil
return nil
default:
return nil, errProviderMachineTooManyFound
return errProviderMachineTooManyFound
}
}
2 changes: 1 addition & 1 deletion test/e2e/e2e_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ var (

// projectImage is the name of the image which will be build and loaded
// with the code source changes to be tested.
projectImage = "example.com/cluster-api-provider-metal-stack:v0.0.1"
projectImage = "capms-controller:latest"
)

// TestE2E runs the end-to-end (e2e) test suite for the project. These tests execute in an isolated,
Expand Down
Loading
Loading