Skip to content

Commit

Permalink
Upgrade controller-runtime from v0.2.2 to v0.5.0.
Browse files Browse the repository at this point in the history
Reason for upgrade:
The new version uses DynamicRESTMapper as default `RESTMapper` for controller runtime manager. `DynamicRESTMapper` will "reload the delegated `meta.RESTMapper` on a cache miss" (see kubernetes-sigs/controller-runtime#554), which can solve problem that we need to restart HNC after adding a new CRD to create corresponding object reconciler when using controller-runtime v0.2.2 (see details in kubernetes-retired#488).

Incompatibility issues addressed in this PR: see PR description

Tested:

- Unit tests.
- Went through demo script to make sure HNC behaves as expected on a GKE cluster.
- Manually test if the PR solves the restart problem as described in kubernetes-retired#488 with following workflow:
     - Install HNC
     - Install a new CRD
     - Config the new type in `config` singleton

Before this PR, corresponding object reconciler for the new type will not be created unless we restart HNC. After the change, corresponding object reconciler can be created and it reconciles objects of the new type as expected without restarting HNC.

This partly solve:  kubernetes-retired#488
  • Loading branch information
sophieliu15 committed Mar 9, 2020
1 parent 4cba582 commit 66b1901
Show file tree
Hide file tree
Showing 15 changed files with 570 additions and 50 deletions.
2 changes: 1 addition & 1 deletion incubator/hnc/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the manager binary
FROM golang:1.12.5 as builder
FROM golang:1.13 as builder

WORKDIR /workspace
# Copy the Go Modules manifests
Expand Down
6 changes: 3 additions & 3 deletions incubator/hnc/api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion incubator/hnc/cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ steps:
# Get kustomize
export PATH=$$(go env GOPATH)/bin:$$PATH
mkdir -p $$(go env GOPATH)/bin
GO111MODULE=on go get sigs.k8s.io/kustomize/kustomize/v3@v3.2.1
GO111MODULE=on go get sigs.k8s.io/kustomize/kustomize/v3@v3.5.4
# Build manifests
cd multi-tenancy/incubator/hnc
Expand Down
9 changes: 6 additions & 3 deletions incubator/hnc/cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
"sigs.k8s.io/controller-runtime/pkg/metrics"
"sigs.k8s.io/controller-runtime/pkg/webhook"

// +kubebuilder:scaffold:imports
Expand Down Expand Up @@ -59,6 +58,7 @@ func main() {
metricsAddr string
maxReconciles int
enableLeaderElection bool
leaderElectionId string
novalidation bool
debugLogs bool
testLog bool
Expand All @@ -68,6 +68,8 @@ func main() {
flag.StringVar(&metricsAddr, "metrics-addr", ":8080", "The address the metric endpoint binds to.")
flag.BoolVar(&enableLeaderElection, "enable-leader-election", false,
"Enable leader election for controller manager. Enabling this will ensure there is only one active controller manager.")
flag.StringVar(&leaderElectionId, "leader-election-id", "controller-leader-election-helper",
"Leader election id determines the name of the configmap that leader election will use for holding the leader lock.")
flag.BoolVar(&novalidation, "novalidation", false, "Disables validating webhook")
flag.BoolVar(&debugLogs, "debug-logs", false, "Shows verbose logs in a human-friendly format.")
flag.BoolVar(&testLog, "enable-test-log", false, "Enables test log.")
Expand Down Expand Up @@ -99,8 +101,8 @@ func main() {
}
defer exporter.StopMetricsExporter()

prom.DefaultRegisterer = metrics.Registry
promExporter, err := prometheus.NewExporter(prometheus.Options{Registry: metrics.Registry})
prom.DefaultRegisterer = prom.DefaultRegisterer.(*prom.Registry)
promExporter, err := prometheus.NewExporter(prometheus.Options{Registry: prom.DefaultRegisterer.(*prom.Registry)})
view.RegisterExporter(promExporter)

ctrl.SetLogger(zap.Logger(debugLogs))
Expand All @@ -120,6 +122,7 @@ func main() {
Scheme: scheme,
MetricsBindAddress: metricsAddr,
LeaderElection: enableLeaderElection,
LeaderElectionID: leaderElectionId,
})
if err != nil {
setupLog.Error(err, "unable to start manager")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.2.4
controller-gen.kubebuilder.io/version: v0.2.5
creationTimestamp: null
name: hierarchicalnamespaces.hnc.x-k8s.io
spec:
Expand All @@ -25,12 +25,12 @@ spec:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#resources'
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds'
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.2.4
controller-gen.kubebuilder.io/version: v0.2.5
creationTimestamp: null
name: hierarchyconfigurations.hnc.x-k8s.io
spec:
Expand All @@ -22,12 +22,12 @@ spec:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#resources'
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds'
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.2.4
controller-gen.kubebuilder.io/version: v0.2.5
creationTimestamp: null
name: hncconfigurations.hnc.x-k8s.io
spec:
Expand All @@ -23,12 +23,12 @@ spec:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#resources'
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds'
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
Expand Down
1 change: 1 addition & 0 deletions incubator/hnc/config/default/manager_auth_proxy_patch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ spec:
args:
- "--metrics-addr=127.0.0.1:8080"
- "--enable-leader-election"
- "--leader-election-id=hnc-controller-leader-election-helper"
- "--max-reconciles=10"
- "--apiserver-qps-throttle=50"
24 changes: 11 additions & 13 deletions incubator/hnc/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/kubernetes-sigs/multi-tenancy/incubator/hnc

go 1.12
go 1.13

require (
contrib.go.opencensus.io/exporter/prometheus v0.1.0
Expand All @@ -10,22 +10,20 @@ require (
github.com/emicklei/go-restful v2.10.0+incompatible // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/go-logr/logr v0.1.0
github.com/go-openapi/spec v0.19.3 // indirect
github.com/gogo/protobuf v1.2.1 // indirect
github.com/gophercloud/gophercloud v0.4.0 // indirect
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect
github.com/json-iterator/go v1.1.6 // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/onsi/ginkgo v1.10.1
github.com/onsi/gomega v1.7.0
github.com/onsi/ginkgo v1.12.0
github.com/onsi/gomega v1.9.0
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
github.com/prometheus/client_golang v0.9.2
github.com/prometheus/client_golang v1.5.0
github.com/spf13/cobra v0.0.5
go.opencensus.io v0.22.3
k8s.io/api v0.0.0-20190409021203-6e4e0e4f393b
k8s.io/apimachinery v0.0.0-20190404173353-6a84e37a896d
k8s.io/cli-runtime v0.0.0-20190314001948-2899ed30580f
k8s.io/client-go v11.0.1-0.20190409021438-1a26190bd76a+incompatible
sigs.k8s.io/controller-runtime v0.2.2
sigs.k8s.io/kustomize v2.0.3+incompatible // indirect
k8s.io/api v0.17.3
k8s.io/apimachinery v0.17.3
k8s.io/cli-runtime v0.17.3
k8s.io/client-go v0.17.3
sigs.k8s.io/controller-runtime v0.5.0
sigs.k8s.io/controller-tools v0.2.5 // indirect
sigs.k8s.io/kustomize/kustomize/v3 v3.5.4 // indirect
)
Loading

0 comments on commit 66b1901

Please sign in to comment.