Skip to content

Commit

Permalink
Bump CAPI to v1.5.2 and CAPE to v1.3.0-rc.2 (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
haijianyang authored Sep 28, 2023
1 parent 2badee5 commit 4e05cbc
Show file tree
Hide file tree
Showing 19 changed files with 418 additions and 447 deletions.
12 changes: 8 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,20 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- uses: actions/setup-go@v2
- name: Calculate go version
run: echo "go_version=$(make go-version)" >> $GITHUB_ENV

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.19
go-version: ${{ env.go_version }}

- run: make lint

- run: make test

- uses: codecov/codecov-action@v2
- uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
13 changes: 8 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,18 @@ jobs:
fi
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Install go
uses: actions/setup-go@v2
- name: Calculate go version
run: echo "go_version=$(make go-version)" >> $GITHUB_ENV

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.19
go-version: ${{ env.go_version }}

- name: Login docker
uses: docker/login-action@v1
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion .go-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.19.6
1.20.8
8 changes: 4 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ linters:
- bidichk
- contextcheck
- cyclop
- depguard
- dupl
- durationcheck
- errname
Expand Down Expand Up @@ -85,8 +86,6 @@ linters-settings:
alias: ctrlmgr
- pkg: sigs.k8s.io/controller-runtime/pkg/controller/controllerutil
alias: ctrlutil
- pkg: sigs.k8s.io/controller-runtime/pkg/log
alias: ctrllog
# CAPI
- pkg: sigs.k8s.io/cluster-api/api/v1beta1
alias: capiv1
Expand All @@ -104,9 +103,9 @@ linters-settings:
- pkg: github.com/smartxworks/cluster-api-provider-elf/api/v1beta1
alias: capev1
staticcheck:
go: "1.19"
go: "1.20"
stylecheck:
go: "1.19"
go: "1.20"
issues:
max-same-issues: 0
max-issues-per-linter: 0
Expand Down Expand Up @@ -169,6 +168,7 @@ issues:

run:
timeout: 10m
go: "1.20"
skip-files:
- "zz_generated.*\\.go$"
allow-parallel-runners: true
11 changes: 8 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# syntax=docker/dockerfile:1.4

# Copyright 2022.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -12,8 +14,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# Build architecture
ARG ARCH

# Build the manager binary
FROM golang:1.19.6 as builder
FROM golang:1.20.8 as builder
WORKDIR /workspace

# Run this with docker build --build_arg $(go env GOPROXY) to override the goproxy
Expand All @@ -31,14 +36,14 @@ RUN go mod download
COPY ./ ./

# Build
ARG ARCH=amd64
ARG ldflags

RUN CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} \
go build -a -ldflags "${ldflags} -extldflags '-static'" \
-o manager .

# Copy the controller-manager into a thin image
FROM gcr.io/distroless/static:nonroot
FROM gcr.io/distroless/static:nonroot-${ARCH}
WORKDIR /
COPY --from=builder /workspace/manager .
# Use uid of nonroot user (65532) because kubernetes expects numeric user when applying PSPs
Expand Down
25 changes: 20 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ SHELL := /usr/bin/env bash

.DEFAULT_GOAL := help

#
# Go.
#
GO_VERSION ?= 1.20.8

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
Expand Down Expand Up @@ -95,19 +100,19 @@ kustomize: ## Download kustomize locally if necessary.

CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
controller-gen: ## Download controller-gen locally if necessary.
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.11.3)
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.12.0)

GINKGO := $(shell pwd)/bin/ginkgo
ginkgo: ## Download ginkgo locally if necessary.
$(call go-get-tool,$(GINKGO),github.com/onsi/ginkgo/v2/ginkgo@v2.9.2)
$(call go-get-tool,$(GINKGO),github.com/onsi/ginkgo/v2/ginkgo@v2.11.0)

KIND := $(shell pwd)/bin/kind
kind: ## Download kind locally if necessary.
$(call go-get-tool,$(KIND),sigs.k8s.io/kind@v0.17.0)
$(call go-get-tool,$(KIND),sigs.k8s.io/kind@v0.20.0)

GOLANGCI_LINT := $(shell pwd)/bin/golangci-lint
golangci-lint: ## Download golangci-lint locally if necessary.
$(call go-get-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint@v1.52.1)
$(call go-get-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint@v1.53.3)

## --------------------------------------
## Linting and fixing linter errors
Expand Down Expand Up @@ -229,7 +234,7 @@ docker-push: ## Push the docker image

.PHONY: docker-pull-prerequisites
docker-pull-prerequisites:
docker pull docker.io/docker/dockerfile:1.1-experimental
docker pull docker.io/docker/dockerfile:1.4
docker pull gcr.io/distroless/static:latest

## --------------------------------------
Expand All @@ -255,3 +260,13 @@ docker-push-manifest: ## Push the fat manifest docker image.
docker manifest create --amend $(CONTROLLER_IMG):$(IMAGE_TAG) $(shell echo $(ALL_ARCH) | sed -e "s~[^ ]*~$(CONTROLLER_IMG)\-&:$(IMAGE_TAG)~g")
@for arch in $(ALL_ARCH); do docker manifest annotate --arch $${arch} ${CONTROLLER_IMG}:${IMAGE_TAG} ${CONTROLLER_IMG}-$${arch}:${IMAGE_TAG}; done
docker manifest push --purge ${CONTROLLER_IMG}:${IMAGE_TAG}


## --------------------------------------
## Helpers
## --------------------------------------

##@ helpers:

go-version: ## Print the go version we use to compile our binaries and images
@echo $(GO_VERSION)
1 change: 0 additions & 1 deletion config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ spec:
containers:
- args:
- --leader-elect
- --logtostderr
- --v=4
image: docker.io/smartxworks/cape-ip-manager:latest
imagePullPolicy: IfNotPresent
Expand Down
1 change: 0 additions & 1 deletion config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
creationTimestamp: null
name: manager-role
rules:
- apiGroups:
Expand Down
6 changes: 4 additions & 2 deletions controllers/elfmachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
capiutil "sigs.k8s.io/cluster-api/util"
"sigs.k8s.io/cluster-api/util/annotations"
"sigs.k8s.io/cluster-api/util/patch"
"sigs.k8s.io/cluster-api/util/predicates"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/controller"
ctrlutil "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
Expand Down Expand Up @@ -70,7 +71,7 @@ type ElfMachineReconciler struct {
*capecontext.ControllerContext
}

func AddMachineControllerToManager(ctx *capecontext.ControllerManagerContext, mgr ctrlmgr.Manager) error {
func AddMachineControllerToManager(ctx *capecontext.ControllerManagerContext, mgr ctrlmgr.Manager, options controller.Options) error {
var (
controlledType = &capev1.ElfMachine{}
controlledTypeName = reflect.TypeOf(controlledType).Elem().Name()
Expand All @@ -90,7 +91,8 @@ func AddMachineControllerToManager(ctx *capecontext.ControllerManagerContext, mg

return ctrl.NewControllerManagedBy(mgr).
For(controlledType).
WithOptions(controller.Options{MaxConcurrentReconciles: ctx.MaxConcurrentReconciles}).
WithOptions(options).
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), ctx.WatchFilterValue)).
Complete(reconciler)
}

Expand Down
8 changes: 0 additions & 8 deletions controllers/elfmachine_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package controllers
import (
"bytes"
goctx "context"
"flag"
"fmt"
"time"

Expand Down Expand Up @@ -59,13 +58,6 @@ var _ = Describe("ElfMachineReconciler", func() {
ctx := goctx.Background()

BeforeEach(func() {
// set log
if err := flag.Set("logtostderr", "false"); err != nil {
_ = fmt.Errorf("Error setting logtostderr flag")
}
if err := flag.Set("v", "6"); err != nil {
_ = fmt.Errorf("Error setting v flag")
}
logBuffer = new(bytes.Buffer)
klog.SetOutput(logBuffer)

Expand Down
23 changes: 20 additions & 3 deletions controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package controllers

import (
"flag"
"fmt"
"os"
"testing"
Expand All @@ -25,7 +26,9 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
capecontext "github.com/smartxworks/cluster-api-provider-elf/pkg/context"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/klog/v2"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"
ctrllog "sigs.k8s.io/controller-runtime/pkg/log"

ipamutil "github.com/smartxworks/cluster-api-provider-elf-static-ip/pkg/ipam/util"
Expand Down Expand Up @@ -55,12 +58,26 @@ func TestMain(m *testing.M) {
}

func setup() {
// set log
klog.InitFlags(nil)
if err := flag.Set("logtostderr", "false"); err != nil {
_ = fmt.Errorf("Error setting logtostderr flag")
}
if err := flag.Set("v", "6"); err != nil {
_ = fmt.Errorf("Error setting v flag")
}
if err := flag.Set("alsologtostderr", "false"); err != nil {
_ = fmt.Errorf("Error setting alsologtostderr flag")
}

testEnv = helpers.NewTestEnvironment()

// Set kubeconfig.
os.Setenv("KUBECONFIG", testEnv.Kubeconfig)

if err := AddMachineControllerToManager(testEnv.GetContext(), testEnv.Manager); err != nil {
controllerOpts := controller.Options{MaxConcurrentReconciles: 10}

if err := AddMachineControllerToManager(testEnv.GetContext(), testEnv.Manager, controllerOpts); err != nil {
panic(fmt.Sprintf("unable to setup ElfMachine controller: %v", err))
}

Expand All @@ -80,7 +97,7 @@ func teardown() {
}
}

func newCtrlContexts(objs ...runtime.Object) *capecontext.ControllerContext {
func newCtrlContexts(objs ...client.Object) *capecontext.ControllerContext {
ctrlMgrContext := fake.NewControllerManagerContext(objs...)
ctrlContext := &capecontext.ControllerContext{
ControllerManagerContext: ctrlMgrContext,
Expand Down
Loading

0 comments on commit 4e05cbc

Please sign in to comment.