diff --git a/Taskfile.yaml b/Taskfile.yaml index 86d9e92..aa53c48 100644 --- a/Taskfile.yaml +++ b/Taskfile.yaml @@ -41,7 +41,7 @@ tasks: setup:kcp-api-gen: internal: true cmds: - - test -s {{.LOCAL_BIN}}/apigen || GOBIN=$(pwd)/{{.LOCAL_BIN}} go install github.com/kcp-dev/kcp/sdk/cmd/apigen@{{.KCP_APIGEN_VERSION}} + - test -s {{.LOCAL_BIN}}/apigen || GOBIN=$(pwd)/{{.LOCAL_BIN}} go install github.com/kcp-dev/sdk/cmd/apigen@{{.KCP_APIGEN_VERSION}} setup:kcp: cmds: - test -s {{.LOCAL_BIN}}/kcp || GOBIN=$(pwd)/{{.LOCAL_BIN}} ./hack/download-tool.sh https://github.com/kcp-dev/kcp/releases/download/v{{ .KCP_VERSION }}/kcp_{{ .KCP_VERSION }}_{{ .GOOS }}_{{ .GOARCH }}.tar.gz kcp {{.KCP_VERSION}} diff --git a/cmd/initializer.go b/cmd/initializer.go index 63a86d5..38f224b 100644 --- a/cmd/initializer.go +++ b/cmd/initializer.go @@ -6,7 +6,6 @@ import ( helmv2 "github.com/fluxcd/helm-controller/api/v2" sourcev1 "github.com/fluxcd/source-controller/api/v1" - pmcontext "github.com/platform-mesh/golang-commons/context" "github.com/platform-mesh/security-operator/internal/controller" "github.com/spf13/cobra" ctrl "sigs.k8s.io/controller-runtime" @@ -27,9 +26,6 @@ var initializerCmd = &cobra.Command{ Use: "initializer", Short: "FGA initializer for the organization workspacetype", RunE: func(cmd *cobra.Command, args []string) error { - ctx, _, shutdown := pmcontext.StartContext(log, initializerCfg, defaultCfg.ShutdownTimeout) - defer shutdown() - restCfg, err := getKubeconfigFromPath(initializerCfg.KCP.Kubeconfig) if err != nil { log.Error().Err(err).Msg("unable to get KCP kubeconfig") @@ -112,12 +108,6 @@ var initializerCmd = &cobra.Command{ os.Exit(1) } - go func() { - if err := provider.Run(ctx, mgr); err != nil { - log.Fatal().Err(err).Msg("unable to run provider") - } - }() - setupLog.Info("starting manager") return mgr.Start(ctrl.SetupSignalHandler()) diff --git a/cmd/model_generator.go b/cmd/model_generator.go index e555224..3a6874b 100644 --- a/cmd/model_generator.go +++ b/cmd/model_generator.go @@ -70,7 +70,12 @@ var modelGeneratorCmd = &cobra.Command{ return fmt.Errorf("scheme should not be nil") } - provider, err := apiexport.New(restCfg, apiexport.Options{ + providerConfig, err := getPlatformMeshSystemConfig(restCfg) + if err != nil { + setupLog.Error(err, "unable to create provider config") + return err + } + provider, err := apiexport.New(providerConfig, operatorCfg.APIExportEndpointSliceName, apiexport.Options{ Scheme: mgrOpts.Scheme, }) if err != nil { @@ -99,18 +104,11 @@ var modelGeneratorCmd = &cobra.Command{ return err } - go func() { - if err := provider.Run(ctx, mgr); err != nil { - log.Fatal().Err(err).Msg("unable to run provider") - } - }() - setupLog.Info("starting manager") if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil { setupLog.Error(err, "problem running manager") return err } - return nil }, } diff --git a/cmd/operator.go b/cmd/operator.go index bc96955..0809ad0 100644 --- a/cmd/operator.go +++ b/cmd/operator.go @@ -29,11 +29,11 @@ import ( // Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.) // to ensure that exec-entrypoint and run can make use of them. - apisv1alpha1 "github.com/kcp-dev/kcp/sdk/apis/apis/v1alpha1" - kcpcorev1alpha1 "github.com/kcp-dev/kcp/sdk/apis/core/v1alpha1" - kcptenancyv1alphav1 "github.com/kcp-dev/kcp/sdk/apis/tenancy/v1alpha1" "github.com/kcp-dev/logicalcluster/v3" "github.com/kcp-dev/multicluster-provider/apiexport" + kcpapisv1alpha1 "github.com/kcp-dev/sdk/apis/apis/v1alpha1" + kcpcorev1alpha1 "github.com/kcp-dev/sdk/apis/core/v1alpha1" + kcptenancyv1alphav1 "github.com/kcp-dev/sdk/apis/tenancy/v1alpha1" _ "k8s.io/client-go/plugin/pkg/client/auth" ) @@ -42,8 +42,29 @@ var ( scheme = runtime.NewScheme() ) +const ( + platformMeshWorkspace = "root:platform-mesh-system" +) + type NewLogicalClusterClientFunc func(clusterKey logicalcluster.Name) (client.Client, error) +func getPlatformMeshSystemConfig(cfg *rest.Config) (*rest.Config, error) { + providerConfig := rest.CopyConfig(cfg) + + parsed, err := url.Parse(providerConfig.Host) + if err != nil { + return nil, fmt.Errorf("unable to parse URL: %w", err) + } + + parsed.Path, err = url.JoinPath("clusters", platformMeshWorkspace) + if err != nil { + return nil, fmt.Errorf("failed to join path") + } + providerConfig.Host = parsed.String() + + return providerConfig, nil +} + func logicalClusterClientFromKey(config *rest.Config, log *logger.Logger) NewLogicalClusterClientFunc { return func(clusterKey logicalcluster.Name) (client.Client, error) { cfg := rest.CopyConfig(config) @@ -126,8 +147,12 @@ var operatorCmd = &cobra.Command{ log.Error().Err(fmt.Errorf("scheme should not be nil")).Msg("scheme should not be nil") return fmt.Errorf("scheme should not be nil") } - - provider, err := apiexport.New(restCfg, apiexport.Options{ + providerConfig, err := getPlatformMeshSystemConfig(restCfg) + if err != nil { + setupLog.Error(err, "unable to create provider config") + return err + } + provider, err := apiexport.New(providerConfig, operatorCfg.APIExportEndpointSliceName, apiexport.Options{ Scheme: mgrOpts.Scheme, }) if err != nil { @@ -185,12 +210,6 @@ var operatorCmd = &cobra.Command{ return err } - go func() { - if err := provider.Run(ctx, mgr); err != nil { - log.Fatal().Err(err).Msg("unable to run provider") - } - }() - setupLog.Info("starting manager") if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil { log.Error().Err(err).Msg("problem running manager") @@ -246,7 +265,7 @@ func init() { utilruntime.Must(clientgoscheme.AddToScheme(scheme)) utilruntime.Must(kcptenancyv1alphav1.AddToScheme(scheme)) utilruntime.Must(corev1alpha1.AddToScheme(scheme)) - utilruntime.Must(apisv1alpha1.AddToScheme(scheme)) + utilruntime.Must(kcpapisv1alpha1.AddToScheme(scheme)) utilruntime.Must(kcpcorev1alpha1.AddToScheme(scheme)) utilruntime.Must(accountsv1alpha1.AddToScheme(scheme)) // +kubebuilder:scaffold:scheme diff --git a/go.mod b/go.mod index 7597399..2d10b3e 100644 --- a/go.mod +++ b/go.mod @@ -2,17 +2,15 @@ module github.com/platform-mesh/security-operator go 1.25.0 -replace github.com/kcp-dev/multicluster-provider v0.2.0 => github.com/kcp-dev/multicluster-provider v0.0.0-20250827085327-2b5ca378b7b4 - require ( github.com/coreos/go-oidc v2.5.0+incompatible github.com/fluxcd/helm-controller/api v1.4.5 github.com/fluxcd/source-controller/api v1.7.4 github.com/go-logr/logr v1.4.3 github.com/google/gnostic-models v0.7.1 - github.com/kcp-dev/kcp/sdk v0.28.1-0.20250926104223-cec2e15f24c6 github.com/kcp-dev/logicalcluster/v3 v3.0.5 - github.com/kcp-dev/multicluster-provider v0.2.0 + github.com/kcp-dev/multicluster-provider v0.3.3 + github.com/kcp-dev/sdk v0.28.1-0.20251209130449-436a0347809b github.com/openfga/api/proto v0.0.0-20251105142303-feed3db3d69d github.com/openfga/language/pkg/go v0.2.0-beta.2.0.20251027165255-0f8f255e5f6c github.com/platform-mesh/account-operator v0.6.2 @@ -22,7 +20,6 @@ require ( github.com/spf13/viper v1.21.0 github.com/stretchr/testify v1.11.1 golang.org/x/oauth2 v0.34.0 - golang.org/x/sync v0.19.0 google.golang.org/grpc v1.78.0 google.golang.org/protobuf v1.36.11 k8s.io/api v0.35.0 @@ -31,7 +28,7 @@ require ( k8s.io/client-go v0.35.0 k8s.io/utils v0.0.0-20260108192941-914a6e750570 sigs.k8s.io/controller-runtime v0.22.4 - sigs.k8s.io/multicluster-runtime v0.21.0-alpha.9 + sigs.k8s.io/multicluster-runtime v0.22.4-beta.1 sigs.k8s.io/yaml v1.6.0 ) @@ -68,7 +65,7 @@ require ( github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/josharian/intern v1.0.0 // indirect github.com/json-iterator/go v1.1.12 // indirect - github.com/kcp-dev/apimachinery/v2 v2.0.1-0.20250728122101-adbf20db3e51 // indirect + github.com/kcp-dev/apimachinery/v2 v2.29.1-0.20251209121225-cf3c0b624983 // indirect github.com/mailru/easyjson v0.9.0 // indirect github.com/martinlindhe/base36 v1.1.1 // indirect github.com/mattn/go-colorable v0.1.14 // indirect @@ -109,6 +106,7 @@ require ( golang.org/x/crypto v0.46.0 // indirect golang.org/x/exp v0.0.0-20260112195511-716be5621a96 // indirect golang.org/x/net v0.48.0 // indirect + golang.org/x/sync v0.19.0 // indirect golang.org/x/sys v0.40.0 // indirect golang.org/x/term v0.38.0 // indirect golang.org/x/text v0.33.0 // indirect diff --git a/go.sum b/go.sum index 5c08547..de8ebc4 100644 --- a/go.sum +++ b/go.sum @@ -110,14 +110,14 @@ github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8Hm github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= -github.com/kcp-dev/apimachinery/v2 v2.0.1-0.20250728122101-adbf20db3e51 h1:l38RDS+VUMx9etvyaCgJIZa4nM7FaNevNubWN0kDZY4= -github.com/kcp-dev/apimachinery/v2 v2.0.1-0.20250728122101-adbf20db3e51/go.mod h1:rF1jfvUfPjFXs+HV/LN1BtPzAz1bfjJOwVa+hAVfroQ= -github.com/kcp-dev/kcp/sdk v0.28.1-0.20250926104223-cec2e15f24c6 h1:bOR4mdLD24VCJRrHxmtTh21AdbbzkBBKkEh0ngL+XTc= -github.com/kcp-dev/kcp/sdk v0.28.1-0.20250926104223-cec2e15f24c6/go.mod h1:aC2BPGPvy8QtkI2gQNH9NfW6xpfGIKZkR93gy9O02BE= +github.com/kcp-dev/apimachinery/v2 v2.29.1-0.20251209121225-cf3c0b624983 h1:4hCauFTFMwvIhwL9fqZ5omjeZ+vsOUNO1tLsrCeprxM= +github.com/kcp-dev/apimachinery/v2 v2.29.1-0.20251209121225-cf3c0b624983/go.mod h1:DOv0iw5tcgzFBhudwLFe2WHCLqtlgNkuO4AcqbZ4zVo= github.com/kcp-dev/logicalcluster/v3 v3.0.5 h1:JbYakokb+5Uinz09oTXomSUJVQsqfxEvU4RyHUYxHOU= github.com/kcp-dev/logicalcluster/v3 v3.0.5/go.mod h1:EWBUBxdr49fUB1cLMO4nOdBWmYifLbP1LfoL20KkXYY= -github.com/kcp-dev/multicluster-provider v0.0.0-20250827085327-2b5ca378b7b4 h1:GUihV22j2J/cGF5Svr/zGVvfqTJepIO+sOnYTn9o4Vc= -github.com/kcp-dev/multicluster-provider v0.0.0-20250827085327-2b5ca378b7b4/go.mod h1:E/NxN2SMtC7b6iXgFMlQYWA7lJIfDPqRkPdvpxOEQLA= +github.com/kcp-dev/multicluster-provider v0.3.3 h1:wTu1Zbk6+kVlB/d/K9TM7KPjUEe/Dg8SYzKQsVDiDFY= +github.com/kcp-dev/multicluster-provider v0.3.3/go.mod h1:4QGU39wyNztoYNatdWqbdOV6/R9ZzaIh4DdSj30dm9o= +github.com/kcp-dev/sdk v0.28.1-0.20251209130449-436a0347809b h1:hPwN5SK3L5bx4Ymeb5NeYN0lqIXd+Xt1cAr3qcSlQxU= +github.com/kcp-dev/sdk v0.28.1-0.20251209130449-436a0347809b/go.mod h1:kdlYfujcotSPrBzwtI6qrsNo4JQ+GB1o04buOfKUo2c= github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo= github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= @@ -318,8 +318,8 @@ sigs.k8s.io/controller-runtime v0.22.4 h1:GEjV7KV3TY8e+tJ2LCTxUTanW4z/FmNB7l327U sigs.k8s.io/controller-runtime v0.22.4/go.mod h1:+QX1XUpTXN4mLoblf4tqr5CQcyHPAki2HLXqQMY6vh8= sigs.k8s.io/json v0.0.0-20250730193827-2d320260d730 h1:IpInykpT6ceI+QxKBbEflcR5EXP7sU1kvOlxwZh5txg= sigs.k8s.io/json v0.0.0-20250730193827-2d320260d730/go.mod h1:mdzfpAEoE6DHQEN0uh9ZbOCuHbLK5wOm7dK4ctXE9Tg= -sigs.k8s.io/multicluster-runtime v0.21.0-alpha.9 h1:baonM4f081WWct3U7O4EfqrxcUGtmCrFDbsT1FQ8xlo= -sigs.k8s.io/multicluster-runtime v0.21.0-alpha.9/go.mod h1:CpBzLMLQKdm+UCchd2FiGPiDdCxM5dgCCPKuaQ6Fsv0= +sigs.k8s.io/multicluster-runtime v0.22.4-beta.1 h1:0XWbDINepM9UOyLkqhG4g7BtGBFKCDvZFyPsw1vufKE= +sigs.k8s.io/multicluster-runtime v0.22.4-beta.1/go.mod h1:zSMb4mC8MAZK42l8eE1ywkeX6vjuNRenYzJ1w+GPdfI= sigs.k8s.io/randfill v1.0.0 h1:JfjMILfT8A6RbawdsK2JXGBR5AQVfd+9TbzrlneTyrU= sigs.k8s.io/randfill v1.0.0/go.mod h1:XeLlZ/jmk4i1HRopwe7/aU3H5n1zNUcX6TM94b3QxOY= sigs.k8s.io/structured-merge-diff/v6 v6.3.0 h1:jTijUJbW353oVOd9oTlifJqOGEkUw2jB/fXCbTiQEco= diff --git a/internal/config/config.go b/internal/config/config.go index e75a038..8cbfc33 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -14,7 +14,7 @@ type Config struct { KCP struct { Kubeconfig string `mapstructure:"kcp-kubeconfig" default:"/api-kubeconfig/kubeconfig"` } `mapstructure:",squash"` - APIExportEndpointSliceName string `mapstructure:"api-export-endpoint-slice-name"` + APIExportEndpointSliceName string `mapstructure:"api-export-endpoint-slice-name" default:"core.platform-mesh.io"` CoreModulePath string `mapstructure:"core-module-path"` BaseDomain string `mapstructure:"base-domain" default:"portal.dev.local:8443"` GroupClaim string `mapstructure:"group-claim" default:"groups"` diff --git a/internal/controller/apibinding_controller.go b/internal/controller/apibinding_controller.go index a0e7ad1..5b72534 100644 --- a/internal/controller/apibinding_controller.go +++ b/internal/controller/apibinding_controller.go @@ -22,8 +22,8 @@ import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/client-go/rest" - kcpv1alpha1 "github.com/kcp-dev/kcp/sdk/apis/apis/v1alpha1" "github.com/kcp-dev/logicalcluster/v3" + kcpapisv1alpha1 "github.com/kcp-dev/sdk/apis/apis/v1alpha1" ) func GetAllClient(config *rest.Config, schema *runtime.Scheme) (client.Client, error) { @@ -78,9 +78,9 @@ type APIBindingReconciler struct { func (r *APIBindingReconciler) Reconcile(ctx context.Context, req mcreconcile.Request) (ctrl.Result, error) { ctxWithCluster := mccontext.WithCluster(ctx, req.ClusterName) - return r.mclifecycle.Reconcile(ctxWithCluster, req, &kcpv1alpha1.APIBinding{}) + return r.mclifecycle.Reconcile(ctxWithCluster, req, &kcpapisv1alpha1.APIBinding{}) } func (r *APIBindingReconciler) SetupWithManager(mgr mcmanager.Manager, cfg *platformeshconfig.CommonServiceConfig, evp ...predicate.Predicate) error { - return r.mclifecycle.SetupWithManager(mgr, cfg.MaxConcurrentReconciles, "apibinding-controller", &kcpv1alpha1.APIBinding{}, cfg.DebugLabelValue, r, r.log, evp...) + return r.mclifecycle.SetupWithManager(mgr, cfg.MaxConcurrentReconciles, "apibinding-controller", &kcpapisv1alpha1.APIBinding{}, cfg.DebugLabelValue, r, r.log, evp...) } diff --git a/internal/controller/initializer_controller.go b/internal/controller/initializer_controller.go index 121451f..8a77a2f 100644 --- a/internal/controller/initializer_controller.go +++ b/internal/controller/initializer_controller.go @@ -17,7 +17,7 @@ import ( mcmanager "sigs.k8s.io/multicluster-runtime/pkg/manager" mcreconcile "sigs.k8s.io/multicluster-runtime/pkg/reconcile" - kcpcorev1alpha1 "github.com/kcp-dev/kcp/sdk/apis/core/v1alpha1" + kcpcorev1alpha1 "github.com/kcp-dev/sdk/apis/core/v1alpha1" ) type LogicalClusterReconciler struct { diff --git a/internal/subroutine/authorization_model_generation.go b/internal/subroutine/authorization_model_generation.go index 235fbfd..55d59f5 100644 --- a/internal/subroutine/authorization_model_generation.go +++ b/internal/subroutine/authorization_model_generation.go @@ -23,8 +23,8 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" - kcpv1alpha1 "github.com/kcp-dev/kcp/sdk/apis/apis/v1alpha1" "github.com/kcp-dev/logicalcluster/v3" + kcpapisv1alpha1 "github.com/kcp-dev/sdk/apis/apis/v1alpha1" ) func NewAuthorizationModelGenerationSubroutine(mcMgr mcmanager.Manager, allClient client.Client) *AuthorizationModelGenerationSubroutine { @@ -88,14 +88,14 @@ type modelInput struct { func (a *AuthorizationModelGenerationSubroutine) Finalize(ctx context.Context, instance lifecyclecontrollerruntime.RuntimeObject) (ctrl.Result, errors.OperatorError) { log := logger.LoadLoggerFromContext(ctx) - bindingToDelete := instance.(*kcpv1alpha1.APIBinding) + bindingToDelete := instance.(*kcpapisv1alpha1.APIBinding) bindingCluster, err := a.mgr.ClusterFromContext(ctx) if err != nil { return ctrl.Result{}, errors.NewOperatorError(fmt.Errorf("unable to get cluster from context: %w", err), true, false) } - var bindings kcpv1alpha1.APIBindingList + var bindings kcpapisv1alpha1.APIBindingList err = a.allClient.List(ctx, &bindings) if err != nil { return ctrl.Result{}, errors.NewOperatorError(err, true, true) @@ -150,7 +150,7 @@ func (a *AuthorizationModelGenerationSubroutine) Finalize(ctx context.Context, i } apiExportClient := apiExportCluster.GetClient() - var apiExport kcpv1alpha1.APIExport + var apiExport kcpapisv1alpha1.APIExport err = apiExportClient.Get(ctx, types.NamespacedName{Name: bindingToDelete.Spec.Reference.Export.Name}, &apiExport) if err != nil { log.Error().Err(err).Msg("failed to get apiexport for binding deletion") @@ -158,7 +158,7 @@ func (a *AuthorizationModelGenerationSubroutine) Finalize(ctx context.Context, i } for _, latestResourceSchema := range apiExport.Spec.LatestResourceSchemas { - var resourceSchema kcpv1alpha1.APIResourceSchema + var resourceSchema kcpapisv1alpha1.APIResourceSchema err := apiExportClient.Get(ctx, types.NamespacedName{Name: latestResourceSchema}, &resourceSchema) if err != nil { log.Error().Err(err).Msg("failed to get resource schema for binding deletion") @@ -199,7 +199,7 @@ func (a *AuthorizationModelGenerationSubroutine) GetName() string { // Process implements lifecycle.Subroutine. func (a *AuthorizationModelGenerationSubroutine) Process(ctx context.Context, instance lifecyclecontrollerruntime.RuntimeObject) (ctrl.Result, errors.OperatorError) { - binding := instance.(*kcpv1alpha1.APIBinding) + binding := instance.(*kcpapisv1alpha1.APIBinding) cluster, err := a.mgr.ClusterFromContext(ctx) if err != nil { @@ -226,14 +226,14 @@ func (a *AuthorizationModelGenerationSubroutine) Process(ctx context.Context, in return ctrl.Result{}, errors.NewOperatorError(err, true, true) } - var apiExport kcpv1alpha1.APIExport + var apiExport kcpapisv1alpha1.APIExport err = apiExportCluster.GetClient().Get(ctx, types.NamespacedName{Name: binding.Spec.Reference.Export.Name}, &apiExport) if err != nil { return ctrl.Result{}, errors.NewOperatorError(err, true, true) } for _, latestResourceSchema := range apiExport.Spec.LatestResourceSchemas { - var resourceSchema kcpv1alpha1.APIResourceSchema + var resourceSchema kcpapisv1alpha1.APIResourceSchema err := apiExportCluster.GetClient().Get(ctx, types.NamespacedName{Name: latestResourceSchema}, &resourceSchema) if err != nil { return ctrl.Result{}, errors.NewOperatorError(err, true, true) diff --git a/internal/subroutine/authorization_model_generation_test.go b/internal/subroutine/authorization_model_generation_test.go index 5e83c02..c1bbcc2 100644 --- a/internal/subroutine/authorization_model_generation_test.go +++ b/internal/subroutine/authorization_model_generation_test.go @@ -16,16 +16,16 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/types" - kcpv1alpha1 "github.com/kcp-dev/kcp/sdk/apis/apis/v1alpha1" + kcpapisv1alpha1 "github.com/kcp-dev/sdk/apis/apis/v1alpha1" ) -func newApiBinding(name, path string) *kcpv1alpha1.APIBinding { - return &kcpv1alpha1.APIBinding{ - Spec: kcpv1alpha1.APIBindingSpec{Reference: kcpv1alpha1.BindingReference{Export: &kcpv1alpha1.ExportBindingReference{Name: name, Path: path}}}, +func newApiBinding(name, path string) *kcpapisv1alpha1.APIBinding { + return &kcpapisv1alpha1.APIBinding{ + Spec: kcpapisv1alpha1.APIBindingSpec{Reference: kcpapisv1alpha1.BindingReference{Export: &kcpapisv1alpha1.ExportBindingReference{Name: name, Path: path}}}, } } -func bindingWithCluster(name, path, cluster string) *kcpv1alpha1.APIBinding { +func bindingWithCluster(name, path, cluster string) *kcpapisv1alpha1.APIBinding { b := newApiBinding(name, path) if b.Annotations == nil { b.Annotations = make(map[string]string) @@ -34,7 +34,7 @@ func bindingWithCluster(name, path, cluster string) *kcpv1alpha1.APIBinding { return b } -func bindingWithApiExportCluster(name, path, exportCluster string) *kcpv1alpha1.APIBinding { +func bindingWithApiExportCluster(name, path, exportCluster string) *kcpapisv1alpha1.APIBinding { b := newApiBinding(name, path) b.Status.APIExportClusterName = exportCluster return b @@ -53,7 +53,7 @@ func mockAccountInfo(cl *mocks.MockClient, orgName, originCluster string) { func TestAuthorizationModelGeneration_Process(t *testing.T) { tests := []struct { name string - binding *kcpv1alpha1.APIBinding + binding *kcpapisv1alpha1.APIBinding mockSetup func(*mocks.MockManager, *mocks.MockClient, *mocks.MockCluster, *mocks.MockClient) expectError bool }{ @@ -107,14 +107,14 @@ func TestAuthorizationModelGeneration_Process(t *testing.T) { }).Once() manager.EXPECT().GetCluster(mock.Anything, mock.Anything).Return(cluster, nil) kcpClient.EXPECT().Get(mock.Anything, mock.Anything, mock.Anything).RunAndReturn(func(ctx context.Context, nn types.NamespacedName, o client.Object, opts ...client.GetOption) error { - if ae, ok := o.(*kcpv1alpha1.APIExport); ok { + if ae, ok := o.(*kcpapisv1alpha1.APIExport); ok { ae.Spec.LatestResourceSchemas = []string{"schema1"} return nil } return nil }).Once() kcpClient.EXPECT().Get(mock.Anything, mock.Anything, mock.Anything).RunAndReturn(func(ctx context.Context, nn types.NamespacedName, o client.Object, opts ...client.GetOption) error { - if rs, ok := o.(*kcpv1alpha1.APIResourceSchema); ok { + if rs, ok := o.(*kcpapisv1alpha1.APIResourceSchema); ok { rs.Spec.Group = "group" rs.Spec.Names.Plural = "things" rs.Spec.Names.Singular = "thing" @@ -145,14 +145,14 @@ func TestAuthorizationModelGeneration_Process(t *testing.T) { mockAccountInfo(kcpClient, "org", "origin") manager.EXPECT().GetCluster(mock.Anything, mock.Anything).Return(cluster, nil) kcpClient.EXPECT().Get(mock.Anything, mock.Anything, mock.Anything).RunAndReturn(func(ctx context.Context, nn types.NamespacedName, o client.Object, opts ...client.GetOption) error { - if ae, ok := o.(*kcpv1alpha1.APIExport); ok { + if ae, ok := o.(*kcpapisv1alpha1.APIExport); ok { ae.Spec.LatestResourceSchemas = []string{"schema1"} return nil } return nil }).Once() kcpClient.EXPECT().Get(mock.Anything, mock.Anything, mock.Anything).RunAndReturn(func(ctx context.Context, nn types.NamespacedName, o client.Object, opts ...client.GetOption) error { - if rs, ok := o.(*kcpv1alpha1.APIResourceSchema); ok { + if rs, ok := o.(*kcpapisv1alpha1.APIResourceSchema); ok { rs.Spec.Group = "group" rs.Spec.Names.Plural = "foos" rs.Spec.Names.Singular = "foo" @@ -175,14 +175,14 @@ func TestAuthorizationModelGeneration_Process(t *testing.T) { mockAccountInfo(kcpClient, "org", "origin") manager.EXPECT().GetCluster(mock.Anything, mock.Anything).Return(cluster, nil) kcpClient.EXPECT().Get(mock.Anything, mock.Anything, mock.Anything).RunAndReturn(func(ctx context.Context, nn types.NamespacedName, o client.Object, opts ...client.GetOption) error { - if ae, ok := o.(*kcpv1alpha1.APIExport); ok { + if ae, ok := o.(*kcpapisv1alpha1.APIExport); ok { ae.Spec.LatestResourceSchemas = []string{"schema1"} return nil } return nil }).Once() kcpClient.EXPECT().Get(mock.Anything, mock.Anything, mock.Anything).RunAndReturn(func(ctx context.Context, nn types.NamespacedName, o client.Object, opts ...client.GetOption) error { - if rs, ok := o.(*kcpv1alpha1.APIResourceSchema); ok { + if rs, ok := o.(*kcpapisv1alpha1.APIResourceSchema); ok { rs.Spec.Group = "group" rs.Spec.Names.Plural = "foos" rs.Spec.Names.Singular = "foo" @@ -218,7 +218,7 @@ func TestAuthorizationModelGeneration_Process(t *testing.T) { mockAccountInfo(kcpClient, "org", "origin") manager.EXPECT().GetCluster(mock.Anything, mock.Anything).Return(cluster, nil) kcpClient.EXPECT().Get(mock.Anything, mock.Anything, mock.Anything).RunAndReturn(func(ctx context.Context, nn types.NamespacedName, o client.Object, opts ...client.GetOption) error { - if ae, ok := o.(*kcpv1alpha1.APIExport); ok { + if ae, ok := o.(*kcpapisv1alpha1.APIExport); ok { ae.Spec.LatestResourceSchemas = []string{"schema1"} return nil } @@ -236,14 +236,14 @@ func TestAuthorizationModelGeneration_Process(t *testing.T) { mockAccountInfo(kcpClient, "org", "origin") manager.EXPECT().GetCluster(mock.Anything, mock.Anything).Return(cluster, nil) kcpClient.EXPECT().Get(mock.Anything, mock.Anything, mock.Anything).RunAndReturn(func(ctx context.Context, nn types.NamespacedName, o client.Object, opts ...client.GetOption) error { - if ae, ok := o.(*kcpv1alpha1.APIExport); ok { + if ae, ok := o.(*kcpapisv1alpha1.APIExport); ok { ae.Spec.LatestResourceSchemas = []string{"schema1"} return nil } return nil }).Once() kcpClient.EXPECT().Get(mock.Anything, mock.Anything, mock.Anything).RunAndReturn(func(ctx context.Context, nn types.NamespacedName, o client.Object, opts ...client.GetOption) error { - if rs, ok := o.(*kcpv1alpha1.APIResourceSchema); ok { + if rs, ok := o.(*kcpapisv1alpha1.APIResourceSchema); ok { rs.Spec.Group = "veryverylonggroup.platform-mesh.org" rs.Spec.Names.Plural = "plural" rs.Spec.Names.Singular = "singular" @@ -304,14 +304,14 @@ func TestAuthorizationModelGeneration_Process(t *testing.T) { func TestAuthorizationModelGeneration_Finalize(t *testing.T) { tests := []struct { name string - binding *kcpv1alpha1.APIBinding - mockSetup func(*mocks.MockManager, *mocks.MockClient, *kcpv1alpha1.APIBinding) + binding *kcpapisv1alpha1.APIBinding + mockSetup func(*mocks.MockManager, *mocks.MockClient, *kcpapisv1alpha1.APIBinding) expectError bool }{ { name: "bindings with non-matching export are skipped", binding: bindingWithApiExportCluster("foo", "bar", "export-cluster"), - mockSetup: func(manager *mocks.MockManager, allClient *mocks.MockClient, binding *kcpv1alpha1.APIBinding) { + mockSetup: func(manager *mocks.MockManager, allClient *mocks.MockClient, binding *kcpapisv1alpha1.APIBinding) { bindingCluster := mocks.NewMockCluster(t) bindingClient := mocks.NewMockClient(t) bindingWsCluster := mocks.NewMockCluster(t) @@ -322,10 +322,10 @@ func TestAuthorizationModelGeneration_Finalize(t *testing.T) { manager.EXPECT().ClusterFromContext(mock.Anything).Return(bindingCluster, nil) bindingCluster.EXPECT().GetClient().Return(bindingClient) allClient.EXPECT().List(mock.Anything, mock.Anything).RunAndReturn(func(ctx context.Context, ol client.ObjectList, lo ...client.ListOption) error { - list := ol.(*kcpv1alpha1.APIBindingList) + list := ol.(*kcpapisv1alpha1.APIBindingList) b1 := bindingWithCluster("foo", "bar", "cluster1") b2 := bindingWithCluster("other", "other", "cluster2") - list.Items = []kcpv1alpha1.APIBinding{*b1, *b2} + list.Items = []kcpapisv1alpha1.APIBinding{*b1, *b2} return nil }) bindingClient.EXPECT().Get(mock.Anything, types.NamespacedName{Name: "account"}, mock.Anything).RunAndReturn(func(ctx context.Context, nn types.NamespacedName, o client.Object, opts ...client.GetOption) error { @@ -345,12 +345,12 @@ func TestAuthorizationModelGeneration_Finalize(t *testing.T) { manager.EXPECT().GetCluster(mock.Anything, "export-cluster").Return(apiExportCluster, nil) apiExportCluster.EXPECT().GetClient().Return(apiExportClient) apiExportClient.EXPECT().Get(mock.Anything, types.NamespacedName{Name: "foo"}, mock.Anything).RunAndReturn(func(ctx context.Context, nn types.NamespacedName, o client.Object, opts ...client.GetOption) error { - ae := o.(*kcpv1alpha1.APIExport) + ae := o.(*kcpapisv1alpha1.APIExport) ae.Spec.LatestResourceSchemas = []string{"schema1"} return nil }) apiExportClient.EXPECT().Get(mock.Anything, types.NamespacedName{Name: "schema1"}, mock.Anything).RunAndReturn(func(ctx context.Context, nn types.NamespacedName, o client.Object, opts ...client.GetOption) error { - rs := o.(*kcpv1alpha1.APIResourceSchema) + rs := o.(*kcpapisv1alpha1.APIResourceSchema) rs.Spec.Names.Plural = "foos" return nil }) @@ -361,7 +361,7 @@ func TestAuthorizationModelGeneration_Finalize(t *testing.T) { name: "error on ClusterFromContext in Finalize", binding: bindingWithApiExportCluster("foo", "bar", "export-cluster"), expectError: true, - mockSetup: func(manager *mocks.MockManager, allClient *mocks.MockClient, binding *kcpv1alpha1.APIBinding) { + mockSetup: func(manager *mocks.MockManager, allClient *mocks.MockClient, binding *kcpapisv1alpha1.APIBinding) { manager.EXPECT().ClusterFromContext(mock.Anything).Return(nil, assert.AnError) }, }, @@ -369,20 +369,20 @@ func TestAuthorizationModelGeneration_Finalize(t *testing.T) { name: "early return when accountInfo missing in Finalize", binding: bindingWithApiExportCluster("foo", "bar", "export-cluster"), expectError: true, - mockSetup: func(manager *mocks.MockManager, allClient *mocks.MockClient, binding *kcpv1alpha1.APIBinding) { + mockSetup: func(manager *mocks.MockManager, allClient *mocks.MockClient, binding *kcpapisv1alpha1.APIBinding) { bindingCluster := mocks.NewMockCluster(t) bindingClient := mocks.NewMockClient(t) manager.EXPECT().ClusterFromContext(mock.Anything).Return(bindingCluster, nil) bindingCluster.EXPECT().GetClient().Return(bindingClient) allClient.EXPECT().List(mock.Anything, mock.Anything).RunAndReturn(func(ctx context.Context, ol client.ObjectList, lo ...client.ListOption) error { - list := ol.(*kcpv1alpha1.APIBindingList) + list := ol.(*kcpapisv1alpha1.APIBindingList) b := binding.DeepCopy() if b.Annotations == nil { b.Annotations = make(map[string]string) } b.Annotations["kcp.io/cluster"] = "cluster1" - list.Items = []kcpv1alpha1.APIBinding{*b} + list.Items = []kcpapisv1alpha1.APIBinding{*b} return nil }) bindingClient.EXPECT().Get(mock.Anything, types.NamespacedName{Name: "account"}, mock.Anything).Return( @@ -393,7 +393,7 @@ func TestAuthorizationModelGeneration_Finalize(t *testing.T) { name: "delete returns error in Finalize", binding: bindingWithApiExportCluster("foo", "bar", "export-cluster"), expectError: true, - mockSetup: func(manager *mocks.MockManager, allClient *mocks.MockClient, binding *kcpv1alpha1.APIBinding) { + mockSetup: func(manager *mocks.MockManager, allClient *mocks.MockClient, binding *kcpapisv1alpha1.APIBinding) { bindingCluster := mocks.NewMockCluster(t) bindingClient := mocks.NewMockClient(t) apiExportCluster := mocks.NewMockCluster(t) @@ -402,13 +402,13 @@ func TestAuthorizationModelGeneration_Finalize(t *testing.T) { manager.EXPECT().ClusterFromContext(mock.Anything).Return(bindingCluster, nil) bindingCluster.EXPECT().GetClient().Return(bindingClient) allClient.EXPECT().List(mock.Anything, mock.Anything).RunAndReturn(func(ctx context.Context, ol client.ObjectList, lo ...client.ListOption) error { - list := ol.(*kcpv1alpha1.APIBindingList) + list := ol.(*kcpapisv1alpha1.APIBindingList) b := binding.DeepCopy() if b.Annotations == nil { b.Annotations = make(map[string]string) } b.Annotations["kcp.io/cluster"] = "cluster1" - list.Items = []kcpv1alpha1.APIBinding{*b} + list.Items = []kcpapisv1alpha1.APIBinding{*b} return nil }) bindingClient.EXPECT().Get(mock.Anything, types.NamespacedName{Name: "account"}, mock.Anything).RunAndReturn(func(ctx context.Context, nn types.NamespacedName, o client.Object, opts ...client.GetOption) error { @@ -427,12 +427,12 @@ func TestAuthorizationModelGeneration_Finalize(t *testing.T) { manager.EXPECT().GetCluster(mock.Anything, "export-cluster").Return(apiExportCluster, nil) apiExportCluster.EXPECT().GetClient().Return(apiExportClient) apiExportClient.EXPECT().Get(mock.Anything, types.NamespacedName{Name: "foo"}, mock.Anything).RunAndReturn(func(ctx context.Context, nn types.NamespacedName, o client.Object, opts ...client.GetOption) error { - ae := o.(*kcpv1alpha1.APIExport) + ae := o.(*kcpapisv1alpha1.APIExport) ae.Spec.LatestResourceSchemas = []string{"schema1"} return nil }) apiExportClient.EXPECT().Get(mock.Anything, types.NamespacedName{Name: "schema1"}, mock.Anything).RunAndReturn(func(ctx context.Context, nn types.NamespacedName, o client.Object, opts ...client.GetOption) error { - rs := o.(*kcpv1alpha1.APIResourceSchema) + rs := o.(*kcpapisv1alpha1.APIResourceSchema) rs.Spec.Names.Plural = "foos" return nil }) @@ -442,7 +442,7 @@ func TestAuthorizationModelGeneration_Finalize(t *testing.T) { { name: "skip Finalize if other bindings exist", binding: bindingWithApiExportCluster("foo", "bar", "export-cluster"), - mockSetup: func(manager *mocks.MockManager, allClient *mocks.MockClient, binding *kcpv1alpha1.APIBinding) { + mockSetup: func(manager *mocks.MockManager, allClient *mocks.MockClient, binding *kcpapisv1alpha1.APIBinding) { bindingCluster := mocks.NewMockCluster(t) bindingClient := mocks.NewMockClient(t) bindingWsCluster1 := mocks.NewMockCluster(t) @@ -453,10 +453,10 @@ func TestAuthorizationModelGeneration_Finalize(t *testing.T) { manager.EXPECT().ClusterFromContext(mock.Anything).Return(bindingCluster, nil) bindingCluster.EXPECT().GetClient().Return(bindingClient) allClient.EXPECT().List(mock.Anything, mock.Anything).RunAndReturn(func(ctx context.Context, ol client.ObjectList, lo ...client.ListOption) error { - list := ol.(*kcpv1alpha1.APIBindingList) + list := ol.(*kcpapisv1alpha1.APIBindingList) b1 := bindingWithCluster("foo", "bar", "cluster1") b2 := bindingWithCluster("foo", "bar", "cluster2") - list.Items = []kcpv1alpha1.APIBinding{*b1, *b2} + list.Items = []kcpapisv1alpha1.APIBinding{*b1, *b2} return nil }) bindingClient.EXPECT().Get(mock.Anything, types.NamespacedName{Name: "account"}, mock.Anything).RunAndReturn(func(ctx context.Context, nn types.NamespacedName, o client.Object, opts ...client.GetOption) error { @@ -486,7 +486,7 @@ func TestAuthorizationModelGeneration_Finalize(t *testing.T) { { name: "delete model in Finalize if last binding", binding: bindingWithApiExportCluster("foo", "bar", "export-cluster"), - mockSetup: func(manager *mocks.MockManager, allClient *mocks.MockClient, binding *kcpv1alpha1.APIBinding) { + mockSetup: func(manager *mocks.MockManager, allClient *mocks.MockClient, binding *kcpapisv1alpha1.APIBinding) { bindingCluster := mocks.NewMockCluster(t) bindingClient := mocks.NewMockClient(t) bindingWsCluster := mocks.NewMockCluster(t) @@ -497,13 +497,13 @@ func TestAuthorizationModelGeneration_Finalize(t *testing.T) { manager.EXPECT().ClusterFromContext(mock.Anything).Return(bindingCluster, nil) bindingCluster.EXPECT().GetClient().Return(bindingClient) allClient.EXPECT().List(mock.Anything, mock.Anything).RunAndReturn(func(ctx context.Context, ol client.ObjectList, lo ...client.ListOption) error { - list := ol.(*kcpv1alpha1.APIBindingList) + list := ol.(*kcpapisv1alpha1.APIBindingList) b := binding.DeepCopy() if b.Annotations == nil { b.Annotations = make(map[string]string) } b.Annotations["kcp.io/cluster"] = "cluster1" - list.Items = []kcpv1alpha1.APIBinding{*b} + list.Items = []kcpapisv1alpha1.APIBinding{*b} return nil }) bindingClient.EXPECT().Get(mock.Anything, types.NamespacedName{Name: "account"}, mock.Anything).RunAndReturn(func(ctx context.Context, nn types.NamespacedName, o client.Object, opts ...client.GetOption) error { @@ -523,12 +523,12 @@ func TestAuthorizationModelGeneration_Finalize(t *testing.T) { manager.EXPECT().GetCluster(mock.Anything, "export-cluster").Return(apiExportCluster, nil) apiExportCluster.EXPECT().GetClient().Return(apiExportClient) apiExportClient.EXPECT().Get(mock.Anything, types.NamespacedName{Name: "foo"}, mock.Anything).RunAndReturn(func(ctx context.Context, nn types.NamespacedName, o client.Object, opts ...client.GetOption) error { - ae := o.(*kcpv1alpha1.APIExport) + ae := o.(*kcpapisv1alpha1.APIExport) ae.Spec.LatestResourceSchemas = []string{"schema1"} return nil }) apiExportClient.EXPECT().Get(mock.Anything, types.NamespacedName{Name: "schema1"}, mock.Anything).RunAndReturn(func(ctx context.Context, nn types.NamespacedName, o client.Object, opts ...client.GetOption) error { - rs := o.(*kcpv1alpha1.APIResourceSchema) + rs := o.(*kcpapisv1alpha1.APIResourceSchema) rs.Spec.Names.Plural = "foos" return nil }) @@ -538,7 +538,7 @@ func TestAuthorizationModelGeneration_Finalize(t *testing.T) { { name: "delete model in Finalize but model is not found", binding: bindingWithApiExportCluster("foo", "bar", "export-cluster"), - mockSetup: func(manager *mocks.MockManager, allClient *mocks.MockClient, binding *kcpv1alpha1.APIBinding) { + mockSetup: func(manager *mocks.MockManager, allClient *mocks.MockClient, binding *kcpapisv1alpha1.APIBinding) { bindingCluster := mocks.NewMockCluster(t) bindingClient := mocks.NewMockClient(t) bindingWsCluster := mocks.NewMockCluster(t) @@ -549,13 +549,13 @@ func TestAuthorizationModelGeneration_Finalize(t *testing.T) { manager.EXPECT().ClusterFromContext(mock.Anything).Return(bindingCluster, nil) bindingCluster.EXPECT().GetClient().Return(bindingClient) allClient.EXPECT().List(mock.Anything, mock.Anything).RunAndReturn(func(ctx context.Context, ol client.ObjectList, lo ...client.ListOption) error { - list := ol.(*kcpv1alpha1.APIBindingList) + list := ol.(*kcpapisv1alpha1.APIBindingList) b := binding.DeepCopy() if b.Annotations == nil { b.Annotations = make(map[string]string) } b.Annotations["kcp.io/cluster"] = "cluster1" - list.Items = []kcpv1alpha1.APIBinding{*b} + list.Items = []kcpapisv1alpha1.APIBinding{*b} return nil }) bindingClient.EXPECT().Get(mock.Anything, types.NamespacedName{Name: "account"}, mock.Anything).RunAndReturn(func(ctx context.Context, nn types.NamespacedName, o client.Object, opts ...client.GetOption) error { @@ -575,12 +575,12 @@ func TestAuthorizationModelGeneration_Finalize(t *testing.T) { manager.EXPECT().GetCluster(mock.Anything, "export-cluster").Return(apiExportCluster, nil) apiExportCluster.EXPECT().GetClient().Return(apiExportClient) apiExportClient.EXPECT().Get(mock.Anything, types.NamespacedName{Name: "foo"}, mock.Anything).RunAndReturn(func(ctx context.Context, nn types.NamespacedName, o client.Object, opts ...client.GetOption) error { - ae := o.(*kcpv1alpha1.APIExport) + ae := o.(*kcpapisv1alpha1.APIExport) ae.Spec.LatestResourceSchemas = []string{"schema1"} return nil }) apiExportClient.EXPECT().Get(mock.Anything, types.NamespacedName{Name: "schema1"}, mock.Anything).RunAndReturn(func(ctx context.Context, nn types.NamespacedName, o client.Object, opts ...client.GetOption) error { - rs := o.(*kcpv1alpha1.APIResourceSchema) + rs := o.(*kcpapisv1alpha1.APIResourceSchema) rs.Spec.Names.Plural = "foos" return nil }) @@ -592,7 +592,7 @@ func TestAuthorizationModelGeneration_Finalize(t *testing.T) { name: "error on List in Finalize", binding: newApiBinding("foo", "bar"), expectError: true, - mockSetup: func(manager *mocks.MockManager, allClient *mocks.MockClient, binding *kcpv1alpha1.APIBinding) { + mockSetup: func(manager *mocks.MockManager, allClient *mocks.MockClient, binding *kcpapisv1alpha1.APIBinding) { bindingCluster := mocks.NewMockCluster(t) bindingClient := mocks.NewMockClient(t) @@ -605,20 +605,20 @@ func TestAuthorizationModelGeneration_Finalize(t *testing.T) { name: "error on getRelatedAuthorizationModels in Finalize", binding: bindingWithApiExportCluster("foo", "bar", "export-cluster"), expectError: true, - mockSetup: func(manager *mocks.MockManager, allClient *mocks.MockClient, binding *kcpv1alpha1.APIBinding) { + mockSetup: func(manager *mocks.MockManager, allClient *mocks.MockClient, binding *kcpapisv1alpha1.APIBinding) { bindingCluster := mocks.NewMockCluster(t) bindingClient := mocks.NewMockClient(t) manager.EXPECT().ClusterFromContext(mock.Anything).Return(bindingCluster, nil) bindingCluster.EXPECT().GetClient().Return(bindingClient) allClient.EXPECT().List(mock.Anything, mock.Anything).RunAndReturn(func(ctx context.Context, ol client.ObjectList, lo ...client.ListOption) error { - list := ol.(*kcpv1alpha1.APIBindingList) + list := ol.(*kcpapisv1alpha1.APIBindingList) b := binding.DeepCopy() if b.Annotations == nil { b.Annotations = make(map[string]string) } b.Annotations["kcp.io/cluster"] = "cluster1" - list.Items = []kcpv1alpha1.APIBinding{*b} + list.Items = []kcpapisv1alpha1.APIBinding{*b} return nil }) bindingClient.EXPECT().Get(mock.Anything, types.NamespacedName{Name: "account"}, mock.Anything).Return(assert.AnError) @@ -627,7 +627,7 @@ func TestAuthorizationModelGeneration_Finalize(t *testing.T) { { name: "only bindings for same org are counted; delete called if only one, not called if none", binding: bindingWithApiExportCluster("foo", "bar", "export-cluster"), - mockSetup: func(manager *mocks.MockManager, allClient *mocks.MockClient, binding *kcpv1alpha1.APIBinding) { + mockSetup: func(manager *mocks.MockManager, allClient *mocks.MockClient, binding *kcpapisv1alpha1.APIBinding) { bindingCluster := mocks.NewMockCluster(t) bindingClient := mocks.NewMockClient(t) bindingWsCluster1 := mocks.NewMockCluster(t) @@ -640,10 +640,10 @@ func TestAuthorizationModelGeneration_Finalize(t *testing.T) { manager.EXPECT().ClusterFromContext(mock.Anything).Return(bindingCluster, nil) bindingCluster.EXPECT().GetClient().Return(bindingClient) allClient.EXPECT().List(mock.Anything, mock.Anything).RunAndReturn(func(ctx context.Context, ol client.ObjectList, lo ...client.ListOption) error { - list := ol.(*kcpv1alpha1.APIBindingList) + list := ol.(*kcpapisv1alpha1.APIBindingList) b1 := bindingWithCluster("foo", "bar", "cluster1") b2 := bindingWithCluster("foo", "bar", "cluster2") - list.Items = []kcpv1alpha1.APIBinding{*b1, *b2} + list.Items = []kcpapisv1alpha1.APIBinding{*b1, *b2} return nil }) bindingClient.EXPECT().Get(mock.Anything, types.NamespacedName{Name: "account"}, mock.Anything).RunAndReturn(func(ctx context.Context, nn types.NamespacedName, o client.Object, opts ...client.GetOption) error { @@ -667,12 +667,12 @@ func TestAuthorizationModelGeneration_Finalize(t *testing.T) { manager.EXPECT().GetCluster(mock.Anything, "export-cluster").Return(apiExportCluster, nil) apiExportCluster.EXPECT().GetClient().Return(apiExportClient) apiExportClient.EXPECT().Get(mock.Anything, types.NamespacedName{Name: "foo"}, mock.Anything).RunAndReturn(func(ctx context.Context, nn types.NamespacedName, o client.Object, opts ...client.GetOption) error { - ae := o.(*kcpv1alpha1.APIExport) + ae := o.(*kcpapisv1alpha1.APIExport) ae.Spec.LatestResourceSchemas = []string{"schema1"} return nil }) apiExportClient.EXPECT().Get(mock.Anything, types.NamespacedName{Name: "schema1"}, mock.Anything).RunAndReturn(func(ctx context.Context, nn types.NamespacedName, o client.Object, opts ...client.GetOption) error { - rs := o.(*kcpv1alpha1.APIResourceSchema) + rs := o.(*kcpapisv1alpha1.APIResourceSchema) rs.Spec.Names.Plural = "foos" return nil }) @@ -682,16 +682,16 @@ func TestAuthorizationModelGeneration_Finalize(t *testing.T) { { name: "error on GetCluster for binding workspace in Finalize loop", binding: bindingWithApiExportCluster("foo", "bar", "export-cluster"), - mockSetup: func(manager *mocks.MockManager, allClient *mocks.MockClient, binding *kcpv1alpha1.APIBinding) { + mockSetup: func(manager *mocks.MockManager, allClient *mocks.MockClient, binding *kcpapisv1alpha1.APIBinding) { bindingCluster := mocks.NewMockCluster(t) bindingClient := mocks.NewMockClient(t) manager.EXPECT().ClusterFromContext(mock.Anything).Return(bindingCluster, nil) bindingCluster.EXPECT().GetClient().Return(bindingClient) allClient.EXPECT().List(mock.Anything, mock.Anything).RunAndReturn(func(ctx context.Context, ol client.ObjectList, lo ...client.ListOption) error { - list := ol.(*kcpv1alpha1.APIBindingList) + list := ol.(*kcpapisv1alpha1.APIBindingList) b := bindingWithCluster("foo", "bar", "cluster1") - list.Items = []kcpv1alpha1.APIBinding{*b} + list.Items = []kcpapisv1alpha1.APIBinding{*b} return nil }) bindingClient.EXPECT().Get(mock.Anything, types.NamespacedName{Name: "account"}, mock.Anything).RunAndReturn(func(ctx context.Context, nn types.NamespacedName, o client.Object, opts ...client.GetOption) error { @@ -707,7 +707,7 @@ func TestAuthorizationModelGeneration_Finalize(t *testing.T) { { name: "error on Get accountInfo in Finalize loop (not NotFound)", binding: bindingWithApiExportCluster("foo", "bar", "export-cluster"), - mockSetup: func(manager *mocks.MockManager, allClient *mocks.MockClient, binding *kcpv1alpha1.APIBinding) { + mockSetup: func(manager *mocks.MockManager, allClient *mocks.MockClient, binding *kcpapisv1alpha1.APIBinding) { bindingCluster := mocks.NewMockCluster(t) bindingClient := mocks.NewMockClient(t) bindingWsCluster := mocks.NewMockCluster(t) @@ -716,9 +716,9 @@ func TestAuthorizationModelGeneration_Finalize(t *testing.T) { manager.EXPECT().ClusterFromContext(mock.Anything).Return(bindingCluster, nil) bindingCluster.EXPECT().GetClient().Return(bindingClient) allClient.EXPECT().List(mock.Anything, mock.Anything).RunAndReturn(func(ctx context.Context, ol client.ObjectList, lo ...client.ListOption) error { - list := ol.(*kcpv1alpha1.APIBindingList) + list := ol.(*kcpapisv1alpha1.APIBindingList) b := bindingWithCluster("foo", "bar", "cluster1") - list.Items = []kcpv1alpha1.APIBinding{*b} + list.Items = []kcpapisv1alpha1.APIBinding{*b} return nil }) bindingClient.EXPECT().Get(mock.Anything, types.NamespacedName{Name: "account"}, mock.Anything).RunAndReturn(func(ctx context.Context, nn types.NamespacedName, o client.Object, opts ...client.GetOption) error { @@ -736,7 +736,7 @@ func TestAuthorizationModelGeneration_Finalize(t *testing.T) { { name: "bindings with different org are skipped in Finalize", binding: bindingWithApiExportCluster("foo", "bar", "export-cluster"), - mockSetup: func(manager *mocks.MockManager, allClient *mocks.MockClient, binding *kcpv1alpha1.APIBinding) { + mockSetup: func(manager *mocks.MockManager, allClient *mocks.MockClient, binding *kcpapisv1alpha1.APIBinding) { bindingCluster := mocks.NewMockCluster(t) bindingClient := mocks.NewMockClient(t) bindingWsCluster := mocks.NewMockCluster(t) @@ -747,9 +747,9 @@ func TestAuthorizationModelGeneration_Finalize(t *testing.T) { manager.EXPECT().ClusterFromContext(mock.Anything).Return(bindingCluster, nil) bindingCluster.EXPECT().GetClient().Return(bindingClient) allClient.EXPECT().List(mock.Anything, mock.Anything).RunAndReturn(func(ctx context.Context, ol client.ObjectList, lo ...client.ListOption) error { - list := ol.(*kcpv1alpha1.APIBindingList) + list := ol.(*kcpapisv1alpha1.APIBindingList) b := bindingWithCluster("foo", "bar", "cluster1") - list.Items = []kcpv1alpha1.APIBinding{*b} + list.Items = []kcpapisv1alpha1.APIBinding{*b} return nil }) bindingClient.EXPECT().Get(mock.Anything, types.NamespacedName{Name: "account"}, mock.Anything).RunAndReturn(func(ctx context.Context, nn types.NamespacedName, o client.Object, opts ...client.GetOption) error { @@ -769,12 +769,12 @@ func TestAuthorizationModelGeneration_Finalize(t *testing.T) { manager.EXPECT().GetCluster(mock.Anything, "export-cluster").Return(apiExportCluster, nil) apiExportCluster.EXPECT().GetClient().Return(apiExportClient) apiExportClient.EXPECT().Get(mock.Anything, types.NamespacedName{Name: "foo"}, mock.Anything).RunAndReturn(func(ctx context.Context, nn types.NamespacedName, o client.Object, opts ...client.GetOption) error { - ae := o.(*kcpv1alpha1.APIExport) + ae := o.(*kcpapisv1alpha1.APIExport) ae.Spec.LatestResourceSchemas = []string{"schema1"} return nil }) apiExportClient.EXPECT().Get(mock.Anything, types.NamespacedName{Name: "schema1"}, mock.Anything).RunAndReturn(func(ctx context.Context, nn types.NamespacedName, o client.Object, opts ...client.GetOption) error { - rs := o.(*kcpv1alpha1.APIResourceSchema) + rs := o.(*kcpapisv1alpha1.APIResourceSchema) rs.Spec.Names.Plural = "foos" return nil }) @@ -785,7 +785,7 @@ func TestAuthorizationModelGeneration_Finalize(t *testing.T) { name: "error on GetCluster for APIExport cluster in Finalize", binding: bindingWithApiExportCluster("foo", "bar", "export-cluster"), expectError: true, - mockSetup: func(manager *mocks.MockManager, allClient *mocks.MockClient, binding *kcpv1alpha1.APIBinding) { + mockSetup: func(manager *mocks.MockManager, allClient *mocks.MockClient, binding *kcpapisv1alpha1.APIBinding) { bindingCluster := mocks.NewMockCluster(t) bindingClient := mocks.NewMockClient(t) bindingWsCluster := mocks.NewMockCluster(t) @@ -794,9 +794,9 @@ func TestAuthorizationModelGeneration_Finalize(t *testing.T) { manager.EXPECT().ClusterFromContext(mock.Anything).Return(bindingCluster, nil) bindingCluster.EXPECT().GetClient().Return(bindingClient) allClient.EXPECT().List(mock.Anything, mock.Anything).RunAndReturn(func(ctx context.Context, ol client.ObjectList, lo ...client.ListOption) error { - list := ol.(*kcpv1alpha1.APIBindingList) + list := ol.(*kcpapisv1alpha1.APIBindingList) b := bindingWithCluster("foo", "bar", "cluster1") - list.Items = []kcpv1alpha1.APIBinding{*b} + list.Items = []kcpapisv1alpha1.APIBinding{*b} return nil }) bindingClient.EXPECT().Get(mock.Anything, types.NamespacedName{Name: "account"}, mock.Anything).RunAndReturn(func(ctx context.Context, nn types.NamespacedName, o client.Object, opts ...client.GetOption) error { @@ -820,7 +820,7 @@ func TestAuthorizationModelGeneration_Finalize(t *testing.T) { name: "error on Get APIExport in Finalize", binding: bindingWithApiExportCluster("foo", "bar", "export-cluster"), expectError: true, - mockSetup: func(manager *mocks.MockManager, allClient *mocks.MockClient, binding *kcpv1alpha1.APIBinding) { + mockSetup: func(manager *mocks.MockManager, allClient *mocks.MockClient, binding *kcpapisv1alpha1.APIBinding) { bindingCluster := mocks.NewMockCluster(t) bindingClient := mocks.NewMockClient(t) bindingWsCluster := mocks.NewMockCluster(t) @@ -831,9 +831,9 @@ func TestAuthorizationModelGeneration_Finalize(t *testing.T) { manager.EXPECT().ClusterFromContext(mock.Anything).Return(bindingCluster, nil) bindingCluster.EXPECT().GetClient().Return(bindingClient) allClient.EXPECT().List(mock.Anything, mock.Anything).RunAndReturn(func(ctx context.Context, ol client.ObjectList, lo ...client.ListOption) error { - list := ol.(*kcpv1alpha1.APIBindingList) + list := ol.(*kcpapisv1alpha1.APIBindingList) b := bindingWithCluster("foo", "bar", "cluster1") - list.Items = []kcpv1alpha1.APIBinding{*b} + list.Items = []kcpapisv1alpha1.APIBinding{*b} return nil }) bindingClient.EXPECT().Get(mock.Anything, types.NamespacedName{Name: "account"}, mock.Anything).RunAndReturn(func(ctx context.Context, nn types.NamespacedName, o client.Object, opts ...client.GetOption) error { @@ -859,7 +859,7 @@ func TestAuthorizationModelGeneration_Finalize(t *testing.T) { name: "error on Get resource schema in Finalize", binding: bindingWithApiExportCluster("foo", "bar", "export-cluster"), expectError: true, - mockSetup: func(manager *mocks.MockManager, allClient *mocks.MockClient, binding *kcpv1alpha1.APIBinding) { + mockSetup: func(manager *mocks.MockManager, allClient *mocks.MockClient, binding *kcpapisv1alpha1.APIBinding) { bindingCluster := mocks.NewMockCluster(t) bindingClient := mocks.NewMockClient(t) bindingWsCluster := mocks.NewMockCluster(t) @@ -870,9 +870,9 @@ func TestAuthorizationModelGeneration_Finalize(t *testing.T) { manager.EXPECT().ClusterFromContext(mock.Anything).Return(bindingCluster, nil) bindingCluster.EXPECT().GetClient().Return(bindingClient) allClient.EXPECT().List(mock.Anything, mock.Anything).RunAndReturn(func(ctx context.Context, ol client.ObjectList, lo ...client.ListOption) error { - list := ol.(*kcpv1alpha1.APIBindingList) + list := ol.(*kcpapisv1alpha1.APIBindingList) b := bindingWithCluster("foo", "bar", "cluster1") - list.Items = []kcpv1alpha1.APIBinding{*b} + list.Items = []kcpapisv1alpha1.APIBinding{*b} return nil }) bindingClient.EXPECT().Get(mock.Anything, types.NamespacedName{Name: "account"}, mock.Anything).RunAndReturn(func(ctx context.Context, nn types.NamespacedName, o client.Object, opts ...client.GetOption) error { @@ -892,7 +892,7 @@ func TestAuthorizationModelGeneration_Finalize(t *testing.T) { manager.EXPECT().GetCluster(mock.Anything, "export-cluster").Return(apiExportCluster, nil) apiExportCluster.EXPECT().GetClient().Return(apiExportClient) apiExportClient.EXPECT().Get(mock.Anything, types.NamespacedName{Name: "foo"}, mock.Anything).RunAndReturn(func(ctx context.Context, nn types.NamespacedName, o client.Object, opts ...client.GetOption) error { - ae := o.(*kcpv1alpha1.APIExport) + ae := o.(*kcpapisv1alpha1.APIExport) ae.Spec.LatestResourceSchemas = []string{"schema1"} return nil }) diff --git a/internal/subroutine/idp.go b/internal/subroutine/idp.go index 82d43f0..a708576 100644 --- a/internal/subroutine/idp.go +++ b/internal/subroutine/idp.go @@ -23,7 +23,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" - kcpv1alpha1 "github.com/kcp-dev/kcp/sdk/apis/core/v1alpha1" + kcpcorev1alpha1 "github.com/kcp-dev/sdk/apis/core/v1alpha1" ) const ( @@ -62,7 +62,7 @@ func (i *IDPSubroutine) Finalizers(_ runtimeobject.RuntimeObject) []string { func (i *IDPSubroutine) GetName() string { return "IDPSubroutine" } func (i *IDPSubroutine) Process(ctx context.Context, instance runtimeobject.RuntimeObject) (ctrl.Result, errors.OperatorError) { - lc := instance.(*kcpv1alpha1.LogicalCluster) + lc := instance.(*kcpcorev1alpha1.LogicalCluster) workspaceName := getWorkspaceName(lc) if workspaceName == "" { @@ -149,7 +149,7 @@ func ensureClient(existing []v1alpha1.IdentityProviderClientConfig, desired v1al return append(existing, desired) } -func getWorkspaceName(lc *kcpv1alpha1.LogicalCluster) string { +func getWorkspaceName(lc *kcpcorev1alpha1.LogicalCluster) string { if path, ok := lc.Annotations["kcp.io/path"]; ok { pathElements := strings.Split(path, ":") return pathElements[len(pathElements)-1] diff --git a/internal/subroutine/idp_test.go b/internal/subroutine/idp_test.go index 7d6ebb3..4c8e274 100644 --- a/internal/subroutine/idp_test.go +++ b/internal/subroutine/idp_test.go @@ -19,7 +19,7 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/types" - kcpv1alpha1 "github.com/kcp-dev/kcp/sdk/apis/core/v1alpha1" + kcpv1alpha1 "github.com/kcp-dev/sdk/apis/core/v1alpha1" ) func TestNewIDPSubroutine(t *testing.T) { diff --git a/internal/subroutine/invite.go b/internal/subroutine/invite.go index 5b22721..766c7f7 100644 --- a/internal/subroutine/invite.go +++ b/internal/subroutine/invite.go @@ -21,7 +21,7 @@ import ( "k8s.io/apimachinery/pkg/util/wait" "k8s.io/client-go/util/retry" - kcpv1alpha1 "github.com/kcp-dev/kcp/sdk/apis/core/v1alpha1" + kcpcorev1alpha1 "github.com/kcp-dev/sdk/apis/core/v1alpha1" ) func NewInviteSubroutine(orgsClient client.Client, mgr mcmanager.Manager) *inviteSubroutine { @@ -49,7 +49,7 @@ func (w *inviteSubroutine) Finalizers(_ runtimeobject.RuntimeObject) []string { func (w *inviteSubroutine) GetName() string { return "InviteInitilizationSubroutine" } func (w *inviteSubroutine) Process(ctx context.Context, instance runtimeobject.RuntimeObject) (ctrl.Result, errors.OperatorError) { - lc := instance.(*kcpv1alpha1.LogicalCluster) + lc := instance.(*kcpcorev1alpha1.LogicalCluster) wsName := getWorkspaceName(lc) if wsName == "" { diff --git a/internal/subroutine/invite_test.go b/internal/subroutine/invite_test.go index e60d13d..fe5f6cd 100644 --- a/internal/subroutine/invite_test.go +++ b/internal/subroutine/invite_test.go @@ -18,7 +18,7 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/types" - kcpv1alpha1 "github.com/kcp-dev/kcp/sdk/apis/core/v1alpha1" + kcpcorev1alpha1 "github.com/kcp-dev/sdk/apis/core/v1alpha1" ) func TestNewInviteSubroutine(t *testing.T) { @@ -56,7 +56,7 @@ func TestInviteSubroutine_Finalize(t *testing.T) { subroutine := NewInviteSubroutine(orgsClient, mgr) ctx := context.Background() - instance := &kcpv1alpha1.LogicalCluster{} + instance := &kcpcorev1alpha1.LogicalCluster{} result, opErr := subroutine.Finalize(ctx, instance) @@ -68,14 +68,14 @@ func TestInviteSubroutine_Process(t *testing.T) { tests := []struct { name string setupMocks func(*mocks.MockClient, *mocks.MockManager, *mocks.MockCluster) - lc *kcpv1alpha1.LogicalCluster + lc *kcpcorev1alpha1.LogicalCluster expectedErr bool expectedResult ctrl.Result }{ { name: "Empty workspace name - early return", setupMocks: func(orgsClient *mocks.MockClient, mgr *mocks.MockManager, cluster *mocks.MockCluster) {}, - lc: &kcpv1alpha1.LogicalCluster{ + lc: &kcpcorev1alpha1.LogicalCluster{ ObjectMeta: metav1.ObjectMeta{ Annotations: map[string]string{}, }, @@ -88,7 +88,7 @@ func TestInviteSubroutine_Process(t *testing.T) { setupMocks: func(orgsClient *mocks.MockClient, mgr *mocks.MockManager, cluster *mocks.MockCluster) { mgr.EXPECT().ClusterFromContext(mock.Anything).Return(nil, assert.AnError).Once() }, - lc: &kcpv1alpha1.LogicalCluster{ + lc: &kcpcorev1alpha1.LogicalCluster{ ObjectMeta: metav1.ObjectMeta{ Annotations: map[string]string{ "kcp.io/path": "root:orgs:test", @@ -105,7 +105,7 @@ func TestInviteSubroutine_Process(t *testing.T) { orgsClient.EXPECT().Get(mock.Anything, types.NamespacedName{Name: "test"}, mock.AnythingOfType("*v1alpha1.Account")). Return(assert.AnError).Once() }, - lc: &kcpv1alpha1.LogicalCluster{ + lc: &kcpcorev1alpha1.LogicalCluster{ ObjectMeta: metav1.ObjectMeta{ Annotations: map[string]string{ "kcp.io/path": "root:orgs:test", @@ -128,7 +128,7 @@ func TestInviteSubroutine_Process(t *testing.T) { return nil }).Once() }, - lc: &kcpv1alpha1.LogicalCluster{ + lc: &kcpcorev1alpha1.LogicalCluster{ ObjectMeta: metav1.ObjectMeta{ Annotations: map[string]string{ "kcp.io/path": "root:orgs:test", @@ -168,7 +168,7 @@ func TestInviteSubroutine_Process(t *testing.T) { return nil }).Maybe() }, - lc: &kcpv1alpha1.LogicalCluster{ + lc: &kcpcorev1alpha1.LogicalCluster{ ObjectMeta: metav1.ObjectMeta{ Annotations: map[string]string{ "kcp.io/path": "root:orgs:acme", @@ -208,7 +208,7 @@ func TestInviteSubroutine_Process(t *testing.T) { return nil }).Maybe() }, - lc: &kcpv1alpha1.LogicalCluster{ + lc: &kcpcorev1alpha1.LogicalCluster{ ObjectMeta: metav1.ObjectMeta{ Annotations: map[string]string{ "kcp.io/path": "root:orgs:beta", @@ -247,12 +247,12 @@ func TestInviteSubroutine_Process(t *testing.T) { func TestGetWorkspaceName(t *testing.T) { tests := []struct { name string - lc *kcpv1alpha1.LogicalCluster + lc *kcpcorev1alpha1.LogicalCluster expected string }{ { name: "valid workspace path", - lc: &kcpv1alpha1.LogicalCluster{ + lc: &kcpcorev1alpha1.LogicalCluster{ ObjectMeta: metav1.ObjectMeta{ Annotations: map[string]string{ "kcp.io/path": "root:orgs:test", @@ -263,7 +263,7 @@ func TestGetWorkspaceName(t *testing.T) { }, { name: "workspace path with multiple segments", - lc: &kcpv1alpha1.LogicalCluster{ + lc: &kcpcorev1alpha1.LogicalCluster{ ObjectMeta: metav1.ObjectMeta{ Annotations: map[string]string{ "kcp.io/path": "root:orgs:test:sub", @@ -274,7 +274,7 @@ func TestGetWorkspaceName(t *testing.T) { }, { name: "missing annotation", - lc: &kcpv1alpha1.LogicalCluster{ + lc: &kcpcorev1alpha1.LogicalCluster{ ObjectMeta: metav1.ObjectMeta{ Annotations: map[string]string{}, }, @@ -283,7 +283,7 @@ func TestGetWorkspaceName(t *testing.T) { }, { name: "empty annotation", - lc: &kcpv1alpha1.LogicalCluster{ + lc: &kcpcorev1alpha1.LogicalCluster{ ObjectMeta: metav1.ObjectMeta{ Annotations: map[string]string{ "kcp.io/path": "", diff --git a/internal/subroutine/remove_initializer.go b/internal/subroutine/remove_initializer.go index 0744442..0a47719 100644 --- a/internal/subroutine/remove_initializer.go +++ b/internal/subroutine/remove_initializer.go @@ -14,8 +14,8 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" mcmanager "sigs.k8s.io/multicluster-runtime/pkg/manager" - "github.com/kcp-dev/kcp/sdk/apis/cache/initialization" - kcpv1alpha1 "github.com/kcp-dev/kcp/sdk/apis/core/v1alpha1" + "github.com/kcp-dev/sdk/apis/cache/initialization" + kcpcorev1alpha1 "github.com/kcp-dev/sdk/apis/core/v1alpha1" ) type removeInitializer struct { @@ -36,9 +36,9 @@ func (r *removeInitializer) GetName() string { return "RemoveInitializer" } // Process implements subroutine.Subroutine. func (r *removeInitializer) Process(ctx context.Context, instance runtimeobject.RuntimeObject) (ctrl.Result, errors.OperatorError) { - lc := instance.(*kcpv1alpha1.LogicalCluster) + lc := instance.(*kcpcorev1alpha1.LogicalCluster) - initializer := kcpv1alpha1.LogicalClusterInitializer(r.initializerName) + initializer := kcpcorev1alpha1.LogicalClusterInitializer(r.initializerName) cluster, err := r.mgr.ClusterFromContext(ctx) if err != nil { diff --git a/internal/subroutine/remove_initializer_test.go b/internal/subroutine/remove_initializer_test.go index ec15877..002e452 100644 --- a/internal/subroutine/remove_initializer_test.go +++ b/internal/subroutine/remove_initializer_test.go @@ -11,13 +11,13 @@ import ( "github.com/stretchr/testify/mock" "sigs.k8s.io/controller-runtime/pkg/client" - kcpv1alpha1 "github.com/kcp-dev/kcp/sdk/apis/core/v1alpha1" + kcpcorev1alpha1 "github.com/kcp-dev/sdk/apis/core/v1alpha1" ) // fakeStatusWriter implements client.SubResourceWriter to intercept Status().Patch calls type fakeStatusWriter struct { t *testing.T - expectClear kcpv1alpha1.LogicalClusterInitializer + expectClear kcpcorev1alpha1.LogicalClusterInitializer err error } @@ -30,7 +30,7 @@ func (f *fakeStatusWriter) Update(ctx context.Context, obj client.Object, opts . } func (f *fakeStatusWriter) Patch(ctx context.Context, obj client.Object, patch client.Patch, opts ...client.SubResourcePatchOption) error { - lc := obj.(*kcpv1alpha1.LogicalCluster) + lc := obj.(*kcpcorev1alpha1.LogicalCluster) // Ensure initializer was removed before patch for _, init := range lc.Status.Initializers { if init == f.expectClear { @@ -48,8 +48,8 @@ func TestRemoveInitializer_Process(t *testing.T) { cluster := mocks.NewMockCluster(t) mgr.EXPECT().ClusterFromContext(mock.Anything).Return(cluster, nil) - lc := &kcpv1alpha1.LogicalCluster{} - lc.Status.Initializers = []kcpv1alpha1.LogicalClusterInitializer{"other.initializer"} + lc := &kcpcorev1alpha1.LogicalCluster{} + lc.Status.Initializers = []kcpcorev1alpha1.LogicalClusterInitializer{"other.initializer"} r := subroutine.NewRemoveInitializer(mgr, config.Config{InitializerName: initializerName}) _, err := r.Process(context.Background(), lc) @@ -63,11 +63,11 @@ func TestRemoveInitializer_Process(t *testing.T) { mgr.EXPECT().ClusterFromContext(mock.Anything).Return(cluster, nil) cluster.EXPECT().GetClient().Return(k8s) - k8s.EXPECT().Status().Return(&fakeStatusWriter{t: t, expectClear: kcpv1alpha1.LogicalClusterInitializer(initializerName), err: nil}) + k8s.EXPECT().Status().Return(&fakeStatusWriter{t: t, expectClear: kcpcorev1alpha1.LogicalClusterInitializer(initializerName), err: nil}) - lc := &kcpv1alpha1.LogicalCluster{} - lc.Status.Initializers = []kcpv1alpha1.LogicalClusterInitializer{ - kcpv1alpha1.LogicalClusterInitializer(initializerName), + lc := &kcpcorev1alpha1.LogicalCluster{} + lc.Status.Initializers = []kcpcorev1alpha1.LogicalClusterInitializer{ + kcpcorev1alpha1.LogicalClusterInitializer(initializerName), "another.initializer", } @@ -86,11 +86,11 @@ func TestRemoveInitializer_Process(t *testing.T) { mgr.EXPECT().ClusterFromContext(mock.Anything).Return(cluster, nil) cluster.EXPECT().GetClient().Return(k8s) - k8s.EXPECT().Status().Return(&fakeStatusWriter{t: t, expectClear: kcpv1alpha1.LogicalClusterInitializer(initializerName), err: assert.AnError}) + k8s.EXPECT().Status().Return(&fakeStatusWriter{t: t, expectClear: kcpcorev1alpha1.LogicalClusterInitializer(initializerName), err: assert.AnError}) - lc := &kcpv1alpha1.LogicalCluster{} - lc.Status.Initializers = []kcpv1alpha1.LogicalClusterInitializer{ - kcpv1alpha1.LogicalClusterInitializer(initializerName), + lc := &kcpcorev1alpha1.LogicalCluster{} + lc.Status.Initializers = []kcpcorev1alpha1.LogicalClusterInitializer{ + kcpcorev1alpha1.LogicalClusterInitializer(initializerName), } r := subroutine.NewRemoveInitializer(mgr, config.Config{InitializerName: initializerName}) @@ -106,7 +106,7 @@ func TestRemoveInitializer_Misc(t *testing.T) { assert.Equal(t, "RemoveInitializer", r.GetName()) assert.Equal(t, []string{}, r.Finalizers(nil)) - _, err := r.Finalize(context.Background(), &kcpv1alpha1.LogicalCluster{}) + _, err := r.Finalize(context.Background(), &kcpcorev1alpha1.LogicalCluster{}) assert.Nil(t, err) } @@ -115,6 +115,6 @@ func TestRemoveInitializer_ManagerError(t *testing.T) { mgr.EXPECT().ClusterFromContext(mock.Anything).Return(nil, assert.AnError) r := subroutine.NewRemoveInitializer(mgr, config.Config{InitializerName: "foo.initializer.kcp.dev"}) - _, err := r.Process(context.Background(), &kcpv1alpha1.LogicalCluster{}) + _, err := r.Process(context.Background(), &kcpcorev1alpha1.LogicalCluster{}) assert.NotNil(t, err) } diff --git a/internal/subroutine/workspace_authorization.go b/internal/subroutine/workspace_authorization.go index 4c83ad3..9c1d88c 100644 --- a/internal/subroutine/workspace_authorization.go +++ b/internal/subroutine/workspace_authorization.go @@ -22,8 +22,8 @@ import ( "k8s.io/apimachinery/pkg/types" "k8s.io/utils/ptr" - kcpv1alpha1 "github.com/kcp-dev/kcp/sdk/apis/core/v1alpha1" - kcptenancyv1alphav1 "github.com/kcp-dev/kcp/sdk/apis/tenancy/v1alpha1" + kcpcorev1alpha1 "github.com/kcp-dev/sdk/apis/core/v1alpha1" + kcptenancyv1alphav1 "github.com/kcp-dev/sdk/apis/tenancy/v1alpha1" ) type workspaceAuthSubroutine struct { @@ -55,7 +55,7 @@ func (r *workspaceAuthSubroutine) Finalize(ctx context.Context, instance runtime } func (r *workspaceAuthSubroutine) Process(ctx context.Context, instance runtimeobject.RuntimeObject) (reconcile.Result, errors.OperatorError) { - lc := instance.(*kcpv1alpha1.LogicalCluster) + lc := instance.(*kcpcorev1alpha1.LogicalCluster) workspaceName := getWorkspaceName(lc) if workspaceName == "" { diff --git a/internal/subroutine/workspace_authorization_test.go b/internal/subroutine/workspace_authorization_test.go index 1535a3c..51bcd55 100644 --- a/internal/subroutine/workspace_authorization_test.go +++ b/internal/subroutine/workspace_authorization_test.go @@ -19,14 +19,14 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" - kcpv1alpha1 "github.com/kcp-dev/kcp/sdk/apis/core/v1alpha1" - kcptenancyv1alphav1 "github.com/kcp-dev/kcp/sdk/apis/tenancy/v1alpha1" + kcpcorev1alpha1 "github.com/kcp-dev/sdk/apis/core/v1alpha1" + kcptenancyv1alphav1 "github.com/kcp-dev/sdk/apis/tenancy/v1alpha1" ) func TestWorkspaceAuthSubroutine_Process(t *testing.T) { tests := []struct { name string - logicalCluster *kcpv1alpha1.LogicalCluster + logicalCluster *kcpcorev1alpha1.LogicalCluster cfg config.Config setupMocks func(*mocks.MockClient) expectError bool @@ -34,7 +34,7 @@ func TestWorkspaceAuthSubroutine_Process(t *testing.T) { }{ { name: "success - create new WorkspaceAuthenticationConfiguration", - logicalCluster: &kcpv1alpha1.LogicalCluster{ + logicalCluster: &kcpcorev1alpha1.LogicalCluster{ ObjectMeta: metav1.ObjectMeta{ Annotations: map[string]string{ "kcp.io/path": "root:orgs:test-workspace", @@ -89,7 +89,7 @@ func TestWorkspaceAuthSubroutine_Process(t *testing.T) { }, { name: "success - update existing WorkspaceAuthenticationConfiguration", - logicalCluster: &kcpv1alpha1.LogicalCluster{ + logicalCluster: &kcpcorev1alpha1.LogicalCluster{ ObjectMeta: metav1.ObjectMeta{ Annotations: map[string]string{ "kcp.io/path": "root:orgs:existing-workspace", @@ -154,7 +154,7 @@ func TestWorkspaceAuthSubroutine_Process(t *testing.T) { }, { name: "error - missing workspace path annotation", - logicalCluster: &kcpv1alpha1.LogicalCluster{ + logicalCluster: &kcpcorev1alpha1.LogicalCluster{ ObjectMeta: metav1.ObjectMeta{ Annotations: map[string]string{}, }, @@ -166,7 +166,7 @@ func TestWorkspaceAuthSubroutine_Process(t *testing.T) { }, { name: "error - empty workspace path annotation", - logicalCluster: &kcpv1alpha1.LogicalCluster{ + logicalCluster: &kcpcorev1alpha1.LogicalCluster{ ObjectMeta: metav1.ObjectMeta{ Annotations: map[string]string{ "kcp.io/path": "", @@ -180,7 +180,7 @@ func TestWorkspaceAuthSubroutine_Process(t *testing.T) { }, { name: "error - create fails", - logicalCluster: &kcpv1alpha1.LogicalCluster{ + logicalCluster: &kcpcorev1alpha1.LogicalCluster{ ObjectMeta: metav1.ObjectMeta{ Annotations: map[string]string{ "kcp.io/path": "root:orgs:test-workspace", @@ -199,7 +199,7 @@ func TestWorkspaceAuthSubroutine_Process(t *testing.T) { }, { name: "error - update fails", - logicalCluster: &kcpv1alpha1.LogicalCluster{ + logicalCluster: &kcpcorev1alpha1.LogicalCluster{ ObjectMeta: metav1.ObjectMeta{ Annotations: map[string]string{ "kcp.io/path": "root:orgs:test-workspace", @@ -222,7 +222,7 @@ func TestWorkspaceAuthSubroutine_Process(t *testing.T) { }, { name: "error - get fails with non-not-found error", - logicalCluster: &kcpv1alpha1.LogicalCluster{ + logicalCluster: &kcpcorev1alpha1.LogicalCluster{ ObjectMeta: metav1.ObjectMeta{ Annotations: map[string]string{ "kcp.io/path": "root:orgs:test-workspace", @@ -239,7 +239,7 @@ func TestWorkspaceAuthSubroutine_Process(t *testing.T) { }, { name: "success - workspace path with single element", - logicalCluster: &kcpv1alpha1.LogicalCluster{ + logicalCluster: &kcpcorev1alpha1.LogicalCluster{ ObjectMeta: metav1.ObjectMeta{ Annotations: map[string]string{ "kcp.io/path": "single-workspace", @@ -291,7 +291,7 @@ func TestWorkspaceAuthSubroutine_Process(t *testing.T) { }, { name: "success - workspace path with single element and domain CA lookup", - logicalCluster: &kcpv1alpha1.LogicalCluster{ + logicalCluster: &kcpcorev1alpha1.LogicalCluster{ ObjectMeta: metav1.ObjectMeta{ Annotations: map[string]string{ "kcp.io/path": "single-workspace", @@ -357,7 +357,7 @@ func TestWorkspaceAuthSubroutine_Process(t *testing.T) { }, { name: "error - patchWorkspaceType fails for -org", - logicalCluster: &kcpv1alpha1.LogicalCluster{ + logicalCluster: &kcpcorev1alpha1.LogicalCluster{ ObjectMeta: metav1.ObjectMeta{ Annotations: map[string]string{ "kcp.io/path": "root:orgs:test-workspace", @@ -384,7 +384,7 @@ func TestWorkspaceAuthSubroutine_Process(t *testing.T) { }, { name: "error - patchWorkspaceType fails for -acc", - logicalCluster: &kcpv1alpha1.LogicalCluster{ + logicalCluster: &kcpcorev1alpha1.LogicalCluster{ ObjectMeta: metav1.ObjectMeta{ Annotations: map[string]string{ "kcp.io/path": "root:orgs:test-workspace", @@ -419,7 +419,7 @@ func TestWorkspaceAuthSubroutine_Process(t *testing.T) { }, { name: "error - domain CA secret Get fails", - logicalCluster: &kcpv1alpha1.LogicalCluster{ + logicalCluster: &kcpcorev1alpha1.LogicalCluster{ ObjectMeta: metav1.ObjectMeta{ Annotations: map[string]string{ "kcp.io/path": "root:orgs:test-workspace", @@ -441,7 +441,7 @@ func TestWorkspaceAuthSubroutine_Process(t *testing.T) { }, { name: "success - allow unverified emails in development mode", - logicalCluster: &kcpv1alpha1.LogicalCluster{ + logicalCluster: &kcpcorev1alpha1.LogicalCluster{ ObjectMeta: metav1.ObjectMeta{ Annotations: map[string]string{ "kcp.io/path": "root:orgs:dev-workspace", diff --git a/internal/subroutine/workspace_initializer.go b/internal/subroutine/workspace_initializer.go index 879cfc1..42be7c6 100644 --- a/internal/subroutine/workspace_initializer.go +++ b/internal/subroutine/workspace_initializer.go @@ -19,7 +19,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - kcpv1alpha1 "github.com/kcp-dev/kcp/sdk/apis/core/v1alpha1" + kcpcorev1alpha1 "github.com/kcp-dev/sdk/apis/core/v1alpha1" ) func NewWorkspaceInitializer(orgsClient client.Client, cfg config.Config, mgr mcmanager.Manager) *workspaceInitializer { @@ -58,7 +58,7 @@ func (w *workspaceInitializer) Finalizers(_ runtimeobject.RuntimeObject) []strin func (w *workspaceInitializer) GetName() string { return "WorkspaceInitializer" } func (w *workspaceInitializer) Process(ctx context.Context, instance runtimeobject.RuntimeObject) (ctrl.Result, errors.OperatorError) { - lc := instance.(*kcpv1alpha1.LogicalCluster) + lc := instance.(*kcpcorev1alpha1.LogicalCluster) store := v1alpha1.Store{ ObjectMeta: metav1.ObjectMeta{Name: generateStoreName(lc)}, @@ -111,7 +111,7 @@ func (w *workspaceInitializer) Process(ctx context.Context, instance runtimeobje return ctrl.Result{}, nil } -func generateStoreName(lc *kcpv1alpha1.LogicalCluster) string { +func generateStoreName(lc *kcpcorev1alpha1.LogicalCluster) string { if path, ok := lc.Annotations["kcp.io/path"]; ok { pathElements := strings.Split(path, ":") return pathElements[len(pathElements)-1] diff --git a/internal/test/integration/authorization_model_generation_test.go b/internal/test/integration/authorization_model_generation_test.go index 645532e..2868f22 100644 --- a/internal/test/integration/authorization_model_generation_test.go +++ b/internal/test/integration/authorization_model_generation_test.go @@ -15,12 +15,11 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" - kcpapiv1alpha1 "github.com/kcp-dev/kcp/sdk/apis/apis/v1alpha1" - "github.com/kcp-dev/kcp/sdk/apis/core" - tenancyv1alpha1 "github.com/kcp-dev/kcp/sdk/apis/tenancy/v1alpha1" "github.com/kcp-dev/logicalcluster/v3" clusterclient "github.com/kcp-dev/multicluster-provider/client" "github.com/kcp-dev/multicluster-provider/envtest" + kcpapiv1alpha1 "github.com/kcp-dev/sdk/apis/apis/v1alpha1" + "github.com/kcp-dev/sdk/apis/core" ) func (suite *IntegrationSuite) TestAuthorizationModelGeneration_Process() { @@ -42,9 +41,9 @@ func (suite *IntegrationSuite) TestAuthorizationModelGeneration_Process() { testAccount = "test-account" ) - _, testOrgPath := envtest.NewWorkspaceFixture(suite.T(), cli, orgsPath, envtest.WithName(testOrgName), envtest.WithType(core.RootCluster.Path(), tenancyv1alpha1.WorkspaceTypeName("org"))) + _, testOrgPath := envtest.NewWorkspaceFixture(suite.T(), cli, orgsPath, envtest.WithName(testOrgName), envtest.WithType(core.RootCluster.Path(), "org")) - _, testAccountPath := envtest.NewWorkspaceFixture(suite.T(), cli, testOrgPath, envtest.WithName(testAccount), envtest.WithType(core.RootCluster.Path(), tenancyv1alpha1.WorkspaceTypeName("account"))) + _, testAccountPath := envtest.NewWorkspaceFixture(suite.T(), cli, testOrgPath, envtest.WithName(testAccount), envtest.WithType(core.RootCluster.Path(), "account")) testAccountClient := cli.Cluster(testAccountPath) @@ -83,14 +82,14 @@ func (suite *IntegrationSuite) TestAuthorizationModelGeneration_Finalize() { testOrgName = "generator-test-finalize" ) - _, testOrgPath := envtest.NewWorkspaceFixture(suite.T(), cli, orgsPath, envtest.WithName(testOrgName), envtest.WithType(core.RootCluster.Path(), tenancyv1alpha1.WorkspaceTypeName("org"))) + _, testOrgPath := envtest.NewWorkspaceFixture(suite.T(), cli, orgsPath, envtest.WithName(testOrgName), envtest.WithType(core.RootCluster.Path(), "org")) testClient := cli.Cluster(testOrgPath) suite.createAccount(ctx, testClient, testAccount1Name, accountv1alpha1.AccountTypeAccount, suite.T()) suite.createAccount(ctx, testClient, testAccount2Name, accountv1alpha1.AccountTypeAccount, suite.T()) - _, testAccount1Path := envtest.NewWorkspaceFixture(suite.T(), cli, testOrgPath, envtest.WithName(testAccount1Name), envtest.WithType(core.RootCluster.Path(), tenancyv1alpha1.WorkspaceTypeName("account"))) - _, testAccount2Path := envtest.NewWorkspaceFixture(suite.T(), cli, testOrgPath, envtest.WithName(testAccount2Name), envtest.WithType(core.RootCluster.Path(), tenancyv1alpha1.WorkspaceTypeName("account"))) + _, testAccount1Path := envtest.NewWorkspaceFixture(suite.T(), cli, testOrgPath, envtest.WithName(testAccount1Name), envtest.WithType(core.RootCluster.Path(), "account")) + _, testAccount2Path := envtest.NewWorkspaceFixture(suite.T(), cli, testOrgPath, envtest.WithName(testAccount2Name), envtest.WithType(core.RootCluster.Path(), "account")) testAccount1Client := cli.Cluster(testAccount1Path) testAccount2Client := cli.Cluster(testAccount2Path) diff --git a/internal/test/integration/suite_test.go b/internal/test/integration/suite_test.go index d6c3e10..6617270 100644 --- a/internal/test/integration/suite_test.go +++ b/internal/test/integration/suite_test.go @@ -2,8 +2,9 @@ package test import ( "context" - "errors" + "fmt" "io" + "net/url" "testing" "time" @@ -15,29 +16,26 @@ import ( "github.com/spf13/cobra" "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" - "golang.org/x/sync/errgroup" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" mcmanager "sigs.k8s.io/multicluster-runtime/pkg/manager" "sigs.k8s.io/yaml" - eventsv1 "k8s.io/api/events/v1" kerrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" utilruntime "k8s.io/apimachinery/pkg/util/runtime" "k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/rest" - kcpapiv1alpha1 "github.com/kcp-dev/kcp/sdk/apis/apis/v1alpha1" - apisv1alpha2 "github.com/kcp-dev/kcp/sdk/apis/apis/v1alpha2" - "github.com/kcp-dev/kcp/sdk/apis/core" - corev1alpha1 "github.com/kcp-dev/kcp/sdk/apis/core/v1alpha1" - tenancyv1alpha1 "github.com/kcp-dev/kcp/sdk/apis/tenancy/v1alpha1" - topologyv1alpha1 "github.com/kcp-dev/kcp/sdk/apis/topology/v1alpha1" "github.com/kcp-dev/logicalcluster/v3" "github.com/kcp-dev/multicluster-provider/apiexport" clusterclient "github.com/kcp-dev/multicluster-provider/client" "github.com/kcp-dev/multicluster-provider/envtest" + apisv1alpha1 "github.com/kcp-dev/sdk/apis/apis/v1alpha1" + apisv1alpha2 "github.com/kcp-dev/sdk/apis/apis/v1alpha2" + "github.com/kcp-dev/sdk/apis/core" + corev1alpha1 "github.com/kcp-dev/sdk/apis/core/v1alpha1" + tenancyv1alpha1 "github.com/kcp-dev/sdk/apis/tenancy/v1alpha1" _ "embed" ) @@ -72,13 +70,12 @@ var ( ) func init() { - utilruntime.Must(kcpapiv1alpha1.AddToScheme(scheme.Scheme)) + utilruntime.Must(apisv1alpha1.AddToScheme(scheme.Scheme)) utilruntime.Must(corev1alpha1.AddToScheme(scheme.Scheme)) utilruntime.Must(tenancyv1alpha1.AddToScheme(scheme.Scheme)) - utilruntime.Must(topologyv1alpha1.AddToScheme(scheme.Scheme)) - utilruntime.Must(eventsv1.AddToScheme(scheme.Scheme)) utilruntime.Must(accountv1alpha1.AddToScheme(scheme.Scheme)) utilruntime.Must(securityv1alpha1.AddToScheme(scheme.Scheme)) + utilruntime.Must(apisv1alpha2.AddToScheme(scheme.Scheme)) } type IntegrationSuite struct { @@ -141,7 +138,7 @@ func (suite *IntegrationSuite) setupPlatformMesh(t *testing.T) { // register api-resource schemas schemas := [][]byte{AccountInfoSchemaYAML, AccountSchemaYAML, AuthorizationModelSchemaYAML, StoreSchemaYAML} for _, schemaYAML := range schemas { - var schema kcpapiv1alpha1.APIResourceSchema + var schema apisv1alpha1.APIResourceSchema suite.Require().NoError(yaml.Unmarshal(schemaYAML, &schema)) err = cli.Cluster(platformMeshSystemClusterPath).Create(ctx, &schema) if err != nil && !kerrors.IsAlreadyExists(err) { @@ -151,7 +148,7 @@ func (suite *IntegrationSuite) setupPlatformMesh(t *testing.T) { } suite.Require().NoError(err) - var apiExport kcpapiv1alpha1.APIExport + var apiExport apisv1alpha1.APIExport suite.Require().NoError(yaml.Unmarshal(ApiExportPlatformMeshSystemYAML, &apiExport)) err = cli.Cluster(platformMeshSystemClusterPath).Create(ctx, &apiExport) @@ -204,10 +201,10 @@ func (suite *IntegrationSuite) setupPlatformMesh(t *testing.T) { t.Log("created WorkspaceType 'account' in root workspace") // create :root:orgs ws - orgsWs, orgsClusterPath := envtest.NewWorkspaceFixture(suite.T(), cli, core.RootCluster.Path(), envtest.WithName("orgs"), envtest.WithType(core.RootCluster.Path(), tenancyv1alpha1.WorkspaceTypeName("orgs"))) + orgsWs, orgsClusterPath := envtest.NewWorkspaceFixture(suite.T(), cli, core.RootCluster.Path(), envtest.WithName("orgs"), envtest.WithType(core.RootCluster.Path(), "orgs")) t.Logf("orgs workspace path (%s), cluster id (%s)", orgsClusterPath, orgsWs.Spec.Cluster) - var endpointSlice kcpapiv1alpha1.APIExportEndpointSlice + var endpointSlice apisv1alpha1.APIExportEndpointSlice suite.Assert().Eventually(func() bool { err := cli.Cluster(platformMeshSystemClusterPath).Get(ctx, client.ObjectKey{Name: "core.platform-mesh.io"}, &endpointSlice) if err != nil { @@ -229,7 +226,10 @@ func (suite *IntegrationSuite) setupPlatformMesh(t *testing.T) { func (suite *IntegrationSuite) setupControllers(defaultCfg *platformeshconfig.CommonServiceConfig, testLogger *logger.Logger) { ctx := suite.T().Context() - provider, err := apiexport.New(suite.apiExportEndpointSliceConfig, apiexport.Options{Scheme: scheme.Scheme}) + providerConfig, err := suite.getPlatformMeshSystemConfig(suite.apiExportEndpointSliceConfig) + suite.Require().NoError(err) + + provider, err := apiexport.New(providerConfig, "core.platform-mesh.io", apiexport.Options{Scheme: scheme.Scheme}) suite.Require().NoError(err) mgr, err := mcmanager.New(suite.apiExportEndpointSliceConfig, provider, mcmanager.Options{ @@ -237,24 +237,19 @@ func (suite *IntegrationSuite) setupControllers(defaultCfg *platformeshconfig.Co }) suite.Require().NoError(err) + err = controller.NewAPIBindingReconciler(testLogger, mgr).SetupWithManager(mgr, defaultCfg) + suite.Require().NoError(err) + managerCtx, cancel := context.WithCancel(ctx) - eg, egCtx := errgroup.WithContext(managerCtx) - eg.Go(func() error { - return mgr.Start(egCtx) - }) - eg.Go(func() error { - return provider.Run(egCtx, mgr) - }) + go func() { + if err := mgr.Start(managerCtx); err != nil { + suite.T().Logf("controller manager exited with error: %v", err) + } + }() suite.T().Cleanup(func() { cancel() - if err := eg.Wait(); err != nil && !errors.Is(err, context.Canceled) { - suite.T().Logf("controller manager exited with error: %v", err) - } }) - - err = controller.NewAPIBindingReconciler(testLogger, mgr).SetupWithManager(mgr, defaultCfg) - suite.Require().NoError(err) } func (suite *IntegrationSuite) createAccount(ctx context.Context, client client.Client, accountName string, accountType accountv1alpha1.AccountType, t *testing.T) { @@ -306,3 +301,20 @@ func (suite *IntegrationSuite) createAccountInfo(ctx context.Context, accountCli } t.Logf("created accountInfo 'account' in %s workspace", accountPath) } + +func (suite *IntegrationSuite) getPlatformMeshSystemConfig(cfg *rest.Config) (*rest.Config, error) { + providerConfig := rest.CopyConfig(cfg) + + parsed, err := url.Parse(providerConfig.Host) + if err != nil { + return nil, fmt.Errorf("unable to parse URL: %w", err) + } + + parsed.Path, err = url.JoinPath("clusters", suite.platformMeshSysPath.String()) + if err != nil { + return nil, fmt.Errorf("failed to join path") + } + providerConfig.Host = parsed.String() + + return providerConfig, nil +}