Skip to content

Commit ca89e73

Browse files
committed
implement review feedback
1 parent 9995115 commit ca89e73

File tree

1 file changed

+7
-17
lines changed

1 file changed

+7
-17
lines changed

internal/controllers/cluster/controller.go

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"time"
1111

1212
corev1 "k8s.io/api/core/v1"
13-
rbacv1 "k8s.io/api/rbac/v1"
1413
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
1514
apierrors "k8s.io/apimachinery/pkg/api/errors"
1615
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -80,8 +79,6 @@ type ReconcileResult struct {
8079
ReconcileError errutils.ReasonableError
8180
// Config is the selected configuration that was applied to the Cluster, if it could be determined.
8281
Config *dnsv1alpha1.ExternalDNSPurposeConfig
83-
// ConfigIndex is the index of the selected configuration in the DNSServiceConfig, or -1 if no configuration was selected.
84-
ConfigIndex int
8582
// SourceKind is the kind of Flux source that was deployed (HelmRepository, GitRepository, OCIRepository), if any.
8683
SourceKind string
8784
// AccessRequest is the AccessRequest that provides access to the Cluster, if access was successfully obtained.
@@ -170,13 +167,11 @@ func (r *ClusterReconciler) reconcile(ctx context.Context, c *clustersv1alpha1.C
170167
if cfg.PurposeSelector.Matches(c.Spec.Purposes) {
171168
log.Info("Found configuration with matching purpose selector", "configName", cfg.Name, "configIndex", i)
172169
rr.Config = &rr.ProviderConfig.Spec.ExternalDNSForPurposes[i]
173-
rr.ConfigIndex = i
174170
break
175171
}
176172
}
177173
if rr.Config == nil {
178174
log.Info("No configuration with matching purpose selector found")
179-
rr.ConfigIndex = -1
180175
}
181176

182177
if c.DeletionTimestamp.IsZero() && rr.Config != nil {
@@ -219,15 +214,10 @@ func (r *ClusterReconciler) handleCreateOrUpdate(ctx context.Context, c *cluster
219214
Namespace: c.Namespace,
220215
}
221216
ar.Spec.Token = &clustersv1alpha1.TokenConfig{
222-
Permissions: []clustersv1alpha1.PermissionsRequest{
217+
RoleRefs: []commonapi.RoleRef{
223218
{
224-
Rules: []rbacv1.PolicyRule{ // TODO: restrict permissions
225-
{
226-
APIGroups: []string{"*"},
227-
Resources: []string{"*"},
228-
Verbs: []string{"*"},
229-
},
230-
},
219+
Kind: "ClusterRole",
220+
Name: "cluster-admin",
231221
},
232222
},
233223
}
@@ -256,7 +246,7 @@ func (r *ClusterReconciler) handleCreateOrUpdate(ctx context.Context, c *cluster
256246
return rr
257247
}
258248
// remove any secrets that were copied in a previous run but are no longer configured to be copied
259-
rr = r.uncopySecrets(ctx, c, expectedLabels, rr, copied)
249+
rr = r.removeSecrets(ctx, c, expectedLabels, rr, copied)
260250
if rr.ReconcileError != nil || rr.Result.RequeueAfter > 0 {
261251
return rr
262252
}
@@ -296,7 +286,7 @@ func (r *ClusterReconciler) handleDelete(ctx context.Context, c *clustersv1alpha
296286
return rr
297287
}
298288

299-
rr = r.uncopySecrets(ctx, c, expectedLabels, rr, nil)
289+
rr = r.removeSecrets(ctx, c, expectedLabels, rr, nil)
300290
if rr.ReconcileError != nil || rr.Result.RequeueAfter > 0 {
301291
return rr
302292
}
@@ -698,10 +688,10 @@ func (r *ClusterReconciler) undeployHelmChartSource(ctx context.Context, c *clus
698688
return rr
699689
}
700690

701-
// uncopySecrets removes all secrets from the Cluster namespace where the labels indicate they were created by this controller for the given Cluster.
691+
// removeSecrets removes all secrets from the Cluster namespace where the labels indicate they were created by this controller for the given Cluster.
702692
// Secrets listed in 'keep' are not deleted.
703693
// It does not wait for their deletion.
704-
func (r *ClusterReconciler) uncopySecrets(ctx context.Context, c *clustersv1alpha1.Cluster, expectedLabels map[string]string, rr ReconcileResult, keep sets.Set[string]) ReconcileResult {
694+
func (r *ClusterReconciler) removeSecrets(ctx context.Context, c *clustersv1alpha1.Cluster, expectedLabels map[string]string, rr ReconcileResult, keep sets.Set[string]) ReconcileResult {
705695
log := logging.FromContextOrPanic(ctx)
706696

707697
// list existing secrets to detect obsolete ones

0 commit comments

Comments
 (0)