Skip to content

Commit

Permalink
Combine the cluster / machine permissions per review
Browse files Browse the repository at this point in the history
  • Loading branch information
kylewuolle committed Nov 13, 2024
1 parent 199a194 commit 56bd578
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 35 deletions.
3 changes: 3 additions & 0 deletions api/v1alpha1/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ type ServicesType struct {
// that could be installed on the target cluster.
Services []ServiceSpec `json:"services,omitempty"`

// +kubebuilder:default:=100
// +kubebuilder:validation:Minimum=1
// +kubebuilder:validation:Maximum=2147483646
// ServicesPriority sets the priority for the services defined in this spec.
// Higher value means higher priority and lower means lower.
// In case of conflict with another object managing the service,
Expand Down
10 changes: 6 additions & 4 deletions internal/controller/managedcluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,12 @@ var _ = Describe("ManagedCluster Controller", func() {
Spec: hmc.ManagedClusterSpec{
Template: templateName,
Credential: credentialName,
Services: []hmc.ServiceSpec{
{
Template: svcTemplateName,
Name: "test-svc-name",
ServicesType: hmc.ServicesType{
Services: []hmc.ServiceSpec{
{
Template: svcTemplateName,
Name: "test-svc-name",
},
},
},
},
Expand Down
10 changes: 6 additions & 4 deletions internal/controller/multiclusterservice_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,12 @@ var _ = Describe("MultiClusterService Controller", func() {
},
},
Spec: hmc.MultiClusterServiceSpec{
Services: []hmc.ServiceSpec{
{
Template: serviceTemplateName,
Name: helmChartReleaseName,
ServicesType: hmc.ServicesType{
Services: []hmc.ServiceSpec{
{
Template: serviceTemplateName,
Name: helmChartReleaseName,
},
},
},
},
Expand Down
13 changes: 0 additions & 13 deletions internal/controller/unmanagedcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (
"k8s.io/client-go/tools/clientcmd"
"sigs.k8s.io/cluster-api/api/v1beta1"
"sigs.k8s.io/cluster-api/util/kubeconfig"
"sigs.k8s.io/cluster-api/util/secret"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
Expand Down Expand Up @@ -311,18 +310,6 @@ func (r *UnmanagedClusterReconciler) reconcileDeletion(ctx context.Context, unma
return ctrl.Result{Requeue: true}, fmt.Errorf("failed to delete unmanaged machines: %w", err)
}

if err := r.Delete(ctx, &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Namespace: unmanagedCluster.Namespace,
Name: secret.Name(unmanagedCluster.Name, secret.Kubeconfig),
Labels: map[string]string{
v1beta1.ClusterNameLabel: unmanagedCluster.Name,
},
},
}); err != nil && !apierrors.IsNotFound(err) {
return ctrl.Result{Requeue: true}, fmt.Errorf("failed to delete cluster secret: %w", err)
}

if err := r.Delete(ctx, &v1beta1.Cluster{
ObjectMeta: metav1.ObjectMeta{
Namespace: unmanagedCluster.Namespace,
Expand Down
6 changes: 1 addition & 5 deletions internal/controller/unmanagedcluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,7 @@ var _ = Describe("UnmanagedCluster Controller", func() {
Name: unmanagedClusterName,
Namespace: unmanagedClusterNamespace,
},
Spec: hmc.UnmanagedClusterSpec{
Services: nil,
ServicesPriority: 1,
StopOnConflict: true,
},
Spec: hmc.UnmanagedClusterSpec{},
}
Expect(k8sClient.Create(ctx, resource)).To(Succeed())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,15 @@ spec:
type: object
type: array
servicesPriority:
default: 100
description: |-
ServicesPriority sets the priority for the services defined in this spec.
Higher value means higher priority and lower means lower.
In case of conflict with another object managing the service,
the one with higher priority will get to deploy its services.
format: int32
maximum: 2147483646
minimum: 1
type: integer
stopOnConflict:
default: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,15 @@ spec:
type: object
type: array
servicesPriority:
default: 100
description: |-
ServicesPriority sets the priority for the services defined in this spec.
Higher value means higher priority and lower means lower.
In case of conflict with another object managing the service,
the one with higher priority will get to deploy its services.
format: int32
maximum: 2147483646
minimum: 1
type: integer
stopOnConflict:
default: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,15 @@ spec:
type: object
type: array
servicesPriority:
default: 100
description: |-
ServicesPriority sets the priority for the services defined in this spec.
Higher value means higher priority and lower means lower.
In case of conflict with another object managing the service,
the one with higher priority will get to deploy its services.
format: int32
maximum: 2147483646
minimum: 1
type: integer
stopOnConflict:
default: false
Expand Down
13 changes: 4 additions & 9 deletions templates/provider/hmc/templates/rbac/controller/roles.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ rules:
- cluster.x-k8s.io
resources:
- clusters
verbs: {{ include "rbac.viewerVerbs" . | nindent 4 }}
verbs: {{ include "rbac.editorVerbs" . | nindent 4 }}
- delete
- apiGroups:
- helm.toolkit.fluxcd.io
resources:
Expand Down Expand Up @@ -145,7 +146,8 @@ rules:
- cluster.x-k8s.io
resources:
- machines
verbs: {{ include "rbac.viewerVerbs" . | nindent 4 }}
verbs: {{ include "rbac.editorVerbs" . | nindent 4 }}
- delete
- apiGroups:
- ""
resources:
Expand Down Expand Up @@ -250,13 +252,6 @@ rules:
- get
- patch
- update
- apiGroups:
- cluster.x-k8s.io
resources:
- clusters
- machines
verbs: {{ include "rbac.editorVerbs" . | nindent 4 }}
- delete
- apiGroups:
- config.projectsveltos.io
resources:
Expand Down

0 comments on commit 56bd578

Please sign in to comment.