From bdbca7b1fbad972590f3a704247e6c9021e4be2e Mon Sep 17 00:00:00 2001 From: Matous Jobanek Date: Tue, 20 Aug 2024 16:57:43 +0200 Subject: [PATCH 1/2] remove unused code, leftovers, and other zombies from sandbox-sre adoption (#60) --- pkg/assets/assets.go | 2 +- pkg/client/client.go | 23 +--- pkg/cmd/adm/restart_test.go | 2 +- pkg/cmd/ban.go | 2 - pkg/cmd/generate/assertion_test.go | 4 +- pkg/cmd/generate/cli_configs_test.go | 18 ++- pkg/configuration/configuration.go | 31 ----- pkg/context/clusterconfig_command_context.go | 36 ----- .../clusterconfig_command_context_test.go | 57 -------- pkg/test/client.go | 40 ------ pkg/test/object_assertions.go | 130 ------------------ pkg/test/usersignup.go | 37 +---- 12 files changed, 22 insertions(+), 360 deletions(-) delete mode 100644 pkg/context/clusterconfig_command_context.go delete mode 100644 pkg/context/clusterconfig_command_context_test.go diff --git a/pkg/assets/assets.go b/pkg/assets/assets.go index bdb4e8b..02d94b7 100644 --- a/pkg/assets/assets.go +++ b/pkg/assets/assets.go @@ -16,7 +16,7 @@ import ( runtimeclient "sigs.k8s.io/controller-runtime/pkg/client" ) -// interface that matches all the methods provided by embed.FS +// FS is an interface that matches all the methods provided by embed.FS type FS interface { fs.FS fs.ReadDirFS diff --git a/pkg/client/client.go b/pkg/client/client.go index 2242af4..14e96e8 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -24,7 +24,6 @@ import ( olmv1 "github.com/operator-framework/api/pkg/operators/v1" olmv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1" errs "github.com/pkg/errors" - authv1 "k8s.io/api/authentication/v1" corev1 "k8s.io/api/core/v1" rbacv1 "k8s.io/api/rbac/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" @@ -69,7 +68,7 @@ func NewClientWithTransport(token, apiEndpoint string, transport http.RoundTripp } cfg.Transport = transport - cfg.BearerToken = string(token) + cfg.BearerToken = token cfg.QPS = 40.0 cfg.Burst = 50 cfg.Timeout = 60 * time.Second @@ -119,26 +118,6 @@ func newTlsVerifySkippingTransport() http.RoundTripper { } } -var DefaultNewRESTClient = NewRESTClient - -func NewRESTClient(token, apiEndpoint string) (*rest.RESTClient, error) { - if err := AddToScheme(); err != nil { - return nil, err - } - config := &rest.Config{ - BearerToken: token, - Host: apiEndpoint, - Transport: newTlsVerifySkippingTransport(), - Timeout: 60 * time.Second, - // These fields need to be set when using the REST client ¯\_(ツ)_/¯ - ContentConfig: rest.ContentConfig{ - GroupVersion: &authv1.SchemeGroupVersion, - NegotiatedSerializer: scheme.Codecs, - }, - } - return rest.RESTClientFor(config) -} - func PatchUserSignup(ctx *clicontext.CommandContext, name string, changeUserSignup func(*toolchainv1alpha1.UserSignup) (bool, error), afterMessage string) error { cfg, err := configuration.LoadClusterConfig(ctx, configuration.HostName) if err != nil { diff --git a/pkg/cmd/adm/restart_test.go b/pkg/cmd/adm/restart_test.go index d9ec1d8..32197c3 100644 --- a/pkg/cmd/adm/restart_test.go +++ b/pkg/cmd/adm/restart_test.go @@ -246,7 +246,7 @@ func checkDeploymentBeingUpdated(t *testing.T, fakeClient *test.FakeClient, name // check the current deployment's replicas field AssertDeploymentHasReplicas(t, fakeClient, namespacedName, 0) // check the requested deployment's replicas field - assert.Equal(t, int32(currentReplicas), *deployment.Spec.Replicas) + assert.Equal(t, currentReplicas, *deployment.Spec.Replicas) } *numberOfUpdateCalls++ } diff --git a/pkg/cmd/ban.go b/pkg/cmd/ban.go index 4697061..4e12f81 100644 --- a/pkg/cmd/ban.go +++ b/pkg/cmd/ban.go @@ -28,8 +28,6 @@ only one parameter which is the name of the UserSignup to be used for banning`, } } -const BannedByLabel = toolchainv1alpha1.LabelKeyPrefix + "banned-by" - func Ban(ctx *clicontext.CommandContext, args ...string) error { return CreateBannedUser(ctx, args[0], func(userSignup *toolchainv1alpha1.UserSignup, bannedUser *toolchainv1alpha1.BannedUser) (bool, error) { if _, exists := bannedUser.Labels[toolchainv1alpha1.BannedUserPhoneNumberHashLabelKey]; !exists { diff --git a/pkg/cmd/generate/assertion_test.go b/pkg/cmd/generate/assertion_test.go index 3d4995e..90dc547 100644 --- a/pkg/cmd/generate/assertion_test.go +++ b/pkg/cmd/generate/assertion_test.go @@ -325,11 +325,11 @@ type groupsUserBelongsTo []string type extraGroupsPresentInCluster []string func groups(groups ...string) groupsUserBelongsTo { - return groupsUserBelongsTo(groups) + return groups } func extraGroupsUserIsNotPartOf(groups ...string) extraGroupsPresentInCluster { - return extraGroupsPresentInCluster(groups) + return groups } func (a userAssertion) belongsToGroups(groups groupsUserBelongsTo, extraGroups extraGroupsPresentInCluster) userAssertion { diff --git a/pkg/cmd/generate/cli_configs_test.go b/pkg/cmd/generate/cli_configs_test.go index ea1ec21..9aa1239 100644 --- a/pkg/cmd/generate/cli_configs_test.go +++ b/pkg/cmd/generate/cli_configs_test.go @@ -20,6 +20,7 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" + "k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/rest" ) @@ -232,9 +233,7 @@ func TestGetServiceAccountToken(t *testing.T) { setupGockForServiceAccounts(t, "https://api.example.com", 365, newServiceAccount("openshift-customer-monitoring", "loki")) t.Cleanup(gock.OffAll) - cl, err := client.NewRESTClient("secret_token", "https://api.example.com") - cl.Client.Transport = gock.DefaultTransport // make sure that the underlying client's request are intercepted by Gock - // gock.Observe(gock.DumpRequest) + cl, err := newGockRESTClient("secret_token", "https://api.example.com") require.NoError(t, err) // when actualToken, err := getServiceAccountToken(cl, types.NamespacedName{ @@ -247,6 +246,19 @@ func TestGetServiceAccountToken(t *testing.T) { assert.Equal(t, "token-secret-for-loki", actualToken) // `token-secret-for-loki` is the answered mock by Gock in `setupGockForServiceAccounts(...)` } +func newGockRESTClient(token, apiEndpoint string) (*rest.RESTClient, error) { + config := &rest.Config{ + BearerToken: token, + Host: apiEndpoint, + Transport: gock.DefaultTransport, // make sure that the underlying client's request are intercepted by Gock + ContentConfig: rest.ContentConfig{ + GroupVersion: &authv1.SchemeGroupVersion, + NegotiatedSerializer: scheme.Codecs, + }, + } + return rest.RESTClientFor(config) +} + func verifyKsctlConfigFiles(t *testing.T, tempDir string, clusterAssertions ...userConfigClusterAssertions) { tempDirInfo, err := os.ReadDir(tempDir) require.NoError(t, err) diff --git a/pkg/configuration/configuration.go b/pkg/configuration/configuration.go index d5bdccb..10cae1d 100644 --- a/pkg/configuration/configuration.go +++ b/pkg/configuration/configuration.go @@ -207,34 +207,3 @@ func (c ClusterConfig) GetServerParam() string { func (c ClusterConfig) GetNamespaceParam() string { return "--namespace=" + c.OperatorNamespace } - -// ConfigurePath returns the path to the 'configure' directory, using the clusterConfigName arg if it's not empty, -// or the Host cluster's server name (even if the current config applies to a Member cluster) -func (c ClusterConfig) ConfigurePath(term ioutils.Terminal, clusterConfigName, component string) (string, error) { - return c.Path(term, clusterConfigName, "configure", component) -} - -// InstallPath returns the path to the 'install' directory, using the clusterConfigName arg if it's not empty, -// or the Host cluster's server name (even if the current config applies to a Member cluster) -func (c ClusterConfig) InstallPath(term ioutils.Terminal, clusterConfigName, component string) (string, error) { - return c.Path(term, clusterConfigName, "install", component) -} - -// Path returns the path to the directory for the given action, using the clusterConfigName arg if it's not empty, -// or the Host cluster's server name (even if the current config applies to a Member cluster) -func (c ClusterConfig) Path(term ioutils.Terminal, clusterConfigName, section, component string) (string, error) { - baseDir := c.ServerName - if c.ClusterType == Member { - // for member clusters, we use the associated host's serverName to retrieve the configuration - var err error - clusterDef, err := LoadClusterAccessDefinition(term, HostName) - if err != nil { - return "", err - } - baseDir = clusterDef.ServerName - } - if clusterConfigName != "" { - baseDir = clusterConfigName - } - return fmt.Sprintf("%s/%s/%s/%s", baseDir, section, c.ClusterType, component), nil -} diff --git a/pkg/context/clusterconfig_command_context.go b/pkg/context/clusterconfig_command_context.go deleted file mode 100644 index 251eb94..0000000 --- a/pkg/context/clusterconfig_command_context.go +++ /dev/null @@ -1,36 +0,0 @@ -package context - -import ( - "path/filepath" - - "github.com/kubesaw/ksctl/pkg/assets" - "github.com/kubesaw/ksctl/pkg/configuration" - "github.com/kubesaw/ksctl/pkg/ioutils" -) - -// ClusterConfigCommandContext the context of the admin command to run -type ClusterConfigCommandContext struct { - CommandContext - Files assets.FS - ClusterConfig configuration.ClusterConfig - ClusterConfigName string -} - -// NewClusterConfigCommandContext returns the context of the admin command to run -func NewClusterConfigCommandContext(term ioutils.Terminal, cfg configuration.ClusterConfig, newClient NewClientFunc, files assets.FS, clusterConfigName string) *ClusterConfigCommandContext { - return &ClusterConfigCommandContext{ - CommandContext: CommandContext{ - Terminal: term, - NewClient: newClient, - }, - Files: files, - ClusterConfig: cfg, - ClusterConfigName: clusterConfigName, - } -} - -func (ctx *ClusterConfigCommandContext) GetFileContent(path ...string) ([]byte, error) { - p := filepath.Join(path...) - return ctx.Files.ReadFile(p) - -} diff --git a/pkg/context/clusterconfig_command_context_test.go b/pkg/context/clusterconfig_command_context_test.go deleted file mode 100644 index 68ba1d1..0000000 --- a/pkg/context/clusterconfig_command_context_test.go +++ /dev/null @@ -1,57 +0,0 @@ -package context_test - -import ( - "testing" - - "github.com/kubesaw/ksctl/pkg/configuration" - clicontext "github.com/kubesaw/ksctl/pkg/context" - . "github.com/kubesaw/ksctl/pkg/test" - "github.com/kubesaw/ksctl/resources" - - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" -) - -func TestConfigPath(t *testing.T) { - - // given - clusterConfigParams := []ClusterDefinitionWithName{ - Host(ServerName("host-cluster")), - Member(ServerName("member-cluster"))} - SetFileConfig(t, clusterConfigParams...) - - for _, clusterConfigParam := range clusterConfigParams { - - term := NewFakeTerminal() - clusterName := clusterConfigParam.ClusterName - cfg, err := configuration.LoadClusterConfig(term, clusterName) - require.NoError(t, err) - - t.Run(string(cfg.ClusterType), func(t *testing.T) { - - t.Run("with explicit clusterName", func(t *testing.T) { - // given - ctx := clicontext.NewClusterConfigCommandContext(term, cfg, nil, resources.Resources, "custom_path") - - // when - path, err := cfg.ConfigurePath(ctx, ctx.ClusterConfigName, "component") - - // then - require.NoError(t, err) - assert.Equal(t, "custom_path/configure/"+cfg.ClusterType.String()+"/component", path) - }) - - t.Run("without explicit clusterName", func(t *testing.T) { - // given - ctx := clicontext.NewClusterConfigCommandContext(term, cfg, nil, resources.Resources, "") // default path - - // when - path, err := cfg.ConfigurePath(ctx, ctx.ClusterConfigName, "component") - - // then - require.NoError(t, err) - assert.Equal(t, "host-cluster/configure/"+cfg.ClusterType.String()+"/component", path) // no matter if the cluster is the Host or a Member - }) - }) - } -} diff --git a/pkg/test/client.go b/pkg/test/client.go index d4154e7..96f2586 100644 --- a/pkg/test/client.go +++ b/pkg/test/client.go @@ -1,7 +1,6 @@ package test import ( - "context" "os/exec" "testing" @@ -9,25 +8,13 @@ import ( "github.com/kubesaw/ksctl/pkg/client" clicontext "github.com/kubesaw/ksctl/pkg/context" - "github.com/h2non/gock" "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/client-go/rest" runtimeclient "sigs.k8s.io/controller-runtime/pkg/client" ) func NewFakeClients(t *testing.T, initObjs ...runtime.Object) (clicontext.NewClientFunc, *test.FakeClient) { fakeClient := test.NewFakeClient(t, initObjs...) - fakeClient.MockCreate = func(ctx context.Context, obj runtimeclient.Object, opts ...runtimeclient.CreateOption) error { - stringDataToData(obj) - return fakeClient.Client.Create(ctx, obj, opts...) - } - fakeClient.MockUpdate = func(ctx context.Context, obj runtimeclient.Object, opts ...runtimeclient.UpdateOption) error { - stringDataToData(obj) - return fakeClient.Client.Update(ctx, obj, opts...) - } return func(token, apiEndpoint string) (runtimeclient.Client, error) { t.Helper() assert.Equal(t, "cool-token", token) @@ -39,33 +26,6 @@ func NewFakeClients(t *testing.T, initObjs ...runtime.Object) (clicontext.NewCli fakeClient } -func NewFakeExternalClient(t *testing.T, token string, apiEndpoint string) *rest.RESTClient { - t.Helper() - cl, err := client.NewRESTClient(token, apiEndpoint) - require.NoError(t, err) - // override the underlying client's transport with Gock to intercep requests - cl.Client.Transport = gock.DefaultTransport - return cl -} - -func stringDataToData(obj runtimeclient.Object) { - if obj.GetObjectKind().GroupVersionKind().Kind == "Secret" { - secret := obj.(*corev1.Secret) - if secret.Data == nil { - secret.Data = map[string][]byte{} - } - for key, value := range secret.StringData { - secret.Data[key] = []byte(value) - } - } -} - -func AssertArgsEqual(expArgs ...string) ArgsAssertion { - return func(t *testing.T, actualArgs ...string) { - assert.Equal(t, expArgs, actualArgs) - } -} - func AssertFirstArgPrefixRestEqual(firstArgPrefix string, toEqual ...string) ArgsAssertion { return func(t *testing.T, actualArgs ...string) { t.Helper() diff --git a/pkg/test/object_assertions.go b/pkg/test/object_assertions.go index a08a032..5e1b5d6 100644 --- a/pkg/test/object_assertions.go +++ b/pkg/test/object_assertions.go @@ -4,15 +4,11 @@ import ( "context" "testing" - toolchainv1alpha1 "github.com/codeready-toolchain/api/api/v1alpha1" - "github.com/codeready-toolchain/toolchain-common/pkg/test" - olmv1 "github.com/operator-framework/api/pkg/operators/v1" olmv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" appsv1 "k8s.io/api/apps/v1" - corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/types" runtimeclient "sigs.k8s.io/controller-runtime/pkg/client" @@ -32,19 +28,6 @@ func AssertCatalogSourceExists(t *testing.T, fakeClient runtimeclient.Client, na AssertObjectExists(t, fakeClient, namespacedName, actual) } -// AssertCatalogSourceDoesNotExist verifies that there is no CatalogSource resource with the given namespace/name -func AssertCatalogSourceDoesNotExist(t *testing.T, fakeClient runtimeclient.Client, namespacedName types.NamespacedName) { - AssertObjectDoesNotExist(t, fakeClient, namespacedName, &olmv1alpha1.CatalogSource{}) -} - -// AssertOperatorGroupHasSpec verifies that the there is an OperatorGroup resource matching the expected namespace/name, and with the same specs. -func AssertOperatorGroupHasSpec(t *testing.T, fakeClient runtimeclient.Client, namespacedName types.NamespacedName, expected olmv1.OperatorGroupSpec) { - actual := &olmv1.OperatorGroup{} - AssertObjectHasContent(t, fakeClient, namespacedName, actual, func() { - assert.Equal(t, expected, actual.Spec) - }) -} - // AssertOperatorGroupExists verifies that the there is a OperatorGroup resource matching the expected namespace/name func AssertOperatorGroupExists(t *testing.T, fakeClient runtimeclient.Client, namespacedName types.NamespacedName) { actual := &olmv1.OperatorGroup{} @@ -82,93 +65,6 @@ func AssertSubscriptionDoesNotExist(t *testing.T, fakeClient runtimeclient.Clien AssertObjectDoesNotExist(t, fakeClient, namespacedName, &olmv1alpha1.Subscription{}) } -// AssertToolchainConfigHasSpec verifies that there is an ToolchainConfig resource matching the expected namespace/name, and with the same spec. -func AssertToolchainConfigHasSpec(t *testing.T, fakeClient runtimeclient.Client, namespacedName types.NamespacedName, expected toolchainv1alpha1.ToolchainConfigSpec) { - actual := &toolchainv1alpha1.ToolchainConfig{} - AssertObjectHasContent(t, fakeClient, namespacedName, actual, func() { - assert.Equal(t, expected, actual.Spec) - }) -} - -// AssertToolchainConfigExists verifies that the there is an ToolchainConfig resource matching the expected namespace/name -func AssertToolchainConfigExists(t *testing.T, fakeClient runtimeclient.Client, namespacedName types.NamespacedName) { - actual := &toolchainv1alpha1.ToolchainConfig{} - AssertObjectExists(t, fakeClient, namespacedName, actual) -} - -// AssertToolchainConfigDoesNotExist verifies that there is no ToolchainConfig resource with the given namespace/name -func AssertToolchainConfigDoesNotExist(t *testing.T, fakeClient runtimeclient.Client, namespacedName types.NamespacedName) { - AssertObjectDoesNotExist(t, fakeClient, namespacedName, &toolchainv1alpha1.ToolchainConfig{}) -} - -// AssertConfigMapHasData verifies that the there is a ConfigMap resource matching the expected namespace/name, and with the same data. -func AssertConfigMapHasData(t *testing.T, fakeClient runtimeclient.Client, namespacedName types.NamespacedName, expected map[string]string) { - actual := &corev1.ConfigMap{} - AssertObjectHasContent(t, fakeClient, namespacedName, actual, func() { - assert.Equal(t, expected, actual.Data) - }) -} - -// AssertConfigMapExists verifies that the there is a ConfigMap resource matching the expected namespace/name -func AssertConfigMapExists(t *testing.T, fakeClient runtimeclient.Client, namespacedName types.NamespacedName) { - actual := &corev1.ConfigMap{} - AssertObjectExists(t, fakeClient, namespacedName, actual) -} - -// AssertConfigMapHasDataEntries verifies that the there is a ConfigMap resource matching the expected namespace/name, and with the given entries in its `data`. -func AssertConfigMapHasDataEntries(t *testing.T, fakeClient runtimeclient.Client, namespacedName types.NamespacedName, expectedEntries ...string) { - actual := &corev1.ConfigMap{} - err := fakeClient.Get(context.TODO(), namespacedName, actual) - require.NoError(t, err) - require.Len(t, actual.Data, len(expectedEntries)) - for _, e := range expectedEntries { - assert.Contains(t, actual.Data, e) - } -} - -// AssertConfigMapDoesNotExist verifies that there is no ConfigMap resource with the given namespace/name -func AssertConfigMapDoesNotExist(t *testing.T, fakeClient runtimeclient.Client, namespacedName types.NamespacedName) { - AssertObjectDoesNotExist(t, fakeClient, namespacedName, &corev1.ConfigMap{}) -} - -// AssertSecretHasData verifies that the there is a Secret resource matching the expected namespace/name, and with the same data. -func AssertSecretHasData(t *testing.T, fakeClient runtimeclient.Client, namespacedName types.NamespacedName, expected map[string][]byte) { - actual := &corev1.Secret{} - AssertObjectHasContent(t, fakeClient, namespacedName, actual, func() { - assert.Equal(t, expected, actual.Data) - }) -} - -// AssertSecretExists verifies that the there is a Secret resource matching the expected namespace/name -func AssertSecretExists(t *testing.T, fakeClient runtimeclient.Client, namespacedName types.NamespacedName) { - actual := &corev1.Secret{} - AssertObjectExists(t, fakeClient, namespacedName, actual) -} - -// AssertSecretHasDataEntries verifies that the there is a Secret resource matching the expected namespace/name, and with the given entries in its `data`. -func AssertSecretHasDataEntries(t *testing.T, fakeClient runtimeclient.Client, namespacedName types.NamespacedName, expectedEntries ...string) map[string][]byte { - actual := &corev1.Secret{} - err := fakeClient.Get(context.TODO(), namespacedName, actual) - require.NoError(t, err) - require.Len(t, actual.Data, len(expectedEntries)) - for _, e := range expectedEntries { - assert.Contains(t, actual.Data, e) - } - return actual.Data -} - -// AssertSecretDoesNotExist verifies that there is no Secret resource with the given namespace/name -func AssertSecretDoesNotExist(t *testing.T, fakeClient runtimeclient.Client, namespacedName types.NamespacedName) { - AssertObjectDoesNotExist(t, fakeClient, namespacedName, &corev1.Secret{}) -} - -func AssertServiceAccountHasImagePullSecret(t *testing.T, fakeClient runtimeclient.Client, saNamespacedName types.NamespacedName, secretName string) { - actual := &corev1.ServiceAccount{} - err := fakeClient.Get(context.TODO(), saNamespacedName, actual) - require.NoError(t, err) - assert.Contains(t, actual.ImagePullSecrets, corev1.LocalObjectReference{Name: secretName}) -} - // AssertDeploymentHasReplicas verifies that the there is a Deployment resource matching the expected namespace/name, and with the same spec.replicas. func AssertDeploymentHasReplicas(t *testing.T, fakeClient runtimeclient.Client, namespacedName types.NamespacedName, replicas int32) { actual := &appsv1.Deployment{} @@ -178,32 +74,6 @@ func AssertDeploymentHasReplicas(t *testing.T, fakeClient runtimeclient.Client, }) } -// ObjectAssertion is a type of function that should assert a content of an object -type ObjectAssertion func(t *testing.T, fakeClient *test.FakeClient) - -// ObjectExists checks that the given object exists and executes the given content assertion -func ObjectExists(namespace, name string, actualResource runtimeclient.Object, contentAssertion func(t *testing.T)) ObjectAssertion { - return func(t *testing.T, fakeClient *test.FakeClient) { - AssertObjectHasContent(t, fakeClient, test.NamespacedName(namespace, name), actualResource, func() { - contentAssertion(t) - }) - } -} - -// ObjectDoesNotExists checks that the given object does not exist -func ObjectDoesNotExists(namespace, name string, actualResource runtimeclient.Object) ObjectAssertion { - return func(t *testing.T, fakeClient *test.FakeClient) { - AssertObjectDoesNotExist(t, fakeClient, test.NamespacedName(namespace, name), actualResource) - } -} - -// AssertObjects executes all given object assertions -func AssertObjects(t *testing.T, fakeClient *test.FakeClient, objectAssertions ...ObjectAssertion) { - for _, assertObject := range objectAssertions { - assertObject(t, fakeClient) - } -} - // AssertObjectHasContent verifies that the there is a resource matching the expected namespace/name, and with the same specs. func AssertObjectHasContent(t *testing.T, fakeClient runtimeclient.Client, namespacedName types.NamespacedName, actualResource runtimeclient.Object, contentAssertions ...func()) { err := fakeClient.Get(context.TODO(), namespacedName, actualResource) diff --git a/pkg/test/usersignup.go b/pkg/test/usersignup.go index 1b47f58..2c8c36e 100644 --- a/pkg/test/usersignup.go +++ b/pkg/test/usersignup.go @@ -11,7 +11,6 @@ import ( uuid "github.com/google/uuid" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -58,46 +57,14 @@ func AssertUserSignupDoesNotExist(t *testing.T, fakeClient *test.FakeClient, use require.True(t, apierrors.IsNotFound(err), "the UserSignup should be deleted") } -func UserSignupCompleteCondition(status corev1.ConditionStatus, reason string) toolchainv1alpha1.Condition { - return toolchainv1alpha1.Condition{ - Type: toolchainv1alpha1.UserSignupComplete, - Status: status, - Reason: reason, - } -} - type UserSignupModifier func(userSignup *toolchainv1alpha1.UserSignup) -func UserSignupCompliantUsername(username string) UserSignupModifier { - return func(userSignup *toolchainv1alpha1.UserSignup) { - userSignup.Status.CompliantUsername = username - } -} - -func UserSignupTargetCluster(cluster string) UserSignupModifier { - return func(userSignup *toolchainv1alpha1.UserSignup) { - userSignup.Spec.TargetCluster = cluster - } -} - func UserSignupDeactivated(deactivated bool) UserSignupModifier { return func(userSignup *toolchainv1alpha1.UserSignup) { states.SetDeactivated(userSignup, deactivated) } } -func UserSignupStatusComplete(status corev1.ConditionStatus, reason string) UserSignupModifier { - return func(userSignup *toolchainv1alpha1.UserSignup) { - userSignup.Status.Conditions = []toolchainv1alpha1.Condition{UserSignupCompleteCondition(status, reason)} - } -} - -func UserSignupSetLabel(key, value string) UserSignupModifier { - return func(userSignup *toolchainv1alpha1.UserSignup) { - userSignup.Labels[key] = value - } -} - func UserSignupRemoveLabel(key string) UserSignupModifier { return func(userSignup *toolchainv1alpha1.UserSignup) { delete(userSignup.Labels, key) @@ -106,14 +73,14 @@ func UserSignupRemoveLabel(key string) UserSignupModifier { func UserSignupAutomaticallyApproved(_ bool) UserSignupModifier { return func(userSignup *toolchainv1alpha1.UserSignup) { - userSignup.Labels[toolchainv1alpha1.StateLabelKey] = string(toolchainv1alpha1.UserSignupStateLabelValueApproved) + userSignup.Labels[toolchainv1alpha1.StateLabelKey] = toolchainv1alpha1.UserSignupStateLabelValueApproved userSignup.Spec.States = nil } } func UserSignupApprovedByAdmin(_ bool) UserSignupModifier { return func(userSignup *toolchainv1alpha1.UserSignup) { - userSignup.Labels[toolchainv1alpha1.StateLabelKey] = string(toolchainv1alpha1.UserSignupStateLabelValueApproved) + userSignup.Labels[toolchainv1alpha1.StateLabelKey] = toolchainv1alpha1.UserSignupStateLabelValueApproved states.SetApprovedManually(userSignup, true) } } From 11497da6baacf7c93e8cb708f02a4c6d3e37e731 Mon Sep 17 00:00:00 2001 From: Matous Jobanek Date: Tue, 20 Aug 2024 17:27:26 +0200 Subject: [PATCH 2/2] remove sandbox-cli (#61) --- cmd/sandbox-cli/main.go | 23 ----------------------- 1 file changed, 23 deletions(-) delete mode 100644 cmd/sandbox-cli/main.go diff --git a/cmd/sandbox-cli/main.go b/cmd/sandbox-cli/main.go deleted file mode 100644 index 434d6be..0000000 --- a/cmd/sandbox-cli/main.go +++ /dev/null @@ -1,23 +0,0 @@ -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package main - -import ( - "fmt" - "os" -) - -func main() { - fmt.Println("ERROR: The sandbox-cli command has been migrated to ksctl. Please use ksctl instead.") - os.Exit(1) -}