Skip to content

Commit

Permalink
Merge pull request #344 from furkatgofurov7/capi1-6-missing-changes
Browse files Browse the repository at this point in the history
✨ Missing changes from CAPI v1.6.0 bump
  • Loading branch information
alexander-demicev authored Jun 4, 2024
2 parents 2545c38 + 1463df9 commit 45d668e
Show file tree
Hide file tree
Showing 18 changed files with 182 additions and 49 deletions.
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ GOLANGCI_LINT_VER := v1.55.1
GOLANGCI_LINT_BIN := golangci-lint
GOLANGCI_LINT := $(abspath $(TOOLS_BIN_DIR)/$(GOLANGCI_LINT_BIN))

GINKGO_VER := v2.16.0
GINKGO_VER := v2.17.1
GINKGO_BIN := ginkgo
GINKGO := $(abspath $(TOOLS_BIN_DIR)/$(GINKGO_BIN)-$(GINKGO_VER))
GINKGO_PKG := github.com/onsi/ginkgo/v2/ginkgo
Expand Down Expand Up @@ -158,6 +158,7 @@ generate-manifests: $(addprefix generate-manifests-,$(ALL_GENERATE_MODULES)) ##
generate-manifests-rke2-bootstrap: $(CONTROLLER_GEN) ## Generate manifests e.g. CRD, RBAC etc. for rke2 bootstrap provider
$(MAKE) clean-generated-yaml SRC_DIRS="./bootstrap/config/crd/bases"
$(CONTROLLER_GEN) \
paths=./bootstrap \
paths=./bootstrap/api/... \
paths=./bootstrap/internal/controllers/... \
crd:crdVersions=v1 \
Expand All @@ -171,6 +172,7 @@ generate-manifests-rke2-bootstrap: $(CONTROLLER_GEN) ## Generate manifests e.g.
generate-manifests-rke2-control-plane: $(CONTROLLER_GEN) ## Generate manifests e.g. CRD, RBAC etc. for RKE2 control plane provider
$(MAKE) clean-generated-yaml SRC_DIRS="./controlplane/config/crd/bases"
$(CONTROLLER_GEN) \
paths=./controlplane \
paths=./controlplane/api/... \
paths=./controlplane/internal/controllers/... \
paths=./controlplane/internal/webhooks/... \
Expand Down
18 changes: 14 additions & 4 deletions bootstrap/api/v1beta1/groupversion_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,27 @@ limitations under the License.
package v1beta1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/scheme"
)

var (
// GroupVersion is group version used to register these objects.
GroupVersion = schema.GroupVersion{Group: "bootstrap.cluster.x-k8s.io", Version: "v1beta1"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme.
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
// schemeBuilder is used to add go types to the GroupVersionKind scheme.
schemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)

// AddToScheme adds the types in this group-version to the given scheme.
AddToScheme = SchemeBuilder.AddToScheme
AddToScheme = schemeBuilder.AddToScheme

objectTypes = []runtime.Object{}
)

func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(GroupVersion, objectTypes...)
metav1.AddToGroupVersion(scheme, GroupVersion)

return nil
}
2 changes: 1 addition & 1 deletion bootstrap/api/v1beta1/rke2config_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,5 +398,5 @@ type ComponentConfig struct {
}

func init() {
SchemeBuilder.Register(&RKE2Config{}, &RKE2ConfigList{})
objectTypes = append(objectTypes, &RKE2Config{}, &RKE2ConfigList{})
}
2 changes: 1 addition & 1 deletion bootstrap/api/v1beta1/rke2configtemplate_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,5 @@ type RKE2ConfigTemplateResource struct {
}

func init() {
SchemeBuilder.Register(&RKE2ConfigTemplate{}, &RKE2ConfigTemplateList{})
objectTypes = append(objectTypes, &RKE2ConfigTemplate{}, &RKE2ConfigTemplateList{})
}
3 changes: 1 addition & 2 deletions bootstrap/api/v1beta1/webhook_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ var _ = BeforeSuite(func() {
Expect(cfg).NotTo(BeNil())

scheme := runtime.NewScheme()
err = AddToScheme(scheme)
Expect(err).NotTo(HaveOccurred())
Expect(AddToScheme(scheme)).To(Succeed())

err = admissionv1beta1.AddToScheme(scheme)
Expect(err).NotTo(HaveOccurred())
Expand Down
6 changes: 5 additions & 1 deletion bootstrap/config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@ spec:
- /manager
args:
- --leader-elect
- --metrics-bind-addr=localhost:8080
- "--diagnostics-address=${CAPRKE2_DIAGNOSTICS_ADDRESS:=:8443}"
- "--insecure-diagnostics=${CAPRKE2_INSECURE_DIAGNOSTICS:=false}"
image: controller:latest
name: manager
ports:
- containerPort: 9440
name: healthz
protocol: TCP
- containerPort: 8443
name: metrics
protocol: TCP
readinessProbe:
httpGet:
path: /readyz
Expand Down
12 changes: 12 additions & 0 deletions bootstrap/config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ rules:
- patch
- update
- watch
- apiGroups:
- authentication.k8s.io
resources:
- tokenreviews
verbs:
- create
- apiGroups:
- authorization.k8s.io
resources:
- subjectaccessreviews
verbs:
- create
- apiGroups:
- bootstrap.cluster.x-k8s.io
resources:
Expand Down
39 changes: 29 additions & 10 deletions bootstrap/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client"
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
"sigs.k8s.io/controller-runtime/pkg/webhook"

clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
"sigs.k8s.io/cluster-api/util/flags"

bootstrapv1alpha1 "github.com/rancher-sandbox/cluster-api-provider-rke2/bootstrap/api/v1alpha1"
bootstrapv1 "github.com/rancher-sandbox/cluster-api-provider-rke2/bootstrap/api/v1beta1"
Expand All @@ -54,7 +54,6 @@ var (
setupLog = ctrl.Log.WithName("setup")

// flags.
metricsBindAddr string
enableLeaderElection bool
leaderElectionLeaseDuration time.Duration
leaderElectionRenewDeadline time.Duration
Expand All @@ -63,9 +62,12 @@ var (
profilerAddress string
concurrencyNumber int
syncPeriod time.Duration
watchNamespace string
webhookPort int
webhookCertDir string
healthAddr string

diagnosticsOptions = flags.DiagnosticsOptions{}
)

func init() {
Expand All @@ -82,9 +84,6 @@ func init() {

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

fs.BoolVar(&enableLeaderElection, "leader-elect", false,
"Enable leader election for controller manager. Enabling this will ensure there is only one active controller manager.")

Expand All @@ -109,22 +108,42 @@ func InitFlags(fs *pflag.FlagSet) {
fs.DurationVar(&syncPeriod, "sync-period", consts.DefaultSyncPeriod,
"The minimum interval at which watched resources are reconciled (e.g. 15m)")

fs.StringVar(&watchNamespace, "namespace", "",
"Namespace that the controller watches to reconcile cluster-api objects. If unspecified, the controller watches for cluster-api objects across all namespaces.") //nolint:lll

fs.IntVar(&webhookPort, "webhook-port", consts.DefaultWebhookPort, "Webhook Server port")

fs.StringVar(&webhookCertDir, "webhook-cert-dir", "/tmp/k8s-webhook-server/serving-certs/",
"Webhook cert dir, only used when webhook-port is specified.")

fs.StringVar(&healthAddr, "health-addr", ":9440",
"The address the health endpoint binds to.")

flags.AddDiagnosticsOptions(fs, &diagnosticsOptions)
}

// Add RBAC for the authorized diagnostics endpoint.
// +kubebuilder:rbac:groups=authentication.k8s.io,resources=tokenreviews,verbs=create
// +kubebuilder:rbac:groups=authorization.k8s.io,resources=subjectaccessreviews,verbs=create

func main() {
InitFlags(pflag.CommandLine)
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
pflag.Parse()

ctrl.SetLogger(klog.Background())

diagnosticsOpts := flags.GetDiagnosticsOptions(diagnosticsOptions)

var watchNamespaces map[string]cache.Config

if watchNamespace != "" {
setupLog.Info("Watching cluster-api objects only in namespace for reconciliation", "namespace", watchNamespace)
watchNamespaces = map[string]cache.Config{
watchNamespace: {},
}
}

if profilerAddress != "" {
klog.Infof("Profiler listening for requests at %s", profilerAddress)

Expand All @@ -134,17 +153,17 @@ func main() {
}

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
Metrics: metricsserver.Options{
BindAddress: metricsBindAddr,
},
Scheme: scheme,
LeaderElection: enableLeaderElection,
LeaderElectionID: "rke2-bootstrap-manager-leader-election-capi",
PprofBindAddress: profilerAddress,
LeaseDuration: &leaderElectionLeaseDuration,
RenewDeadline: &leaderElectionRenewDeadline,
RetryPeriod: &leaderElectionRetryPeriod,
Metrics: diagnosticsOpts,
Cache: cache.Options{
SyncPeriod: &syncPeriod,
DefaultNamespaces: watchNamespaces,
SyncPeriod: &syncPeriod,
},
Client: client.Options{
Cache: &client.CacheOptions{
Expand Down
18 changes: 14 additions & 4 deletions controlplane/api/v1beta1/groupversion_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,27 @@ limitations under the License.
package v1beta1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/scheme"
)

var (
// GroupVersion is group version used to register these objects.
GroupVersion = schema.GroupVersion{Group: "controlplane.cluster.x-k8s.io", Version: "v1beta1"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme.
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
// schemeBuilder is used to add go types to the GroupVersionKind scheme.
schemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)

// AddToScheme adds the types in this group-version to the given scheme.
AddToScheme = SchemeBuilder.AddToScheme
AddToScheme = schemeBuilder.AddToScheme

objectTypes = []runtime.Object{}
)

func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(GroupVersion, objectTypes...)
metav1.AddToGroupVersion(scheme, GroupVersion)

return nil
}
2 changes: 1 addition & 1 deletion controlplane/api/v1beta1/rke2controlplane_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ const (
)

func init() { //nolint:gochecknoinits
SchemeBuilder.Register(&RKE2ControlPlane{}, &RKE2ControlPlaneList{})
objectTypes = append(objectTypes, &RKE2ControlPlane{}, &RKE2ControlPlaneList{})
}

// GetConditions returns the list of conditions for a RKE2ControlPlane object.
Expand Down
2 changes: 1 addition & 1 deletion controlplane/api/v1beta1/rke2controlplanetemplate_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,5 @@ type RKE2ControlPlaneTemplateList struct {
}

func init() { //nolint:gochecknoinits
SchemeBuilder.Register(&RKE2ControlPlaneTemplate{}, &RKE2ControlPlaneTemplateList{})
objectTypes = append(objectTypes, &RKE2ControlPlaneTemplate{}, &RKE2ControlPlaneTemplateList{})
}
3 changes: 1 addition & 2 deletions controlplane/api/v1beta1/webhook_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ var _ = BeforeSuite(func() {
Expect(cfg).NotTo(BeNil())

scheme := runtime.NewScheme()
err = AddToScheme(scheme)
Expect(err).NotTo(HaveOccurred())
Expect(AddToScheme(scheme)).To(Succeed())

err = admissionv1beta1.AddToScheme(scheme)
Expect(err).NotTo(HaveOccurred())
Expand Down
6 changes: 5 additions & 1 deletion controlplane/config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ spec:
- /manager
args:
- "--leader-elect"
- "--metrics-bind-addr=localhost:8080"
- "--diagnostics-address=${CAPRKE2_DIAGNOSTICS_ADDRESS:=:8443}"
- "--insecure-diagnostics=${CAPRKE2_INSECURE_DIAGNOSTICS:=false}"
image: controller:latest
name: manager
env:
Expand All @@ -42,6 +43,9 @@ spec:
- containerPort: 9440
name: healthz
protocol: TCP
- containerPort: 8443
name: metrics
protocol: TCP
readinessProbe:
httpGet:
path: /readyz
Expand Down
12 changes: 12 additions & 0 deletions controlplane/config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ rules:
- patch
- update
- watch
- apiGroups:
- authentication.k8s.io
resources:
- tokenreviews
verbs:
- create
- apiGroups:
- authorization.k8s.io
resources:
- subjectaccessreviews
verbs:
- create
- apiGroups:
- bootstrap.cluster.x-k8s.io
resources:
Expand Down
Loading

0 comments on commit 45d668e

Please sign in to comment.