Skip to content

Commit 55b2c9c

Browse files
authored
Merge pull request #308 from furkatgofurov7/bump-beta-capi-1-6
✨Bump CAPI to v1.6.0-rc.1
2 parents d254cf7 + 91b7103 commit 55b2c9c

24 files changed

+540
-677
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ GOTESTSUM_VER := v1.6.4
8686
GOTESTSUM_BIN := gotestsum
8787
GOTESTSUM := $(TOOLS_BIN_DIR)/$(GOTESTSUM_BIN)-$(GOTESTSUM_VER)
8888

89-
GINKGO_VER := v2.12.0
89+
GINKGO_VER := v2.13.1
9090
GINKGO_BIN := ginkgo
9191
GINKGO := $(TOOLS_BIN_DIR)/$(GINKGO_BIN)-$(GINKGO_VER)
9292

@@ -331,6 +331,7 @@ generate-go: $(CONTROLLER_GEN) ## Runs Go related generate targets for the opera
331331
.PHONY: generate-manifests
332332
generate-manifests: $(CONTROLLER_GEN) ## Generate manifests for the operator e.g. CRD, RBAC etc.
333333
$(CONTROLLER_GEN) \
334+
paths=./cmd \
334335
paths=./api/... \
335336
paths=./internal/controller/... \
336337
paths=./internal/webhook/... \

api/v1alpha2/addonprovider_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,7 @@ type AddonProviderList struct {
5353
metav1.ListMeta `json:"metadata,omitempty"`
5454
Items []AddonProvider `json:"items"`
5555
}
56+
57+
func init() {
58+
objectTypes = append(objectTypes, &AddonProvider{}, &AddonProviderList{})
59+
}

api/v1alpha2/bootstrapprovider_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,7 @@ type BootstrapProviderList struct {
5353
metav1.ListMeta `json:"metadata,omitempty"`
5454
Items []BootstrapProvider `json:"items"`
5555
}
56+
57+
func init() {
58+
objectTypes = append(objectTypes, &BootstrapProvider{}, &BootstrapProviderList{})
59+
}

api/v1alpha2/controlplaneprovider_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,7 @@ type ControlPlaneProviderList struct {
5353
metav1.ListMeta `json:"metadata,omitempty"`
5454
Items []ControlPlaneProvider `json:"items"`
5555
}
56+
57+
func init() {
58+
objectTypes = append(objectTypes, &ControlPlaneProvider{}, &ControlPlaneProviderList{})
59+
}

api/v1alpha2/coreprovider_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,7 @@ type CoreProviderList struct {
5353
metav1.ListMeta `json:"metadata,omitempty"`
5454
Items []CoreProvider `json:"items"`
5555
}
56+
57+
func init() {
58+
objectTypes = append(objectTypes, &CoreProvider{}, &CoreProviderList{})
59+
}

api/v1alpha2/groupversion_info.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,13 @@ var (
3434

3535
// AddToScheme adds the types in this group-version to the given scheme.
3636
AddToScheme = SchemeBuilder.AddToScheme
37+
38+
objectTypes = []runtime.Object{}
3739
)
3840

3941
// Adds the list of known types to api.Scheme.
4042
func addKnownTypes(scheme *runtime.Scheme) error {
41-
scheme.AddKnownTypes(GroupVersion,
42-
&CoreProvider{}, &CoreProviderList{},
43-
&BootstrapProvider{}, &BootstrapProviderList{},
44-
&ControlPlaneProvider{}, &ControlPlaneProviderList{},
45-
&InfrastructureProvider{}, &InfrastructureProviderList{},
46-
&AddonProvider{}, &AddonProviderList{},
47-
)
48-
43+
scheme.AddKnownTypes(GroupVersion, objectTypes...)
4944
metav1.AddToGroupVersion(scheme, GroupVersion)
5045

5146
return nil

api/v1alpha2/infrastructureprovider_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,7 @@ type InfrastructureProviderList struct {
5353
metav1.ListMeta `json:"metadata,omitempty"`
5454
Items []InfrastructureProvider `json:"items"`
5555
}
56+
57+
func init() {
58+
objectTypes = append(objectTypes, &InfrastructureProvider{}, &InfrastructureProviderList{})
59+
}

cmd/main.go

Lines changed: 55 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ package main
1919
import (
2020
"flag"
2121
"fmt"
22-
"net/http"
2322
"os"
23+
goruntime "runtime"
2424
"time"
2525

2626
"github.com/spf13/pflag"
@@ -34,11 +34,14 @@ import (
3434
"sigs.k8s.io/cluster-api-operator/internal/webhook"
3535
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
3636
clusterctlv1 "sigs.k8s.io/cluster-api/cmd/clusterctl/api/v1alpha3"
37+
"sigs.k8s.io/cluster-api/util/flags"
3738
"sigs.k8s.io/cluster-api/version"
3839
ctrl "sigs.k8s.io/controller-runtime"
40+
cache "sigs.k8s.io/controller-runtime/pkg/cache"
3941
"sigs.k8s.io/controller-runtime/pkg/client"
4042
"sigs.k8s.io/controller-runtime/pkg/controller"
4143
"sigs.k8s.io/controller-runtime/pkg/healthz"
44+
ctrlwebhook "sigs.k8s.io/controller-runtime/pkg/webhook"
4245

4346
operatorv1alpha1 "sigs.k8s.io/cluster-api-operator/api/v1alpha1"
4447
operatorv1 "sigs.k8s.io/cluster-api-operator/api/v1alpha2"
@@ -51,18 +54,20 @@ var (
5154
setupLog = ctrl.Log.WithName("setup")
5255

5356
// flags.
54-
metricsBindAddr string
5557
enableLeaderElection bool
5658
leaderElectionLeaseDuration time.Duration
5759
leaderElectionRenewDeadline time.Duration
5860
leaderElectionRetryPeriod time.Duration
5961
watchFilterValue string
62+
watchNamespace string
6063
profilerAddress string
64+
enableContentionProfiling bool
6165
concurrencyNumber int
6266
syncPeriod time.Duration
6367
webhookPort int
6468
webhookCertDir string
6569
healthAddr string
70+
diagnosticsOptions = flags.DiagnosticsOptions{}
6671
)
6772

6873
func init() {
@@ -78,9 +83,6 @@ func init() {
7883

7984
// InitFlags initializes the flags.
8085
func InitFlags(fs *pflag.FlagSet) {
81-
fs.StringVar(&metricsBindAddr, "metrics-bind-addr", "localhost:8080",
82-
"The address the metric endpoint binds to.")
83-
8486
fs.BoolVar(&enableLeaderElection, "leader-elect", false,
8587
"Enable leader election for controller manager. Enabling this will ensure there is only one active controller manager.")
8688

@@ -96,9 +98,15 @@ func InitFlags(fs *pflag.FlagSet) {
9698
fs.StringVar(&watchFilterValue, "watch-filter", "",
9799
fmt.Sprintf("Label value that the controller watches to reconcile cluster-api objects. Label key is always %s. If unspecified, the controller watches for all cluster-api objects.", clusterv1.WatchLabel))
98100

101+
fs.StringVar(&watchNamespace, "namespace", "",
102+
"Namespace that the controller watches to reconcile cluster-api objects. If unspecified, the controller watches for cluster-api objects across all namespaces.")
103+
99104
fs.StringVar(&profilerAddress, "profiler-address", "",
100105
"Bind address to expose the pprof profiler (e.g. localhost:6060)")
101106

107+
fs.BoolVar(&enableContentionProfiling, "contention-profiling", false,
108+
"Enable block profiling")
109+
102110
fs.IntVar(&concurrencyNumber, "concurrency", 1,
103111
"Number of core resources to process simultaneously")
104112

@@ -112,6 +120,8 @@ func InitFlags(fs *pflag.FlagSet) {
112120

113121
fs.StringVar(&healthAddr, "health-addr", ":9440",
114122
"The address the health endpoint binds to.")
123+
124+
flags.AddDiagnosticsOptions(fs, &diagnosticsOptions)
115125
}
116126

117127
func main() {
@@ -120,37 +130,52 @@ func main() {
120130
pflag.Parse()
121131

122132
ctrl.SetLogger(klogr.New())
133+
restConfig := ctrl.GetConfigOrDie()
123134

124-
if profilerAddress != "" {
125-
klog.Infof("Profiler listening for requests at %s", profilerAddress)
135+
diagnosticsOpts := flags.GetDiagnosticsOptions(diagnosticsOptions)
126136

127-
go func() {
128-
server := &http.Server{
129-
Addr: profilerAddress,
130-
ReadHeaderTimeout: 3 * time.Second,
131-
}
137+
var watchNamespaces map[string]cache.Config
138+
if watchNamespace != "" {
139+
watchNamespaces = map[string]cache.Config{
140+
watchNamespace: {},
141+
}
142+
}
132143

133-
klog.Info(server.ListenAndServe())
134-
}()
144+
if enableContentionProfiling {
145+
goruntime.SetBlockProfileRate(1)
135146
}
136147

137-
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
138-
Scheme: scheme,
139-
MetricsBindAddress: metricsBindAddr,
140-
LeaderElection: enableLeaderElection,
141-
LeaderElectionID: "controller-leader-election-capi-operator",
142-
LeaseDuration: &leaderElectionLeaseDuration,
143-
RenewDeadline: &leaderElectionRenewDeadline,
144-
RetryPeriod: &leaderElectionRetryPeriod,
145-
SyncPeriod: &syncPeriod,
146-
ClientDisableCacheFor: []client.Object{
147-
&corev1.ConfigMap{},
148-
&corev1.Secret{},
149-
},
150-
Port: webhookPort,
151-
CertDir: webhookCertDir,
148+
ctrlOptions := ctrl.Options{
149+
Scheme: scheme,
150+
LeaderElection: enableLeaderElection,
151+
LeaderElectionID: "controller-leader-election-capi-operator",
152+
LeaseDuration: &leaderElectionLeaseDuration,
153+
RenewDeadline: &leaderElectionRenewDeadline,
154+
RetryPeriod: &leaderElectionRetryPeriod,
152155
HealthProbeBindAddress: healthAddr,
153-
})
156+
PprofBindAddress: profilerAddress,
157+
Metrics: diagnosticsOpts,
158+
Cache: cache.Options{
159+
DefaultNamespaces: watchNamespaces,
160+
SyncPeriod: &syncPeriod,
161+
},
162+
Client: client.Options{
163+
Cache: &client.CacheOptions{
164+
DisableFor: []client.Object{
165+
&corev1.ConfigMap{},
166+
&corev1.Secret{},
167+
},
168+
},
169+
},
170+
WebhookServer: ctrlwebhook.NewServer(
171+
ctrlwebhook.Options{
172+
Port: webhookPort,
173+
CertDir: webhookCertDir,
174+
},
175+
),
176+
}
177+
178+
mgr, err := ctrl.NewManager(restConfig, ctrlOptions)
154179
if err != nil {
155180
setupLog.Error(err, "unable to start manager")
156181
os.Exit(1)

config/manager/manager.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,14 @@ spec:
1818
containers:
1919
- command:
2020
- /manager
21+
args:
22+
- "--leader-elect"
2123
image: controller:latest
2224
name: manager
25+
ports:
26+
- containerPort: 8443
27+
name: metrics
28+
protocol: TCP
2329
resources:
2430
limits:
2531
cpu: 100m

config/rbac/role.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
apiVersion: rbac.authorization.k8s.io/v1
33
kind: ClusterRole
44
metadata:
5-
creationTimestamp: null
65
name: manager-role
76
rules:
87
- apiGroups:

docs/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ spec:
152152
- --metrics-bind-addr=:8080
153153
- --leader-elect
154154
- --leader-elect-retry-period=5s
155+
- "--diagnostics-address=${CAPI_OPERATOR_DIAGNOSTICS_ADDRESS:=:8443}"
156+
- "--insecure-diagnostics=${CAPI_OPERATOR_INSECURE_DIAGNOSTICS:=false}"
155157
- --v=5
156158
env:...
157159
```

0 commit comments

Comments
 (0)