diff --git a/config/root-phase0/bootstrap.go b/config/root-phase0/bootstrap.go index 4aaf4dce4b8..0a5add55bc9 100644 --- a/config/root-phase0/bootstrap.go +++ b/config/root-phase0/bootstrap.go @@ -52,14 +52,14 @@ func Bootstrap(ctx context.Context, kcpClient kcpclient.Interface, rootDiscovery // set LogicalCluster to Initializing return wait.PollImmediateUntilWithContext(ctx, time.Millisecond*100, func(ctx context.Context) (done bool, err error) { logger := klog.FromContext(ctx).WithValues("bootstrapping", "root-phase0") - this, err := kcpClient.CoreV1alpha1().LogicalClusters().Get(ctx, corev1alpha1.LogicalClusterName, metav1.GetOptions{}) + logicalCluster, err := kcpClient.CoreV1alpha1().LogicalClusters().Get(ctx, corev1alpha1.LogicalClusterName, metav1.GetOptions{}) if err != nil { logger.Error(err, "failed to get this workspace in root") return false, nil } - if this.Status.Phase == corev1alpha1.LogicalClusterPhaseScheduling { - this.Status.Phase = corev1alpha1.LogicalClusterPhaseInitializing - _, err = kcpClient.CoreV1alpha1().LogicalClusters().UpdateStatus(ctx, this, metav1.UpdateOptions{}) + if logicalCluster.Status.Phase == corev1alpha1.LogicalClusterPhaseScheduling { + logicalCluster.Status.Phase = corev1alpha1.LogicalClusterPhaseInitializing + _, err = kcpClient.CoreV1alpha1().LogicalClusters().UpdateStatus(ctx, logicalCluster, metav1.UpdateOptions{}) if err != nil { logger.Error(err, "failed to update LogicalCluster root:cluster") return false, nil diff --git a/pkg/admission/logicalcluster/admission.go b/pkg/admission/logicalcluster/admission.go index 10862ac68f4..c0febd51279 100644 --- a/pkg/admission/logicalcluster/admission.go +++ b/pkg/admission/logicalcluster/admission.go @@ -85,8 +85,8 @@ func (o *plugin) Admit(ctx context.Context, a admission.Attributes, _ admission. if !ok { return fmt.Errorf("unexpected type %T", a.GetObject()) } - this := &corev1alpha1.LogicalCluster{} - if err := runtime.DefaultUnstructuredConverter.FromUnstructured(u.Object, this); err != nil { + logicalCluster := &corev1alpha1.LogicalCluster{} + if err := runtime.DefaultUnstructuredConverter.FromUnstructured(u.Object, logicalCluster); err != nil { return fmt.Errorf("failed to convert unstructured to LogicalCluster: %w", err) } @@ -103,14 +103,14 @@ func (o *plugin) Admit(ctx context.Context, a admission.Attributes, _ admission. } // we only admit at state transition to initializing - transitioningToInitializing := old.Status.Phase != corev1alpha1.LogicalClusterPhaseInitializing && this.Status.Phase == corev1alpha1.LogicalClusterPhaseInitializing + transitioningToInitializing := old.Status.Phase != corev1alpha1.LogicalClusterPhaseInitializing && logicalCluster.Status.Phase == corev1alpha1.LogicalClusterPhaseInitializing if !transitioningToInitializing { return nil } - this.Status.Initializers = this.Spec.Initializers + logicalCluster.Status.Initializers = logicalCluster.Spec.Initializers - return updateUnstructured(u, this) + return updateUnstructured(u, logicalCluster) } return nil @@ -137,8 +137,8 @@ func (o *plugin) Validate(ctx context.Context, a admission.Attributes, _ admissi if !ok { return fmt.Errorf("unexpected type %T", a.GetObject()) } - this := &corev1alpha1.LogicalCluster{} - if err := runtime.DefaultUnstructuredConverter.FromUnstructured(u.Object, this); err != nil { + logicalCluster := &corev1alpha1.LogicalCluster{} + if err := runtime.DefaultUnstructuredConverter.FromUnstructured(u.Object, logicalCluster); err != nil { return fmt.Errorf("failed to convert unstructured to LogicalCluster: %w", err) } @@ -152,46 +152,46 @@ func (o *plugin) Validate(ctx context.Context, a admission.Attributes, _ admissi } oldSpec := toSet(old.Spec.Initializers) - newSpec := toSet(this.Spec.Initializers) + newSpec := toSet(logicalCluster.Spec.Initializers) oldStatus := toSet(old.Status.Initializers) - newStatus := toSet(this.Status.Initializers) + newStatus := toSet(logicalCluster.Status.Initializers) if !oldSpec.Equal(newSpec) { return admission.NewForbidden(a, fmt.Errorf("spec.initializers is immutable")) } - transitioningToInitializing := old.Status.Phase != corev1alpha1.LogicalClusterPhaseInitializing && this.Status.Phase == corev1alpha1.LogicalClusterPhaseInitializing + transitioningToInitializing := old.Status.Phase != corev1alpha1.LogicalClusterPhaseInitializing && logicalCluster.Status.Phase == corev1alpha1.LogicalClusterPhaseInitializing if transitioningToInitializing && !newSpec.Equal(newStatus) { return admission.NewForbidden(a, fmt.Errorf("status.initializers do not equal spec.initializers")) } - if !transitioningToInitializing && this.Status.Phase == corev1alpha1.LogicalClusterPhaseInitializing && !oldStatus.IsSuperset(newStatus) { + if !transitioningToInitializing && logicalCluster.Status.Phase == corev1alpha1.LogicalClusterPhaseInitializing && !oldStatus.IsSuperset(newStatus) { return admission.NewForbidden(a, fmt.Errorf("status.initializers must not grow")) } - if this.Status.Phase != corev1alpha1.LogicalClusterPhaseInitializing && !oldStatus.Equal(newStatus) { + if logicalCluster.Status.Phase != corev1alpha1.LogicalClusterPhaseInitializing && !oldStatus.Equal(newStatus) { return admission.NewForbidden(a, fmt.Errorf("status.initializers is immutable after initilization")) } - if old.Status.Phase == corev1alpha1.LogicalClusterPhaseInitializing && this.Status.Phase != corev1alpha1.LogicalClusterPhaseInitializing { - if len(this.Status.Initializers) > 0 { + if old.Status.Phase == corev1alpha1.LogicalClusterPhaseInitializing && logicalCluster.Status.Phase != corev1alpha1.LogicalClusterPhaseInitializing { + if len(logicalCluster.Status.Initializers) > 0 { return admission.NewForbidden(a, fmt.Errorf("status.initializers is not empty")) } } - if phaseOrdinal[old.Status.Phase] > phaseOrdinal[this.Status.Phase] { - return admission.NewForbidden(a, fmt.Errorf("cannot transition from %q to %q", old.Status.Phase, this.Status.Phase)) + if phaseOrdinal[old.Status.Phase] > phaseOrdinal[logicalCluster.Status.Phase] { + return admission.NewForbidden(a, fmt.Errorf("cannot transition from %q to %q", old.Status.Phase, logicalCluster.Status.Phase)) } return nil case admission.Delete: - this, err := o.logicalClusterLister.Cluster(clusterName).Get(corev1alpha1.LogicalClusterName) + logicalCluster, err := o.logicalClusterLister.Cluster(clusterName).Get(corev1alpha1.LogicalClusterName) if err != nil { return fmt.Errorf("LogicalCluster cannot be deleted: %w", err) } groups := sets.NewString(a.GetUserInfo().GetGroups()...) - if !this.Spec.DirectlyDeletable && !groups.Has(kuser.SystemPrivilegedGroup) && !groups.Has(bootstrap.SystemLogicalClusterAdmin) { + if !logicalCluster.Spec.DirectlyDeletable && !groups.Has(kuser.SystemPrivilegedGroup) && !groups.Has(bootstrap.SystemLogicalClusterAdmin) { return admission.NewForbidden(a, fmt.Errorf("LogicalCluster cannot be deleted")) } diff --git a/pkg/admission/logicalcluster/admission_test.go b/pkg/admission/logicalcluster/admission_test.go index c28641198f3..6b22e57c3ae 100644 --- a/pkg/admission/logicalcluster/admission_test.go +++ b/pkg/admission/logicalcluster/admission_test.go @@ -432,9 +432,9 @@ func (l fakeLogicalClusterClusterLister) List(selector labels.Selector) (ret []* func (l fakeLogicalClusterClusterLister) Cluster(cluster logicalcluster.Name) corev1alpha1listers.LogicalClusterLister { var perCluster []*corev1alpha1.LogicalCluster - for _, this := range l { - if logicalcluster.From(this) == cluster { - perCluster = append(perCluster, this) + for _, logicalCluster := range l { + if logicalcluster.From(logicalCluster) == cluster { + perCluster = append(perCluster, logicalCluster) } } return fakeLogicalClusterLister(perCluster) diff --git a/pkg/admission/namespacelifecycle/admission.go b/pkg/admission/namespacelifecycle/admission.go index f3b7606c0ed..07e0012346c 100644 --- a/pkg/admission/namespacelifecycle/admission.go +++ b/pkg/admission/namespacelifecycle/admission.go @@ -112,14 +112,14 @@ func (l *workspaceNamespaceLifecycle) Admit(ctx context.Context, a admission.Att return apierrors.NewInternalError(err) } - this, err := l.getLogicalCluster(clusterName) + logicalCluster, err := l.getLogicalCluster(clusterName) // The shard hosting the workspace could be down, // just return error from legacy namespace lifecycle admission in this case if err != nil && !apierrors.IsNotFound(err) { return admissionErr } - if this.DeletionTimestamp.IsZero() { + if logicalCluster.DeletionTimestamp.IsZero() { return admissionErr } diff --git a/pkg/admission/pathannotation/pathannotation_admission.go b/pkg/admission/pathannotation/pathannotation_admission.go index a2ca87bbbe2..abad22ecdcd 100644 --- a/pkg/admission/pathannotation/pathannotation_admission.go +++ b/pkg/admission/pathannotation/pathannotation_admission.go @@ -101,13 +101,13 @@ func (p *pathAnnotationPlugin) Admit(ctx context.Context, a admission.Attributes return nil } - this, err := p.logicalClusterLister.Cluster(clusterName).Get(corev1alpha1.LogicalClusterName) + logicalCluster, err := p.logicalClusterLister.Cluster(clusterName).Get(corev1alpha1.LogicalClusterName) if err != nil { return admission.NewForbidden(a, fmt.Errorf("cannot get this workspace: %w", err)) } - thisPath := this.Annotations[core.LogicalClusterPathAnnotationKey] + thisPath := logicalCluster.Annotations[core.LogicalClusterPathAnnotationKey] if thisPath == "" { - thisPath = logicalcluster.From(this).Path().String() + thisPath = logicalcluster.From(logicalCluster).Path().String() } if thisPath != "" && value != thisPath { @@ -142,13 +142,13 @@ func (p *pathAnnotationPlugin) Validate(ctx context.Context, a admission.Attribu value, found := u.GetAnnotations()[core.LogicalClusterPathAnnotationKey] if pathAnnotationResources.Has(a.GetResource().GroupResource().String()) || found { - this, err := p.logicalClusterLister.Cluster(clusterName).Get(corev1alpha1.LogicalClusterName) + logicalCluster, err := p.logicalClusterLister.Cluster(clusterName).Get(corev1alpha1.LogicalClusterName) if err != nil { return admission.NewForbidden(a, fmt.Errorf("cannot get this workspace: %w", err)) } - thisPath := this.Annotations[core.LogicalClusterPathAnnotationKey] + thisPath := logicalCluster.Annotations[core.LogicalClusterPathAnnotationKey] if thisPath == "" { - thisPath = logicalcluster.From(this).Path().String() + thisPath = logicalcluster.From(logicalCluster).Path().String() } if value != thisPath { diff --git a/pkg/admission/workspace/admission.go b/pkg/admission/workspace/admission.go index 337734c7bd7..1b00a106450 100644 --- a/pkg/admission/workspace/admission.go +++ b/pkg/admission/workspace/admission.go @@ -109,11 +109,11 @@ func (o *workspace) Admit(ctx context.Context, a admission.Attributes, _ admissi // copy required groups from LogicalCluster to new child-Worksapce if _, found := cw.Annotations[authorization.RequiredGroupsAnnotationKey]; !found || !isSystemPrivileged { - this, err := o.logicalClusterLister.Cluster(clusterName).Get(corev1alpha1.LogicalClusterName) + logicalCluster, err := o.logicalClusterLister.Cluster(clusterName).Get(corev1alpha1.LogicalClusterName) if err != nil { return admission.NewForbidden(a, err) } - if thisValue, found := this.Annotations[authorization.RequiredGroupsAnnotationKey]; found { + if thisValue, found := logicalCluster.Annotations[authorization.RequiredGroupsAnnotationKey]; found { if cw.Annotations == nil { cw.Annotations = map[string]string{} } @@ -200,11 +200,11 @@ func (o *workspace) Validate(ctx context.Context, a admission.Attributes, _ admi // check that required groups match with LogicalCluster if !isSystemPrivileged { - this, err := o.logicalClusterLister.Cluster(clusterName).Get(corev1alpha1.LogicalClusterName) + logicalCluster, err := o.logicalClusterLister.Cluster(clusterName).Get(corev1alpha1.LogicalClusterName) if err != nil { return admission.NewForbidden(a, err) } - expected := this.Annotations[authorization.RequiredGroupsAnnotationKey] + expected := logicalCluster.Annotations[authorization.RequiredGroupsAnnotationKey] if cw.Annotations[authorization.RequiredGroupsAnnotationKey] != expected { return admission.NewForbidden(a, fmt.Errorf("missing required groups annotation %s=%s", authorization.RequiredGroupsAnnotationKey, expected)) } diff --git a/pkg/admission/workspace/admission_test.go b/pkg/admission/workspace/admission_test.go index 29528d39dee..520a8f8f260 100644 --- a/pkg/admission/workspace/admission_test.go +++ b/pkg/admission/workspace/admission_test.go @@ -713,9 +713,9 @@ func (l fakeLogicalClusterClusterLister) List(selector labels.Selector) (ret []* func (l fakeLogicalClusterClusterLister) Cluster(cluster logicalcluster.Name) corev1alpha1listers.LogicalClusterLister { var perCluster []*corev1alpha1.LogicalCluster - for _, this := range l { - if logicalcluster.From(this) == cluster { - perCluster = append(perCluster, this) + for _, logicalCluster := range l { + if logicalcluster.From(logicalCluster) == cluster { + perCluster = append(perCluster, logicalCluster) } } return fakeLogicalClusterLister(perCluster) diff --git a/pkg/admission/workspacetypeexists/admission.go b/pkg/admission/workspacetypeexists/admission.go index 75abde8ec7c..1a9571814b1 100644 --- a/pkg/admission/workspacetypeexists/admission.go +++ b/pkg/admission/workspacetypeexists/admission.go @@ -126,7 +126,7 @@ func (o *workspacetypeExists) Admit(ctx context.Context, a admission.Attributes, return nil } - this, err := o.logicalClusterLister.Cluster(clusterName).Get(corev1alpha1.LogicalClusterName) + logicalCluster, err := o.logicalClusterLister.Cluster(clusterName).Get(corev1alpha1.LogicalClusterName) if err != nil { return admission.NewForbidden(a, fmt.Errorf("workspace type cannot be resolved: %w", err)) } @@ -134,7 +134,7 @@ func (o *workspacetypeExists) Admit(ctx context.Context, a admission.Attributes, // if the user has not provided any type, use the default from the parent workspace empty := tenancyv1beta1.WorkspaceTypeReference{} if ws.Spec.Type == empty { - typeAnnotation, found := this.Annotations[tenancyv1beta1.LogicalClusterTypeAnnotationKey] + typeAnnotation, found := logicalCluster.Annotations[tenancyv1beta1.LogicalClusterTypeAnnotationKey] if !found { return admission.NewForbidden(a, fmt.Errorf("annotation %s on LogicalCluster must be set", tenancyv1beta1.LogicalClusterTypeAnnotationKey)) } @@ -155,9 +155,9 @@ func (o *workspacetypeExists) Admit(ctx context.Context, a admission.Attributes, } } - thisPath := this.Annotations[core.LogicalClusterPathAnnotationKey] + thisPath := logicalCluster.Annotations[core.LogicalClusterPathAnnotationKey] if thisPath == "" { - thisPath = logicalcluster.From(this).Path().String() + thisPath = logicalcluster.From(logicalCluster).Path().String() } cwt, err := o.resolveTypeRef(logicalcluster.NewPath(thisPath), tenancyv1alpha1.WorkspaceTypeReference{ @@ -292,11 +292,11 @@ func (o *workspacetypeExists) Validate(ctx context.Context, a admission.Attribut } // validate whether the workspace type is allowed in its parent, and the workspace type allows that parent - this, err := o.logicalClusterLister.Cluster(clusterName).Get(corev1alpha1.LogicalClusterName) + logicalCluster, err := o.logicalClusterLister.Cluster(clusterName).Get(corev1alpha1.LogicalClusterName) if err != nil { return admission.NewForbidden(a, fmt.Errorf("workspace type cannot be resolved: %w", err)) } - typeAnnotation, found := this.Annotations[tenancyv1beta1.LogicalClusterTypeAnnotationKey] + typeAnnotation, found := logicalCluster.Annotations[tenancyv1beta1.LogicalClusterTypeAnnotationKey] if !found { return admission.NewForbidden(a, fmt.Errorf("annotation %s on LogicalCluster must be set", tenancyv1beta1.LogicalClusterTypeAnnotationKey)) } diff --git a/pkg/admission/workspacetypeexists/admission_test.go b/pkg/admission/workspacetypeexists/admission_test.go index ed973cc835b..1d4f1005ea4 100644 --- a/pkg/admission/workspacetypeexists/admission_test.go +++ b/pkg/admission/workspacetypeexists/admission_test.go @@ -511,9 +511,9 @@ func (l fakeLogicalClusterClusterLister) List(selector labels.Selector) (ret []* func (l fakeLogicalClusterClusterLister) Cluster(cluster logicalcluster.Name) corev1alpha1listers.LogicalClusterLister { var perCluster []*corev1alpha1.LogicalCluster - for _, this := range l { - if logicalcluster.From(this) == cluster { - perCluster = append(perCluster, this) + for _, logicalCluster := range l { + if logicalcluster.From(logicalCluster) == cluster { + perCluster = append(perCluster, logicalCluster) } } return fakeLogicalClusterLister(perCluster) diff --git a/pkg/authorization/requiredgroups_authorizer.go b/pkg/authorization/requiredgroups_authorizer.go index e10f7dbc620..f594fdf434b 100644 --- a/pkg/authorization/requiredgroups_authorizer.go +++ b/pkg/authorization/requiredgroups_authorizer.go @@ -87,7 +87,7 @@ func (a *requiredGroupsAuthorizer) Authorize(ctx context.Context, attr authorize case isUser: // get logical cluster with required group annotation - this, err := a.getLogicalCluster(cluster.Name) + logicalCluster, err := a.getLogicalCluster(cluster.Name) if err != nil { if errors.IsNotFound(err) { return authorizer.DecisionNoOpinion, "logical cluster not found", nil @@ -96,7 +96,7 @@ func (a *requiredGroupsAuthorizer) Authorize(ctx context.Context, attr authorize } // check required groups - value, found := this.Annotations[RequiredGroupsAnnotationKey] + value, found := logicalCluster.Annotations[RequiredGroupsAnnotationKey] if !found { return DelegateAuthorization("logical cluster does not require groups", a.delegate).Authorize(ctx, attr) } @@ -104,11 +104,11 @@ func (a *requiredGroupsAuthorizer) Authorize(ctx context.Context, attr authorize for _, set := range disjunctiveClauses { groups := strings.Split(set, ",") if sets.NewString(attr.GetUser().GetGroups()...).HasAll(groups...) { - return DelegateAuthorization(fmt.Sprintf("user is member of required groups: %s", this.Annotations[RequiredGroupsAnnotationKey]), a.delegate).Authorize(ctx, attr) + return DelegateAuthorization(fmt.Sprintf("user is member of required groups: %s", logicalCluster.Annotations[RequiredGroupsAnnotationKey]), a.delegate).Authorize(ctx, attr) } } - return authorizer.DecisionDeny, fmt.Sprintf("user is not a member of required groups: %s", this.Annotations[RequiredGroupsAnnotationKey]), nil + return authorizer.DecisionDeny, fmt.Sprintf("user is not a member of required groups: %s", logicalCluster.Annotations[RequiredGroupsAnnotationKey]), nil } return authorizer.DecisionNoOpinion, WorkspaceAccessNotPermittedReason, nil diff --git a/pkg/index/index.go b/pkg/index/index.go index 4f2eb286df8..25589827e0a 100644 --- a/pkg/index/index.go +++ b/pkg/index/index.go @@ -134,8 +134,8 @@ func (c *State) DeleteWorkspace(shard string, ws *tenancyv1beta1.Workspace) { } } -func (c *State) UpsertLogicalCluster(shard string, this *corev1alpha1.LogicalCluster) { - clusterName := logicalcluster.From(this) +func (c *State) UpsertLogicalCluster(shard string, logicalCluster *corev1alpha1.LogicalCluster) { + clusterName := logicalcluster.From(logicalCluster) c.lock.RLock() got := c.clusterShards[clusterName] @@ -148,8 +148,8 @@ func (c *State) UpsertLogicalCluster(shard string, this *corev1alpha1.LogicalClu } } -func (c *State) DeleteLogicalCluster(shard string, this *corev1alpha1.LogicalCluster) { - clusterName := logicalcluster.From(this) +func (c *State) DeleteLogicalCluster(shard string, logicalCluster *corev1alpha1.LogicalCluster) { + clusterName := logicalcluster.From(logicalCluster) c.lock.RLock() got := c.clusterShards[clusterName] diff --git a/pkg/proxy/index/index_controller.go b/pkg/proxy/index/index_controller.go index a5db606ef86..a916d669535 100644 --- a/pkg/proxy/index/index_controller.go +++ b/pkg/proxy/index/index_controller.go @@ -242,19 +242,19 @@ func (c *Controller) process(ctx context.Context, key string) error { twInformer := corev1alpha1informers.NewLogicalClusterClusterInformer(client, resyncPeriod, nil) twInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{ AddFunc: func(obj interface{}) { - this := obj.(*corev1alpha1.LogicalCluster) - c.state.UpsertLogicalCluster(shard.Name, this) + logicalCluster := obj.(*corev1alpha1.LogicalCluster) + c.state.UpsertLogicalCluster(shard.Name, logicalCluster) }, UpdateFunc: func(old, obj interface{}) { - this := obj.(*corev1alpha1.LogicalCluster) - c.state.UpsertLogicalCluster(shard.Name, this) + logicalCluster := obj.(*corev1alpha1.LogicalCluster) + c.state.UpsertLogicalCluster(shard.Name, logicalCluster) }, DeleteFunc: func(obj interface{}) { if final, ok := obj.(cache.DeletedFinalStateUnknown); ok { obj = final.Obj } - this := obj.(*corev1alpha1.LogicalCluster) - c.state.DeleteLogicalCluster(shard.Name, this) + logicalCluster := obj.(*corev1alpha1.LogicalCluster) + c.state.DeleteLogicalCluster(shard.Name, logicalCluster) }, }) diff --git a/pkg/reconciler/core/logicalcluster/logicalcluster_reconcile.go b/pkg/reconciler/core/logicalcluster/logicalcluster_reconcile.go index 71539519a9b..2384aae7862 100644 --- a/pkg/reconciler/core/logicalcluster/logicalcluster_reconcile.go +++ b/pkg/reconciler/core/logicalcluster/logicalcluster_reconcile.go @@ -32,10 +32,10 @@ const ( ) type reconciler interface { - reconcile(ctx context.Context, this *corev1alpha1.LogicalCluster) (reconcileStatus, error) + reconcile(ctx context.Context, logicalCluster *corev1alpha1.LogicalCluster) (reconcileStatus, error) } -func (c *Controller) reconcile(ctx context.Context, this *corev1alpha1.LogicalCluster) (bool, error) { +func (c *Controller) reconcile(ctx context.Context, logicalCluster *corev1alpha1.LogicalCluster) (bool, error) { reconcilers := []reconciler{ &metaDataReconciler{}, &phaseReconciler{}, @@ -48,7 +48,7 @@ func (c *Controller) reconcile(ctx context.Context, this *corev1alpha1.LogicalCl for _, r := range reconcilers { var err error var status reconcileStatus - status, err = r.reconcile(ctx, this) + status, err = r.reconcile(ctx, logicalCluster) if err != nil { errs = append(errs, err) } diff --git a/pkg/reconciler/core/logicalcluster/logicalcluster_reconcile_url.go b/pkg/reconciler/core/logicalcluster/logicalcluster_reconcile_url.go index e9f434fd9a0..1db5f1931c8 100644 --- a/pkg/reconciler/core/logicalcluster/logicalcluster_reconcile_url.go +++ b/pkg/reconciler/core/logicalcluster/logicalcluster_reconcile_url.go @@ -29,7 +29,7 @@ type urlReconciler struct { shardExternalURL func() string } -func (r *urlReconciler) reconcile(ctx context.Context, this *corev1alpha1.LogicalCluster) (reconcileStatus, error) { - this.Status.URL = strings.TrimSuffix(r.shardExternalURL(), "/") + logicalcluster.From(this).Path().RequestPath() +func (r *urlReconciler) reconcile(ctx context.Context, logicalCluster *corev1alpha1.LogicalCluster) (reconcileStatus, error) { + logicalCluster.Status.URL = strings.TrimSuffix(r.shardExternalURL(), "/") + logicalcluster.From(logicalCluster).Path().RequestPath() return reconcileStatusContinue, nil } diff --git a/pkg/reconciler/tenancy/initialization/apibinder_initializer_controller.go b/pkg/reconciler/tenancy/initialization/apibinder_initializer_controller.go index e087aacc615..f8b74acd343 100644 --- a/pkg/reconciler/tenancy/initialization/apibinder_initializer_controller.go +++ b/pkg/reconciler/tenancy/initialization/apibinder_initializer_controller.go @@ -179,7 +179,7 @@ func (b *APIBinder) enqueueAPIBinding(obj interface{}, logger logr.Logger) { logger = logging.WithObject(logger, apiBinding) clusterName := logicalcluster.From(apiBinding) - this, err := b.getLogicalCluster(clusterName) + logicalCluster, err := b.getLogicalCluster(clusterName) if err != nil { if apierrors.IsNotFound(err) { // The workspace was deleted or is no longer initializing, so we can safely ignore this event. @@ -189,7 +189,7 @@ func (b *APIBinder) enqueueAPIBinding(obj interface{}, logger logr.Logger) { return // nothing we can do here } - b.enqueueLogicalCluster(this, logger) + b.enqueueLogicalCluster(logicalCluster, logger) } // enqueueWorkspaceTypes enqueues all clusterworkspaces (which are only those that are initializing, because of diff --git a/pkg/reconciler/tenancy/initialization/apibinder_initializer_reconcile.go b/pkg/reconciler/tenancy/initialization/apibinder_initializer_reconcile.go index ac2d3471d30..dc077ab20ee 100644 --- a/pkg/reconciler/tenancy/initialization/apibinder_initializer_reconcile.go +++ b/pkg/reconciler/tenancy/initialization/apibinder_initializer_reconcile.go @@ -42,8 +42,8 @@ import ( "github.com/kcp-dev/kcp/pkg/logging" ) -func (b *APIBinder) reconcile(ctx context.Context, this *corev1alpha1.LogicalCluster) error { - annotationValue, found := this.Annotations[v1beta1.LogicalClusterTypeAnnotationKey] +func (b *APIBinder) reconcile(ctx context.Context, logicalCluster *corev1alpha1.LogicalCluster) error { + annotationValue, found := logicalCluster.Annotations[v1beta1.LogicalClusterTypeAnnotationKey] if !found { return nil } @@ -57,7 +57,7 @@ func (b *APIBinder) reconcile(ctx context.Context, this *corev1alpha1.LogicalClu ) var errors []error - clusterName := logicalcluster.From(this) + clusterName := logicalcluster.From(logicalCluster) logger.V(2).Info("initializing APIBindings for workspace") // Start with the WorkspaceType specified by the ClusterWorkspace @@ -66,7 +66,7 @@ func (b *APIBinder) reconcile(ctx context.Context, this *corev1alpha1.LogicalClu logger.Error(err, "error getting WorkspaceType") conditions.MarkFalse( - this, + logicalCluster, tenancyv1alpha1.WorkspaceAPIBindingsInitialized, tenancyv1alpha1.WorkspaceInitializedWorkspaceTypeInvalid, conditionsv1alpha1.ConditionSeverityError, @@ -84,7 +84,7 @@ func (b *APIBinder) reconcile(ctx context.Context, this *corev1alpha1.LogicalClu logger.Error(err, "error resolving transitive types") conditions.MarkFalse( - this, + logicalCluster, tenancyv1alpha1.WorkspaceAPIBindingsInitialized, tenancyv1alpha1.WorkspaceInitializedWorkspaceTypeInvalid, conditionsv1alpha1.ConditionSeverityError, @@ -196,7 +196,7 @@ func (b *APIBinder) reconcile(ctx context.Context, this *corev1alpha1.LogicalClu logger.Error(utilerrors.NewAggregate(errors), "error initializing APIBindings") conditions.MarkFalse( - this, + logicalCluster, tenancyv1alpha1.WorkspaceAPIBindingsInitialized, tenancyv1alpha1.WorkspaceInitializedAPIBindingErrors, conditionsv1alpha1.ConditionSeverityError, @@ -235,7 +235,7 @@ func (b *APIBinder) reconcile(ctx context.Context, this *corev1alpha1.LogicalClu sort.Strings(incomplete) conditions.MarkFalse( - this, + logicalCluster, tenancyv1alpha1.WorkspaceAPIBindingsInitialized, tenancyv1alpha1.WorkspaceInitializedWaitingOnAPIBindings, conditionsv1alpha1.ConditionSeverityInfo, @@ -245,7 +245,7 @@ func (b *APIBinder) reconcile(ctx context.Context, this *corev1alpha1.LogicalClu return nil } - this.Status.Initializers = initialization.EnsureInitializerAbsent(tenancyv1alpha1.WorkspaceAPIBindingsInitializer, this.Status.Initializers) + logicalCluster.Status.Initializers = initialization.EnsureInitializerAbsent(tenancyv1alpha1.WorkspaceAPIBindingsInitializer, logicalCluster.Status.Initializers) return nil } diff --git a/pkg/reconciler/tenancy/workspace/workspace_reconcile_phase.go b/pkg/reconciler/tenancy/workspace/workspace_reconcile_phase.go index f0393ba8c58..df1bea8ef81 100644 --- a/pkg/reconciler/tenancy/workspace/workspace_reconcile_phase.go +++ b/pkg/reconciler/tenancy/workspace/workspace_reconcile_phase.go @@ -49,7 +49,7 @@ func (r *phaseReconciler) reconcile(ctx context.Context, workspace *tenancyv1bet case corev1alpha1.LogicalClusterPhaseInitializing: logger = logger.WithValues("cluster", workspace.Status.Cluster) - this, err := r.getLogicalCluster(ctx, logicalcluster.NewPath(workspace.Status.Cluster)) + logicalCluster, err := r.getLogicalCluster(ctx, logicalcluster.NewPath(workspace.Status.Cluster)) if err != nil && !apierrors.IsNotFound(err) { return reconcileStatusStopAndRequeue, err } else if apierrors.IsNotFound(err) { @@ -58,10 +58,10 @@ func (r *phaseReconciler) reconcile(ctx context.Context, workspace *tenancyv1bet return reconcileStatusContinue, nil } - workspace.Status.Initializers = this.Status.Initializers + workspace.Status.Initializers = logicalCluster.Status.Initializers if initializers := workspace.Status.Initializers; len(initializers) > 0 { - after := time.Since(this.CreationTimestamp.Time) / 5 + after := time.Since(logicalCluster.CreationTimestamp.Time) / 5 if max := time.Minute * 10; after > max { after = max } @@ -79,7 +79,7 @@ func (r *phaseReconciler) reconcile(ctx context.Context, workspace *tenancyv1bet if !workspace.DeletionTimestamp.IsZero() { logger = logger.WithValues("cluster", workspace.Status.Cluster) - this, err := r.getLogicalCluster(ctx, logicalcluster.NewPath(workspace.Status.Cluster)) + logicalCluster, err := r.getLogicalCluster(ctx, logicalcluster.NewPath(workspace.Status.Cluster)) if err != nil && !apierrors.IsNotFound(err) { return reconcileStatusStopAndRequeue, err } else if apierrors.IsNotFound(err) { @@ -89,11 +89,11 @@ func (r *phaseReconciler) reconcile(ctx context.Context, workspace *tenancyv1bet } if !conditions.IsTrue(workspace, tenancyv1alpha1.WorkspaceContentDeleted) { - after := time.Since(this.CreationTimestamp.Time) / 5 + after := time.Since(logicalCluster.CreationTimestamp.Time) / 5 if max := time.Minute * 10; after > max { after = max } - cond := conditions.Get(this, tenancyv1alpha1.WorkspaceContentDeleted) + cond := conditions.Get(logicalCluster, tenancyv1alpha1.WorkspaceContentDeleted) if cond != nil { conditions.Set(workspace, cond) logger.V(3).Info("LogicalCluster is still deleting, requeueing", "reason", cond.Reason, "message", cond.Message, "after", after) diff --git a/pkg/reconciler/tenancy/workspace/workspace_reconcile_scheduling.go b/pkg/reconciler/tenancy/workspace/workspace_reconcile_scheduling.go index 8ecb35f64ed..c7f0d094399 100644 --- a/pkg/reconciler/tenancy/workspace/workspace_reconcile_scheduling.go +++ b/pkg/reconciler/tenancy/workspace/workspace_reconcile_scheduling.go @@ -248,7 +248,7 @@ func (r *schedulingReconciler) createLogicalCluster(ctx context.Context, shard * canonicalPath = logicalcluster.NewPath(parent.Annotations[core.LogicalClusterPathAnnotationKey]).Join(workspace.Name) } } - this := &corev1alpha1.LogicalCluster{ + logicalCluster := &corev1alpha1.LogicalCluster{ ObjectMeta: metav1.ObjectMeta{ Name: corev1alpha1.LogicalClusterName, Annotations: map[string]string{ @@ -268,15 +268,15 @@ func (r *schedulingReconciler) createLogicalCluster(ctx context.Context, shard * }, } if owner, found := workspace.Annotations[tenancyv1alpha1.ExperimentalWorkspaceOwnerAnnotationKey]; found { - this.Annotations[tenancyv1alpha1.ExperimentalWorkspaceOwnerAnnotationKey] = owner + logicalCluster.Annotations[tenancyv1alpha1.ExperimentalWorkspaceOwnerAnnotationKey] = owner } if groups, found := workspace.Annotations[authorization.RequiredGroupsAnnotationKey]; found { - this.Annotations[authorization.RequiredGroupsAnnotationKey] = groups + logicalCluster.Annotations[authorization.RequiredGroupsAnnotationKey] = groups } // add initializers var err error - this.Spec.Initializers, err = LogicalClustersInitializers(r.transitiveTypeResolver, r.getWorkspaceType, logicalcluster.NewPath(workspace.Spec.Type.Path), string(workspace.Spec.Type.Name)) + logicalCluster.Spec.Initializers, err = LogicalClustersInitializers(r.transitiveTypeResolver, r.getWorkspaceType, logicalcluster.NewPath(workspace.Spec.Type.Path), string(workspace.Spec.Type.Name)) if err != nil { return err } @@ -285,14 +285,14 @@ func (r *schedulingReconciler) createLogicalCluster(ctx context.Context, shard * if err != nil { return err } - _, err = logicalClusterAdminClient.Cluster(cluster).CoreV1alpha1().LogicalClusters().Create(ctx, this, metav1.CreateOptions{}) + _, err = logicalClusterAdminClient.Cluster(cluster).CoreV1alpha1().LogicalClusters().Create(ctx, logicalCluster, metav1.CreateOptions{}) if apierrors.IsAlreadyExists(err) { existing, getErr := logicalClusterAdminClient.Cluster(cluster).CoreV1alpha1().LogicalClusters().Get(ctx, corev1alpha1.LogicalClusterName, metav1.GetOptions{}) if getErr != nil { return getErr } - if equality.Semantic.DeepEqual(existing.Spec.Owner, this.Spec.Owner) { + if equality.Semantic.DeepEqual(existing.Spec.Owner, logicalCluster.Spec.Owner) { return nil } } @@ -337,12 +337,12 @@ func (r *schedulingReconciler) updateLogicalClusterPhase(ctx context.Context, sh if err != nil { return err } - this, err := logicalClusterAdminClient.Cluster(cluster).CoreV1alpha1().LogicalClusters().Get(ctx, corev1alpha1.LogicalClusterName, metav1.GetOptions{}) + logicalCluster, err := logicalClusterAdminClient.Cluster(cluster).CoreV1alpha1().LogicalClusters().Get(ctx, corev1alpha1.LogicalClusterName, metav1.GetOptions{}) if err != nil { return err } - this.Status.Phase = phase - _, err = logicalClusterAdminClient.Cluster(cluster).CoreV1alpha1().LogicalClusters().UpdateStatus(ctx, this, metav1.UpdateOptions{}) + logicalCluster.Status.Phase = phase + _, err = logicalClusterAdminClient.Cluster(cluster).CoreV1alpha1().LogicalClusters().UpdateStatus(ctx, logicalCluster, metav1.UpdateOptions{}) return err } diff --git a/pkg/server/home_workspaces.go b/pkg/server/home_workspaces.go index 8ad15c58678..a793029d96a 100644 --- a/pkg/server/home_workspaces.go +++ b/pkg/server/home_workspaces.go @@ -203,7 +203,7 @@ func (h *homeWorkspaceHandler) ServeHTTP(rw http.ResponseWriter, req *http.Reque } homeClusterName := indexrewriters.HomeClusterName(effectiveUser.GetName()) - this, err := h.logicalClusterLister.Cluster(homeClusterName).Get(corev1alpha1.LogicalClusterName) + logicalCluster, err := h.logicalClusterLister.Cluster(homeClusterName).Get(corev1alpha1.LogicalClusterName) if err != nil { if !kerrors.IsNotFound(err) { responsewriters.InternalError(rw, req, err) @@ -235,7 +235,7 @@ func (h *homeWorkspaceHandler) ServeHTTP(rw http.ResponseWriter, req *http.Reque return } - this = &corev1alpha1.LogicalCluster{ + logicalCluster = &corev1alpha1.LogicalCluster{ ObjectMeta: metav1.ObjectMeta{ Name: corev1alpha1.LogicalClusterName, Annotations: map[string]string{ @@ -244,14 +244,14 @@ func (h *homeWorkspaceHandler) ServeHTTP(rw http.ResponseWriter, req *http.Reque }, }, } - this.Spec.Initializers, err = reconcilerworkspace.LogicalClustersInitializers(h.transitiveTypeResolver, h.getWorkspaceType, core.RootCluster.Path(), "home") + logicalCluster.Spec.Initializers, err = reconcilerworkspace.LogicalClustersInitializers(h.transitiveTypeResolver, h.getWorkspaceType, core.RootCluster.Path(), "home") if err != nil { responsewriters.InternalError(rw, req, err) return } logger.Info("Creating home LogicalCluster", "cluster", homeClusterName.String(), "user", effectiveUser.GetName()) - this, err = h.kcpClusterClient.Cluster(homeClusterName.Path()).CoreV1alpha1().LogicalClusters().Create(ctx, this, metav1.CreateOptions{}) + logicalCluster, err = h.kcpClusterClient.Cluster(homeClusterName.Path()).CoreV1alpha1().LogicalClusters().Create(ctx, logicalCluster, metav1.CreateOptions{}) if err != nil && !kerrors.IsAlreadyExists(err) { responsewriters.InternalError(rw, req, err) return @@ -261,7 +261,7 @@ func (h *homeWorkspaceHandler) ServeHTTP(rw http.ResponseWriter, req *http.Reque // here we have a LogicalCluster. Create ClusterRoleBinding. Again: if this is pre-existing // and it is not belonging to the current user, the user will get a 403 through normal authorization. - if this.Status.Phase == corev1alpha1.LogicalClusterPhaseScheduling { + if logicalCluster.Status.Phase == corev1alpha1.LogicalClusterPhaseScheduling { logger.Info("Creating home ClusterRoleBinding", "cluster", homeClusterName.String(), "user", effectiveUser.GetName(), "name", "workspace-admin") _, err := h.kubeClusterClient.Cluster(homeClusterName.Path()).RbacV1().ClusterRoleBindings().Create(ctx, &rbacv1.ClusterRoleBinding{ ObjectMeta: metav1.ObjectMeta{ @@ -286,9 +286,9 @@ func (h *homeWorkspaceHandler) ServeHTTP(rw http.ResponseWriter, req *http.Reque } // move to Initializing state - this = this.DeepCopy() - this.Status.Phase = corev1alpha1.LogicalClusterPhaseInitializing - this, err = h.kcpClusterClient.Cluster(homeClusterName.Path()).CoreV1alpha1().LogicalClusters().UpdateStatus(ctx, this, metav1.UpdateOptions{}) + logicalCluster = logicalCluster.DeepCopy() + logicalCluster.Status.Phase = corev1alpha1.LogicalClusterPhaseInitializing + logicalCluster, err = h.kcpClusterClient.Cluster(homeClusterName.Path()).CoreV1alpha1().LogicalClusters().UpdateStatus(ctx, logicalCluster, metav1.UpdateOptions{}) if err != nil { if kerrors.IsConflict(err) { rw.Header().Set("Retry-After", fmt.Sprintf("%d", h.creationDelaySeconds)) @@ -300,8 +300,8 @@ func (h *homeWorkspaceHandler) ServeHTTP(rw http.ResponseWriter, req *http.Reque } } - if this.Status.Phase == corev1alpha1.LogicalClusterPhaseInitializing { - if time.Since(this.CreationTimestamp.Time) > h.creationTimeout { + if logicalCluster.Status.Phase == corev1alpha1.LogicalClusterPhaseInitializing { + if time.Since(logicalCluster.CreationTimestamp.Time) > h.creationTimeout { responsewriters.InternalError(rw, req, fmt.Errorf("home workspace creation timeout")) return } @@ -315,16 +315,16 @@ func (h *homeWorkspaceHandler) ServeHTTP(rw http.ResponseWriter, req *http.Reque homeWorkspace := &tenancyv1beta1.Workspace{ ObjectMeta: metav1.ObjectMeta{ - Name: this.Name, - CreationTimestamp: this.CreationTimestamp, + Name: logicalCluster.Name, + CreationTimestamp: logicalCluster.CreationTimestamp, }, Spec: tenancyv1beta1.WorkspaceSpec{}, Status: tenancyv1beta1.WorkspaceStatus{ - URL: this.Status.URL, - Cluster: logicalcluster.From(this).String(), - Phase: this.Status.Phase, - Conditions: this.Status.Conditions, - Initializers: this.Status.Initializers, + URL: logicalCluster.Status.URL, + Cluster: logicalcluster.From(logicalCluster).String(), + Phase: logicalCluster.Status.Phase, + Conditions: logicalCluster.Status.Conditions, + Initializers: logicalCluster.Status.Initializers, }, } responsewriters.WriteObjectNegotiated(homeWorkspaceCodecs, negotiation.DefaultEndpointRestrictions, tenancyv1beta1.SchemeGroupVersion, rw, req, http.StatusOK, homeWorkspace) diff --git a/pkg/server/localproxy.go b/pkg/server/localproxy.go index 64cdbed2cf9..4de56a2866d 100644 --- a/pkg/server/localproxy.go +++ b/pkg/server/localproxy.go @@ -72,19 +72,19 @@ func WithLocalProxy( logicalClusterInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ AddFunc: func(obj interface{}) { - this := obj.(*corev1alpha1.LogicalCluster) - indexState.UpsertLogicalCluster(shardName, this) + logicalCluster := obj.(*corev1alpha1.LogicalCluster) + indexState.UpsertLogicalCluster(shardName, logicalCluster) }, UpdateFunc: func(old, obj interface{}) { - this := obj.(*corev1alpha1.LogicalCluster) - indexState.UpsertLogicalCluster(shardName, this) + logicalCluster := obj.(*corev1alpha1.LogicalCluster) + indexState.UpsertLogicalCluster(shardName, logicalCluster) }, DeleteFunc: func(obj interface{}) { if final, ok := obj.(cache.DeletedFinalStateUnknown); ok { obj = final.Obj } - this := obj.(*corev1alpha1.LogicalCluster) - indexState.DeleteLogicalCluster(shardName, this) + logicalCluster := obj.(*corev1alpha1.LogicalCluster) + indexState.DeleteLogicalCluster(shardName, logicalCluster) }, }) diff --git a/test/e2e/virtual/initializingworkspaces/virtualworkspace_test.go b/test/e2e/virtual/initializingworkspaces/virtualworkspace_test.go index 5a15e98bf3f..69b69098198 100644 --- a/test/e2e/virtual/initializingworkspaces/virtualworkspace_test.go +++ b/test/e2e/virtual/initializingworkspaces/virtualworkspace_test.go @@ -495,11 +495,11 @@ func TestInitializingWorkspacesVirtualWorkspaceAccess(t *testing.T) { "gamma", } { clusterClient := user1VwKcpClusterClients[initializer].CoreV1alpha1().LogicalClusters() - this, err := clusterClient.Cluster(wsClusterName.Path()).Get(ctx, corev1alpha1.LogicalClusterName, metav1.GetOptions{}) + logicalCluster, err := clusterClient.Cluster(wsClusterName.Path()).Get(ctx, corev1alpha1.LogicalClusterName, metav1.GetOptions{}) require.NoError(t, err) t.Logf("Attempt to do something more than just removing our initializer %q, get denied", initializer) - patchBytes := patchBytesFor(this, func(workspace *corev1alpha1.LogicalCluster) { + patchBytes := patchBytesFor(logicalCluster, func(workspace *corev1alpha1.LogicalCluster) { workspace.Status.Initializers = []corev1alpha1.LogicalClusterInitializer{"wrong"} }) _, err = clusterClient.Cluster(wsClusterName.Path()).Patch(ctx, corev1alpha1.LogicalClusterName, types.MergePatchType, patchBytes, metav1.PatchOptions{}, "status") @@ -508,7 +508,7 @@ func TestInitializingWorkspacesVirtualWorkspaceAccess(t *testing.T) { } t.Logf("Remove just our initializer %q", initializer) - patchBytes = patchBytesFor(this, func(workspace *corev1alpha1.LogicalCluster) { + patchBytes = patchBytesFor(logicalCluster, func(workspace *corev1alpha1.LogicalCluster) { workspace.Status.Initializers = initialization.EnsureInitializerAbsent(initialization.InitializerForType(workspacetypes[initializer]), workspace.Status.Initializers) }) _, err = clusterClient.Cluster(wsClusterName.Path()).Patch(ctx, corev1alpha1.LogicalClusterName, types.MergePatchType, patchBytes, metav1.PatchOptions{}, "status")