Skip to content

Commit

Permalink
Support super-admin config for Kubeadm v1.29
Browse files Browse the repository at this point in the history
Signed-off-by: killianmuldoon <kmuldoon@vmware.com>
  • Loading branch information
killianmuldoon committed Nov 7, 2023
1 parent bd9abfc commit caa2e90
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
6 changes: 6 additions & 0 deletions controlplane/kubeadm/internal/controllers/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ func (r *KubeadmControlPlaneReconciler) upgradeControlPlane(
return ctrl.Result{}, errors.Wrap(err, "failed to set role and role binding for kubeadm")
}

// Ensure kubeadm cluster role & bindings for v1.29+
// as per https://github.com/kubernetes/kubernetes/pull/121305
if err := workloadCluster.AllowBootstrapTokensToGetNodes(ctx); err != nil {
return ctrl.Result{}, errors.Wrap(err, "failed to set role and role binding for kubeadm")
}

if err := workloadCluster.UpdateKubernetesVersionInKubeadmConfigMap(ctx, parsedVersion); err != nil {
return ctrl.Result{}, errors.Wrap(err, "failed to update the kubernetes version in the kubeadm config map")
}
Expand Down
46 changes: 46 additions & 0 deletions controlplane/kubeadm/internal/workload_cluster_rbac.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

"github.com/blang/semver/v4"
"github.com/pkg/errors"
rbac "k8s.io/api/rbac/v1"

Check failure on line 25 in controlplane/kubeadm/internal/workload_cluster_rbac.go

View workflow job for this annotation

GitHub Actions / lint

ST1019: package "k8s.io/api/rbac/v1" is being imported more than once (stylecheck)

Check failure on line 25 in controlplane/kubeadm/internal/workload_cluster_rbac.go

View workflow job for this annotation

GitHub Actions / lint

ST1019: package "k8s.io/api/rbac/v1" is being imported more than once (stylecheck)

Check failure on line 25 in controlplane/kubeadm/internal/workload_cluster_rbac.go

View workflow job for this annotation

GitHub Actions / lint

ST1019: package "k8s.io/api/rbac/v1" is being imported more than once (stylecheck)

Check failure on line 25 in controlplane/kubeadm/internal/workload_cluster_rbac.go

View workflow job for this annotation

GitHub Actions / lint

ST1019: package "k8s.io/api/rbac/v1" is being imported more than once (stylecheck)
rbacv1 "k8s.io/api/rbac/v1"

Check failure on line 26 in controlplane/kubeadm/internal/workload_cluster_rbac.go

View workflow job for this annotation

GitHub Actions / lint

ST1019(related information): other import of "k8s.io/api/rbac/v1" (stylecheck)

Check failure on line 26 in controlplane/kubeadm/internal/workload_cluster_rbac.go

View workflow job for this annotation

GitHub Actions / lint

ST1019(related information): other import of "k8s.io/api/rbac/v1" (stylecheck)

Check failure on line 26 in controlplane/kubeadm/internal/workload_cluster_rbac.go

View workflow job for this annotation

GitHub Actions / lint

ST1019(related information): other import of "k8s.io/api/rbac/v1" (stylecheck)

Check failure on line 26 in controlplane/kubeadm/internal/workload_cluster_rbac.go

View workflow job for this annotation

GitHub Actions / lint

ST1019(related information): other import of "k8s.io/api/rbac/v1" (stylecheck)
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -35,6 +36,14 @@ const (
// GetNodesClusterRoleName defines the name of the ClusterRole and ClusterRoleBinding to get nodes.
GetNodesClusterRoleName = "kubeadm:get-nodes"

// SuperAdminKubeConfigFileName defines name for the kubeconfig aimed to be used by the super-admin of the cluster.
SuperAdminKubeConfigFileName = "super-admin.conf"

// ClusterAdminsGroupAndClusterRoleBinding is the name of the Group used for kubeadm generated cluster
// admin credentials and the name of the ClusterRoleBinding that binds the same Group to the "cluster-admin"
// built-in ClusterRole.
ClusterAdminsGroupAndClusterRoleBinding = "kubeadm:cluster-admins"

// NodesGroup defines the well-known group for all nodes.
NodesGroup = "system:nodes"

Expand Down Expand Up @@ -66,6 +75,43 @@ func (w *Workload) EnsureResource(ctx context.Context, obj client.Object) error
return nil
}

// AllowBootstrapTokensToGetNodes creates RBAC rules to allow Node Bootstrap Tokens to list nodes.

Check failure on line 78 in controlplane/kubeadm/internal/workload_cluster_rbac.go

View workflow job for this annotation

GitHub Actions / lint

exported: comment on exported method Workload.AddSeperateKubeletSuperAdmin should be of the form "AddSeperateKubeletSuperAdmin ..." (revive)

Check warning on line 78 in controlplane/kubeadm/internal/workload_cluster_rbac.go

View workflow job for this annotation

GitHub Actions / lint

exported: comment on exported method Workload.AddSeperateKubeletSuperAdmin should be of the form "AddSeperateKubeletSuperAdmin ..." (revive)

Check failure on line 78 in controlplane/kubeadm/internal/workload_cluster_rbac.go

View workflow job for this annotation

GitHub Actions / lint

exported: comment on exported method Workload.AddSeperateKubeletSuperAdmin should be of the form "AddSeperateKubeletSuperAdmin ..." (revive)

Check warning on line 78 in controlplane/kubeadm/internal/workload_cluster_rbac.go

View workflow job for this annotation

GitHub Actions / lint

exported: comment on exported method Workload.AddSeperateKubeletSuperAdmin should be of the form "AddSeperateKubeletSuperAdmin ..." (revive)
func (w *Workload) AddSeperateKubeletSuperAdmin(ctx context.Context) error {
if err := w.EnsureResource(ctx, &rbacv1.ClusterRole{
ObjectMeta: metav1.ObjectMeta{
Name: GetNodesClusterRoleName,
Namespace: metav1.NamespaceSystem,
},
Rules: []rbacv1.PolicyRule{
{
Verbs: []string{"get"},
APIGroups: []string{""},
Resources: []string{"nodes"},
},
},
}); err != nil {
return err
}

return w.EnsureResource(ctx, &rbac.ClusterRoleBinding{
ObjectMeta: metav1.ObjectMeta{
Name: ClusterAdminsGroupAndClusterRoleBinding,
},
RoleRef: rbac.RoleRef{
APIGroup: rbac.GroupName,
Kind: "ClusterRole",
Name: "cluster-admin",
},
Subjects: []rbac.Subject{
{
Kind: rbac.GroupKind,
Name: ClusterAdminsGroupAndClusterRoleBinding,
},
},
},
)
}

// AllowBootstrapTokensToGetNodes creates RBAC rules to allow Node Bootstrap Tokens to list nodes.
func (w *Workload) AllowBootstrapTokensToGetNodes(ctx context.Context) error {
if err := w.EnsureResource(ctx, &rbacv1.ClusterRole{
Expand Down

0 comments on commit caa2e90

Please sign in to comment.