Skip to content

Commit 6fa8833

Browse files
Bump CAPI to v1.6.0-beta.0
Signed-off-by: Furkat Gofurov <[email protected]>
1 parent c1e3f00 commit 6fa8833

18 files changed

+517
-623
lines changed

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 & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +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)
50-
5145
return nil
5246
}

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: 92 additions & 28 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,6 +34,7 @@ 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"
3940
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -50,18 +51,20 @@ var (
5051
setupLog = ctrl.Log.WithName("setup")
5152

5253
// flags.
53-
metricsBindAddr string
5454
enableLeaderElection bool
5555
leaderElectionLeaseDuration time.Duration
5656
leaderElectionRenewDeadline time.Duration
5757
leaderElectionRetryPeriod time.Duration
5858
watchFilterValue string
59+
watchNamespace string
5960
profilerAddress string
61+
enableContentionProfiling bool
6062
concurrencyNumber int
6163
syncPeriod time.Duration
6264
webhookPort int
6365
webhookCertDir string
6466
healthAddr string
67+
diagnosticsOptions = flags.DiagnosticsOptions{}
6568
)
6669

6770
func init() {
@@ -77,8 +80,6 @@ func init() {
7780

7881
// InitFlags initializes the flags.
7982
func InitFlags(fs *pflag.FlagSet) {
80-
fs.StringVar(&metricsBindAddr, "metrics-bind-addr", ":8080",
81-
"The address the metric endpoint binds to.")
8283

8384
fs.BoolVar(&enableLeaderElection, "leader-elect", false,
8485
"Enable leader election for controller manager. Enabling this will ensure there is only one active controller manager.")
@@ -95,9 +96,15 @@ func InitFlags(fs *pflag.FlagSet) {
9596
fs.StringVar(&watchFilterValue, "watch-filter", "",
9697
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))
9798

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

105+
fs.BoolVar(&enableContentionProfiling, "contention-profiling", false,
106+
"Enable block profiling")
107+
101108
fs.IntVar(&concurrencyNumber, "concurrency", 1,
102109
"Number of core resources to process simultaneously")
103110

@@ -111,45 +118,102 @@ func InitFlags(fs *pflag.FlagSet) {
111118

112119
fs.StringVar(&healthAddr, "health-addr", ":9440",
113120
"The address the health endpoint binds to.")
121+
122+
flags.AddDiagnosticsOptions(fs, &diagnosticsOptions)
114123
}
115124

125+
// Add RBAC for the authorized diagnostics endpoint.
126+
// +kubebuilder:rbac:groups=authentication.k8s.io,resources=tokenreviews,verbs=create
127+
// +kubebuilder:rbac:groups=authorization.k8s.io,resources=subjectaccessreviews,verbs=create
128+
116129
func main() {
117130
InitFlags(pflag.CommandLine)
118131
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
119132
pflag.Parse()
120133

121134
ctrl.SetLogger(klogr.New())
135+
restConfig := ctrl.GetConfigOrDie()
122136

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

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

132-
klog.Info(server.ListenAndServe())
133-
}()
146+
if enableContentionProfiling {
147+
goruntime.SetBlockProfileRate(1)
134148
}
135149

136-
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
137-
Scheme: scheme,
138-
MetricsBindAddress: metricsBindAddr,
139-
LeaderElection: enableLeaderElection,
140-
LeaderElectionID: "controller-leader-election-capi-operator",
141-
LeaseDuration: &leaderElectionLeaseDuration,
142-
RenewDeadline: &leaderElectionRenewDeadline,
143-
RetryPeriod: &leaderElectionRetryPeriod,
144-
SyncPeriod: &syncPeriod,
145-
ClientDisableCacheFor: []client.Object{
146-
&corev1.ConfigMap{},
147-
&corev1.Secret{},
150+
// req, _ := labels.NewRequirement(clusterv1.ClusterNameLabel, selection.Exists, nil)
151+
// clusterSecretCacheSelector := labels.NewSelector().Add(*req)
152+
153+
ctrlOptions := ctrl.Options{
154+
Scheme: scheme,
155+
LeaderElection: enableLeaderElection,
156+
LeaderElectionID: "controller-leader-election-capi-operator",
157+
LeaseDuration: &leaderElectionLeaseDuration,
158+
RenewDeadline: &leaderElectionRenewDeadline,
159+
RetryPeriod: &leaderElectionRetryPeriod,
160+
Client: client.Options{
161+
Cache: &client.CacheOptions{
162+
DisableFor: []client.Object{
163+
&corev1.ConfigMap{},
164+
&corev1.Secret{},
165+
},
166+
},
148167
},
149-
Port: webhookPort,
150-
CertDir: webhookCertDir,
168+
// WebhookServer: webhook.NewServer(
169+
// webhook.Options{
170+
// Port: webhookPort,
171+
// CertDir: webhookCertDir,
172+
// },
173+
// ),
151174
HealthProbeBindAddress: healthAddr,
152-
})
175+
PprofBindAddress: profilerAddress,
176+
Metrics: diagnosticsOpts,
177+
// Cache: cache.Options{
178+
// DefaultNamespaces: watchNamespaces,
179+
// SyncPeriod: &syncPeriod,
180+
// ByObject: map[client.Object]cache.ByObject{
181+
// // Note: Only Secrets with the cluster name label are cached.
182+
// // The default client of the manager won't use the cache for secrets at all (see Client.Cache.DisableFor).
183+
// // The cached secrets will only be used by the secretCachingClient we create below.
184+
// &corev1.Secret{}: {
185+
// Label: clusterSecretCacheSelector,
186+
// },
187+
// },
188+
// },
189+
}
190+
191+
// mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
192+
// Scheme: scheme,
193+
// MetricsBindAddress: metricsBindAddr,
194+
// LeaderElection: enableLeaderElection,
195+
// LeaderElectionID: "controller-leader-election-capi-operator",
196+
// LeaseDuration: &leaderElectionLeaseDuration,
197+
// RenewDeadline: &leaderElectionRenewDeadline,
198+
// RetryPeriod: &leaderElectionRetryPeriod,
199+
// Client: client.Options{
200+
// Cache: &client.CacheOptions{
201+
// DisableFor: []client.Object{
202+
// &corev1.ConfigMap{},
203+
// &corev1.Secret{},
204+
// },
205+
// },
206+
// },
207+
// WebhookServer: webhook.NewServer(
208+
// webhook.Options{
209+
// Port: webhookPort,
210+
// CertDir: webhookCertDir,
211+
// },
212+
// ),
213+
// HealthProbeBindAddress: healthAddr,
214+
// })
215+
216+
mgr, err := ctrl.NewManager(restConfig, ctrlOptions)
153217
if err != nil {
154218
setupLog.Error(err, "unable to start manager")
155219
os.Exit(1)

cmd/plugin/cmd/root.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package cmd
1818

1919
import (
20+
"context"
2021
"flag"
2122
"fmt"
2223
"os"
@@ -78,7 +79,7 @@ func init() {
7879
func initConfig() {
7980
// check if the CLUSTERCTL_LOG_LEVEL was set via env var or in the config file
8081
if *verbosity == 0 { //nolint:nestif
81-
configClient, err := configclient.New(cfgFile)
82+
configClient, err := configclient.New(context.Background(), cfgFile)
8283
if err == nil {
8384
v, err := configClient.Variables().Get("CLUSTERCTL_LOG_LEVEL")
8485
if err == nil && v != "" {

0 commit comments

Comments
 (0)