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

Upgrade controller-runtime to v0.12.3 #788

Merged
merged 1 commit into from
Aug 19, 2022
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
4 changes: 2 additions & 2 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -328,10 +328,10 @@ jobs:
name: Test
runs-on: ubuntu-20.04
steps:
- name: Set up Go 1.16
- name: Set up Go 1.17
uses: actions/setup-go@v2.1.3
with:
go-version: 1.16
go-version: 1.17
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v2.3.4
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ jobs:
name: Lint
runs-on: ubuntu-20.04
steps:
- name: Set up Go 1.16
- name: Set up Go 1.17
uses: actions/setup-go@v2.1.3
with:
go-version: 1.16
go-version: 1.17
- uses: actions/checkout@v2
# See also https://github.com/GoogleCloudPlatform/golang-samples/blob/78dfa41f10b449ba7a06d9793cbd81878d44a4fb/.github/workflows/go.yaml#L29-L53
- name: Run go mod tidy on root modules
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Welcome to go through the contribution guide!

Before you get started to contribute. Please the following requirements:

* [Golang](https://golang.org/) 1.16
* [Golang](https://golang.org/) 1.17

| Technical area | Level requires | Links |
|---|---|---|
Expand Down
17 changes: 9 additions & 8 deletions cmd/allinone/app/entrypoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ limitations under the License.
package app

import (
"context"
"github.com/spf13/cobra"
"k8s.io/klog"
"k8s.io/klog/v2"
apiserverApp "kubesphere.io/devops/cmd/apiserver/app"
"kubesphere.io/devops/cmd/apiserver/app/options"
controllerApp "kubesphere.io/devops/cmd/controller/app"
controllerOpt "kubesphere.io/devops/cmd/controller/app/options"
"kubesphere.io/devops/pkg/config"
"sigs.k8s.io/controller-runtime/pkg/runtime/signals"
"sigs.k8s.io/controller-runtime/pkg/manager/signals"

utilerrors "k8s.io/apimachinery/pkg/util/errors"
)
Expand All @@ -33,19 +34,19 @@ func NewCommand() *cobra.Command {
return &cobra.Command{
Use: "ks-devops",
RunE: func(cmd *cobra.Command, args []string) (err error) {
stopChain := signals.SetupSignalHandler()
go func(stopCh <-chan struct{}) {
ctx := signals.SetupSignalHandler()
go func(stopCh context.Context) {
if err := runControllerManager(stopCh); err != nil {
panic(err)
}
}(stopChain)
err = runAPIServer(stopChain)
}(ctx)
err = runAPIServer(ctx)
return
},
}
}

func runAPIServer(stopCh <-chan struct{}) error {
func runAPIServer(stopCh context.Context) error {
s := options.NewServerRunOptions()

// Load configuration from file
Expand All @@ -66,7 +67,7 @@ func runAPIServer(stopCh <-chan struct{}) error {
return apiserverApp.Run(s, stopCh)
}

func runControllerManager(stopCh <-chan struct{}) (err error) {
func runControllerManager(stopCh context.Context) (err error) {
var conf *config.Config
s := controllerOpt.NewDevOpsControllerManagerOptions()
conf, err = config.TryLoadFromDisk()
Expand Down
2 changes: 1 addition & 1 deletion cmd/apiserver/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/manager"

cliflag "k8s.io/component-base/cli/flag"
"k8s.io/klog"
"k8s.io/klog/v2"
"kubesphere.io/devops/pkg/apis"
"kubesphere.io/devops/pkg/apiserver"
"kubesphere.io/devops/pkg/client/clientset/versioned/scheme"
Expand Down
11 changes: 6 additions & 5 deletions cmd/apiserver/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@ limitations under the License.
package app

import (
"context"
"fmt"

"github.com/spf13/cobra"
utilerrors "k8s.io/apimachinery/pkg/util/errors"
cliflag "k8s.io/component-base/cli/flag"
"k8s.io/klog"
"k8s.io/klog/v2"

"kubesphere.io/devops/cmd/apiserver/app/options"
"kubesphere.io/devops/pkg/config"
"sigs.k8s.io/controller-runtime/pkg/runtime/signals"
"sigs.k8s.io/controller-runtime/pkg/manager/signals"
)

func NewAPIServerCommand() (cmd *cobra.Command) {
Expand Down Expand Up @@ -85,13 +86,13 @@ cluster's shared state through which all other components interact.`,
return
}

func Run(s *options.ServerRunOptions, stopCh <-chan struct{}) error {
apiserver, err := s.NewAPIServer(stopCh)
func Run(s *options.ServerRunOptions, stopCh context.Context) error {
apiserver, err := s.NewAPIServer(stopCh.Done())
if err != nil {
return err
}

err = apiserver.PrepareRun(stopCh)
err = apiserver.PrepareRun(stopCh.Done())
if err != nil {
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/controller/app/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"kubesphere.io/devops/pkg/server/errors"

"github.com/jenkins-zh/jenkins-client/pkg/core"
"k8s.io/klog"
"k8s.io/klog/v2"
"kubesphere.io/devops/cmd/controller/app/options"
"kubesphere.io/devops/controllers/jenkins/config"
jenkinspipeline "kubesphere.io/devops/controllers/jenkins/pipeline"
Expand Down
2 changes: 1 addition & 1 deletion cmd/controller/app/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

"k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/klog"
"k8s.io/klog/v2"
)

// WaitForAPIServer waits for the API Server's /healthz endpoint to report "ok" before timeout.
Expand Down
2 changes: 1 addition & 1 deletion cmd/controller/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
"github.com/spf13/pflag"
"k8s.io/client-go/tools/leaderelection"
cliflag "k8s.io/component-base/cli/flag"
"k8s.io/klog"
"k8s.io/klog/v2"
)

type DevOpsControllerManagerOptions struct {
Expand Down
13 changes: 7 additions & 6 deletions cmd/controller/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package app

import (
"context"
"fmt"
"github.com/jenkins-zh/jenkins-client/pkg/core"
apiextensions "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
Expand All @@ -29,13 +30,13 @@ import (
"kubesphere.io/devops/pkg/config"
"kubesphere.io/devops/pkg/indexers"
"kubesphere.io/devops/pkg/informers"
"sigs.k8s.io/controller-runtime/pkg/runtime/signals"
"sigs.k8s.io/controller-runtime/pkg/manager/signals"

"github.com/spf13/cobra"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
cliflag "k8s.io/component-base/cli/flag"
"k8s.io/klog"
"k8s.io/klog/klogr"
"k8s.io/klog/v2"
"k8s.io/klog/v2/klogr"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/manager"
)
Expand Down Expand Up @@ -111,7 +112,7 @@ func NewControllerManagerCommand() *cobra.Command {
return cmd
}

func Run(s *options.DevOpsControllerManagerOptions, stopCh <-chan struct{}) error {
func Run(s *options.DevOpsControllerManagerOptions, ctx context.Context) error {
// Init k8s client
kubernetesClient, err := k8s.NewKubernetesClient(s.KubernetesOptions)
if err != nil {
Expand Down Expand Up @@ -194,10 +195,10 @@ func Run(s *options.DevOpsControllerManagerOptions, stopCh <-chan struct{}) erro

// Start cache data after all informer is registered
klog.V(0).Info("Starting cache resource from apiserver...")
informerFactory.Start(stopCh)
informerFactory.Start(ctx.Done())

klog.V(0).Info("Starting the controllers.")
if err = mgr.Start(stopCh); err != nil {
if err = mgr.Start(ctx); err != nil {
klog.Fatalf("unable to run the manager: %v", err)
}

Expand Down
4 changes: 2 additions & 2 deletions config/crd/bases/devops.kubesphere.io_gitrepositories.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ spec:
enough information to retrieve secret in any namespace
properties:
name:
description: Name is unique within a namespace to reference a
description: name is unique within a namespace to reference a
secret resource.
type: string
namespace:
description: Namespace defines the space within which the secret
description: namespace defines the space within which the secret
name must be unique.
type: string
type: object
Expand Down
4 changes: 2 additions & 2 deletions config/crd/bases/devops.kubesphere.io_webhooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ spec:
enough information to retrieve secret in any namespace
properties:
name:
description: Name is unique within a namespace to reference a
description: name is unique within a namespace to reference a
secret resource.
type: string
namespace:
description: Namespace defines the space within which the secret
description: namespace defines the space within which the secret
name must be unique.
type: string
type: object
Expand Down
2 changes: 1 addition & 1 deletion config/dockerfiles/apiserver/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the manager binary
FROM golang:1.16 as builder
FROM golang:1.17 as builder

ARG GOPROXY
WORKDIR /workspace
Expand Down
2 changes: 1 addition & 1 deletion config/dockerfiles/controller-manager/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the manager binary
FROM golang:1.16 as builder
FROM golang:1.17 as builder

ARG GOPROXY
WORKDIR /workspace
Expand Down
4 changes: 2 additions & 2 deletions config/dockerfiles/tools/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the manager binary
FROM golang:1.16 as builder
FROM golang:1.17 as builder

ARG GOPROXY
WORKDIR /workspace
Expand All @@ -17,7 +17,7 @@ COPY pkg/ pkg/
# Build
RUN CGO_ENABLED=0 GO111MODULE=on go build -a -o jwt cmd/tools/jwt/jwt_cmd.go

FROM golang:1.16 as downloader
FROM golang:1.17 as downloader
RUN go install github.com/linuxsuren/http-downloader@v0.0.49
RUN http-downloader install kubesphere-sigs/ks@v0.0.60

Expand Down
6 changes: 3 additions & 3 deletions controllers/addon/addon_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ import (
"bytes"
"context"
"fmt"
"github.com/go-logr/logr"
"html/template"

"github.com/go-logr/logr"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
Expand Down Expand Up @@ -49,8 +50,7 @@ type Reconciler struct {
const defaultNamespace = "default"

// Reconcile responsible for addon lifecycle
func (r *Reconciler) Reconcile(req ctrl.Request) (result ctrl.Result, err error) {
ctx := context.Background()
func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (result ctrl.Result, err error) {
r.log.Info(fmt.Sprintf("start to reconcile addon: %s", req.String()))

addon := &v1alpha3.Addon{}
Expand Down
17 changes: 11 additions & 6 deletions controllers/addon/addon_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package addon
import (
"context"
"fmt"
"testing"

"github.com/go-logr/logr"
"github.com/stretchr/testify/assert"
v1 "k8s.io/api/core/v1"
Expand All @@ -29,7 +31,6 @@ import (
"kubesphere.io/devops/pkg/api/devops/v1alpha3"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
"testing"
)

func TestReconciler_supportedStrategy(t *testing.T) {
Expand Down Expand Up @@ -130,7 +131,11 @@ spec:
},
}
addon := &v1alpha3.Addon{
ObjectMeta: metav1.ObjectMeta{Name: "ks-releaser", Namespace: "default"},
ObjectMeta: metav1.ObjectMeta{
Name: "ks-releaser",
Namespace: "default",
ResourceVersion: "999",
},
Spec: v1alpha3.AddonSpec{
Version: "v0.0.1",
Strategy: v1.LocalObjectReference{
Expand All @@ -155,7 +160,7 @@ spec:
}{{
name: "normal case",
fields: fields{
Client: fake.NewFakeClientWithScheme(schema, strategy.DeepCopy(), addon.DeepCopy()),
Client: fake.NewClientBuilder().WithScheme(schema).WithObjects(strategy.DeepCopy(), addon.DeepCopy()).Build(),
},
args: args{
ctx: context.TODO(),
Expand Down Expand Up @@ -192,14 +197,14 @@ spec:
}, {
name: "update existing addon",
fields: fields{
Client: fake.NewFakeClientWithScheme(schema, strategy.DeepCopy(), &unstructured.Unstructured{Object: map[string]interface{}{
Client: fake.NewClientBuilder().WithScheme(schema).WithObjects(strategy.DeepCopy(), &unstructured.Unstructured{Object: map[string]interface{}{
"apiVersion": "devops.kubesphere.io/v1alpha1",
"kind": "ReleaserController",
"metadata": map[string]interface{}{
"name": "ks-releaser",
"namespace": "default",
},
}}),
}}).Build(),
},
args: args{
ctx: context.TODO(),
Expand Down Expand Up @@ -244,7 +249,7 @@ spec:
}
tt.wantErr(t, r.addonHandle(tt.args.ctx, tt.args.addon), fmt.Sprintf("addonHandle(%v, %v)", tt.args.ctx, tt.args.addon))
if tt.verify != nil {
tt.verify(t, r.Client)
tt.verify(t, tt.fields.Client)
}
})
}
Expand Down
7 changes: 3 additions & 4 deletions controllers/addon/operator_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ package addon
import (
"context"
"fmt"
"strings"

"github.com/go-logr/logr"
v1 "k8s.io/api/core/v1"
apiextensions "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/types"
"kubesphere.io/devops/pkg/api/devops/v1alpha3"
ctrl "sigs.k8s.io/controller-runtime"
"strings"

"sigs.k8s.io/controller-runtime/pkg/client"
)
Expand All @@ -46,9 +47,7 @@ type OperatorCRDReconciler struct {
var supportedOperators = []string{"ReleaserController", "ArgoCD"}

// Reconcile manages addonStrategy according to the CRDs of operators
func (r *OperatorCRDReconciler) Reconcile(req ctrl.Request) (result ctrl.Result, err error) {
ctx := context.Background()

func (r *OperatorCRDReconciler) Reconcile(ctx context.Context, req ctrl.Request) (result ctrl.Result, err error) {
crd := &apiextensions.CustomResourceDefinition{}
if err = r.Client.Get(ctx, req.NamespacedName, crd); err != nil {
err = client.IgnoreNotFound(err)
Expand Down
Loading