Skip to content

Commit

Permalink
Bump CAPI to v1.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
haijianyang committed Aug 28, 2023
1 parent 7253a00 commit 386d334
Show file tree
Hide file tree
Showing 27 changed files with 459 additions and 395 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.6
7 changes: 4 additions & 3 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 @@ -103,9 +104,9 @@ linters-settings:
- pkg: github.com/smartxworks/cluster-api-provider-elf/api/v1beta1
alias: infrav1
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 @@ -168,7 +169,7 @@ issues:

run:
timeout: 10m
go: "1.19"
go: "1.20"
skip-files:
- "zz_generated.*\\.go$"
allow-parallel-runners: true
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

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

# Run this with docker build --build_arg $(go env GOPROXY) to override the goproxy
Expand Down
19 changes: 17 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ SHELL := /usr/bin/env bash

VERSION ?= $(shell cat clusterctl-settings.json | jq .config.nextVersion -r)

#
# Go.
#
GO_VERSION ?= 1.20.6

# 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 @@ -150,7 +155,7 @@ 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.4)
$(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.
Expand All @@ -162,7 +167,7 @@ kind: ## Download kind locally if necessary.

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.2)
$(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 @@ -325,3 +330,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)
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.11.4
controller-gen.kubebuilder.io/version: v0.12.0
name: elfclusters.infrastructure.cluster.x-k8s.io
spec:
group: infrastructure.cluster.x-k8s.io
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.11.4
controller-gen.kubebuilder.io/version: v0.12.0
name: elfmachines.infrastructure.cluster.x-k8s.io
spec:
group: infrastructure.cluster.x-k8s.io
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.11.4
controller-gen.kubebuilder.io/version: v0.12.0
name: elfmachinetemplates.infrastructure.cluster.x-k8s.io
spec:
group: infrastructure.cluster.x-k8s.io
Expand Down
22 changes: 10 additions & 12 deletions controllers/elfcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ import (
"sigs.k8s.io/cluster-api/util/annotations"
"sigs.k8s.io/cluster-api/util/conditions"
"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/client"
"sigs.k8s.io/controller-runtime/pkg/controller"
ctrlutil "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/handler"
ctrlmgr "sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"

infrav1 "github.com/smartxworks/cluster-api-provider-elf/api/v1beta1"
"github.com/smartxworks/cluster-api-provider-elf/pkg/config"
Expand All @@ -48,12 +48,6 @@ import (
machineutil "github.com/smartxworks/cluster-api-provider-elf/pkg/util/machine"
)

var (
clusterControlledType = &infrav1.ElfCluster{}
clusterControlledTypeName = reflect.TypeOf(clusterControlledType).Elem().Name()
clusterControlledTypeGVK = infrav1.GroupVersion.WithKind(clusterControlledTypeName)
)

//+kubebuilder:rbac:groups=core,resources=secrets,verbs=get;list;watch;create;patch
//+kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=elfclusters,verbs=get;list;watch;create;update;patch;delete
//+kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=elfclusters/status,verbs=get;update;patch
Expand All @@ -62,9 +56,12 @@ var (

// AddClusterControllerToManager adds the cluster controller to the provided
// manager.
func AddClusterControllerToManager(ctx *context.ControllerManagerContext, mgr ctrlmgr.Manager) error {
func AddClusterControllerToManager(ctx *context.ControllerManagerContext, mgr ctrlmgr.Manager, options controller.Options) error {
var (
controllerNameShort = fmt.Sprintf("%s-controller", strings.ToLower(clusterControlledTypeName))
clusterControlledType = &infrav1.ElfCluster{}
clusterControlledTypeName = reflect.TypeOf(clusterControlledType).Elem().Name()
clusterControlledTypeGVK = infrav1.GroupVersion.WithKind(clusterControlledTypeName)
controllerNameShort = fmt.Sprintf("%s-controller", strings.ToLower(clusterControlledTypeName))
)

// Build the controller context.
Expand All @@ -84,10 +81,11 @@ func AddClusterControllerToManager(ctx *context.ControllerManagerContext, mgr ct
For(clusterControlledType).
// Watch the CAPI resource that owns this infrastructure resource.
Watches(
&source.Kind{Type: &clusterv1.Cluster{}},
&clusterv1.Cluster{},
handler.EnqueueRequestsFromMapFunc(capiutil.ClusterToInfrastructureMapFunc(ctx, clusterControlledTypeGVK, mgr.GetClient(), &infrav1.ElfCluster{})),
).
WithOptions(controller.Options{MaxConcurrentReconciles: ctx.MaxConcurrentReconciles}).
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), ctx.WatchFilterValue)).
WithOptions(options).
Complete(reconciler)
}

Expand Down Expand Up @@ -231,7 +229,7 @@ func (r *ElfClusterReconciler) reconcileDelete(ctx *context.ClusterContext) (rec

func (r *ElfClusterReconciler) reconcileDeleteVMPlacementGroups(ctx *context.ClusterContext) error {
placementGroupPrefix := towerresources.GetVMPlacementGroupNamePrefix(ctx.Cluster)
if err := ctx.VMService.DeleteVMPlacementGroupsByName(placementGroupPrefix); err != nil {
if err := ctx.VMService.DeleteVMPlacementGroupsByName(ctx, placementGroupPrefix); err != nil {
return err
} else {
ctx.Logger.Info(fmt.Sprintf("Placement groups with name prefix %s deleted", placementGroupPrefix))
Expand Down
12 changes: 2 additions & 10 deletions controllers/elfcluster_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 @@ -64,13 +63,6 @@ var _ = Describe("ElfClusterReconciler", 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 Expand Up @@ -215,7 +207,7 @@ var _ = Describe("ElfClusterReconciler", func() {
reconciler := &ElfClusterReconciler{ControllerContext: ctrlContext, NewVMService: mockNewVMService}
elfClusterKey := capiutil.ObjectKey(elfCluster)

mockVMService.EXPECT().DeleteVMPlacementGroupsByName(towerresources.GetVMPlacementGroupNamePrefix(cluster)).Return(errors.New("some error"))
mockVMService.EXPECT().DeleteVMPlacementGroupsByName(gomock.Any(), towerresources.GetVMPlacementGroupNamePrefix(cluster)).Return(errors.New("some error"))

result, err := reconciler.Reconcile(ctx, ctrl.Request{NamespacedName: elfClusterKey})
Expect(result).To(BeZero())
Expand All @@ -224,7 +216,7 @@ var _ = Describe("ElfClusterReconciler", func() {
logBuffer = new(bytes.Buffer)
klog.SetOutput(logBuffer)
task.Status = models.NewTaskStatus(models.TaskStatusSUCCESSED)
mockVMService.EXPECT().DeleteVMPlacementGroupsByName(towerresources.GetVMPlacementGroupNamePrefix(cluster)).Return(nil)
mockVMService.EXPECT().DeleteVMPlacementGroupsByName(gomock.Any(), towerresources.GetVMPlacementGroupNamePrefix(cluster)).Return(nil)
mockVMService.EXPECT().DeleteLabel(towerresources.GetVMLabelClusterName(), elfCluster.Name, true).Return("labelid", nil)
mockVMService.EXPECT().DeleteLabel(towerresources.GetVMLabelVIP(), elfCluster.Spec.ControlPlaneEndpoint.Host, false).Return("labelid", nil)
mockVMService.EXPECT().DeleteLabel(towerresources.GetVMLabelNamespace(), elfCluster.Namespace, true).Return("", nil)
Expand Down
9 changes: 5 additions & 4 deletions controllers/elfmachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ import (
"sigs.k8s.io/cluster-api/util/annotations"
"sigs.k8s.io/cluster-api/util/conditions"
"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/client"
"sigs.k8s.io/controller-runtime/pkg/controller"
ctrlutil "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/handler"
ctrlmgr "sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"

infrav1 "github.com/smartxworks/cluster-api-provider-elf/api/v1beta1"
"github.com/smartxworks/cluster-api-provider-elf/pkg/config"
Expand Down Expand Up @@ -75,7 +75,7 @@ type ElfMachineReconciler struct {

// AddMachineControllerToManager adds the machine controller to the provided
// manager.
func AddMachineControllerToManager(ctx *context.ControllerManagerContext, mgr ctrlmgr.Manager) error {
func AddMachineControllerToManager(ctx *context.ControllerManagerContext, mgr ctrlmgr.Manager, options controller.Options) error {
var (
controlledType = &infrav1.ElfMachine{}
controlledTypeName = reflect.TypeOf(controlledType).Elem().Name()
Expand All @@ -101,10 +101,11 @@ func AddMachineControllerToManager(ctx *context.ControllerManagerContext, mgr ct
For(controlledType).
// Watch the CAPI resource that owns this infrastructure resource.
Watches(
&source.Kind{Type: &clusterv1.Machine{}},
&clusterv1.Machine{},
handler.EnqueueRequestsFromMapFunc(capiutil.MachineToInfrastructureMapFunc(controlledTypeGVK)),
).
WithOptions(controller.Options{MaxConcurrentReconciles: ctx.MaxConcurrentReconciles}).
WithOptions(options).
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), ctx.WatchFilterValue)).
Complete(reconciler)
}

Expand Down
6 changes: 3 additions & 3 deletions controllers/elfmachine_controller_placement_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (r *ElfMachineReconciler) createPlacementGroup(ctx *context.MachineContext,
return nil, err
}

task, err := ctx.VMService.WaitTask(*withTaskVMPlacementGroup.TaskID, config.WaitTaskTimeoutForPlacementGroupOperation, config.WaitTaskInterval)
task, err := ctx.VMService.WaitTask(ctx, *withTaskVMPlacementGroup.TaskID, config.WaitTaskTimeoutForPlacementGroupOperation, config.WaitTaskInterval)
if err != nil {
// The default timeout for Tower to create a placement group is one minute.
// When current task times out, duplicate placement groups may or may not appear.
Expand Down Expand Up @@ -564,7 +564,7 @@ func (r *ElfMachineReconciler) addVMsToPlacementGroup(ctx *context.MachineContex
}

taskID := *task.ID
task, err = ctx.VMService.WaitTask(taskID, config.WaitTaskTimeoutForPlacementGroupOperation, config.WaitTaskInterval)
task, err = ctx.VMService.WaitTask(ctx, taskID, config.WaitTaskTimeoutForPlacementGroupOperation, config.WaitTaskInterval)
if err != nil {
return errors.Wrapf(err, "failed to wait for placement group updating task to complete in %s: pgName %s, taskID %s", config.WaitTaskTimeoutForPlacementGroupOperation, *placementGroup.Name, taskID)
}
Expand Down Expand Up @@ -630,7 +630,7 @@ func (r *ElfMachineReconciler) deletePlacementGroup(ctx *context.MachineContext)
return false, nil
}

if err := ctx.VMService.DeleteVMPlacementGroupsByName(*placementGroup.Name); err != nil {
if err := ctx.VMService.DeleteVMPlacementGroupsByName(ctx, *placementGroup.Name); err != nil {
return false, err
} else {
ctx.Logger.Info(fmt.Sprintf("Placement group %s deleted", *placementGroup.Name))
Expand Down
Loading

0 comments on commit 386d334

Please sign in to comment.