From a3b32022c9d4662b85966d9d8d7dbf95311ed5f2 Mon Sep 17 00:00:00 2001 From: ytimocin Date: Wed, 3 Apr 2024 21:37:30 -0700 Subject: [PATCH] Remove double imports and some dead code Signed-off-by: ytimocin --- go.mod | 1 - pkg/cli/cmd/app/graph/display_test.go | 3 +- pkg/cli/cmd/app/graph/graph_test.go | 12 +-- pkg/cli/kubernetes/portforward/util_test.go | 15 ++-- pkg/corerp/handlers/kubernetes.go | 4 +- .../kubernetes_deployment_waiter_test.go | 26 +++---- .../renderers/daprextension/renderer_test.go | 8 +- .../kubernetesmetadata/render_test.go | 9 +-- pkg/sdk/pipeline.go | 17 ---- .../awsproxy/deleteawsresourcewithpost.go | 24 +++--- .../awsproxy/getawsoperationresults.go | 11 ++- .../awsproxy/getawsoperationstatuses.go | 18 ++--- .../controller/awsproxy/getawsresource.go | 16 ++-- .../awsproxy/getawsresourcewithpost.go | 22 +++--- .../controller/awsproxy/listawsresources.go | 12 +-- .../credentials/aws/deleteawscredential.go | 13 ++-- .../aws/deleteawscredential_test.go | 16 ++-- pkg/ucp/hostoptions/hostoptions.go | 12 --- pkg/ucp/ucplog/log.go | 9 --- pkg/version/version.go | 31 -------- test/radcli/cli.go | 77 ------------------- test/step/deployerrorexecutor.go | 7 -- test/testutil/testutil.go | 10 --- test/validation/k8s.go | 56 -------------- 24 files changed, 99 insertions(+), 330 deletions(-) diff --git a/go.mod b/go.mod index 1b7f8da633..e393b83a9f 100644 --- a/go.mod +++ b/go.mod @@ -146,7 +146,6 @@ require ( github.com/aws/aws-sdk-go-v2/service/ssooidc v1.14.14 // indirect github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect github.com/aymanbagabas/go-udiff v0.1.3 // indirect - github.com/benbjohnson/clock v1.1.0 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/cenkalti/backoff/v4 v4.2.1 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect diff --git a/pkg/cli/cmd/app/graph/display_test.go b/pkg/cli/cmd/app/graph/display_test.go index 331ed0fff8..e9e993e158 100644 --- a/pkg/cli/cmd/app/graph/display_test.go +++ b/pkg/cli/cmd/app/graph/display_test.go @@ -19,14 +19,13 @@ package graph import ( "testing" - "github.com/radius-project/radius/pkg/corerp/api/v20231001preview" corerpv20231001preview "github.com/radius-project/radius/pkg/corerp/api/v20231001preview" "github.com/stretchr/testify/require" ) func Test_display(t *testing.T) { t.Run("empty graph", func(t *testing.T) { - graph := []*v20231001preview.ApplicationGraphResource{} + graph := []*corerpv20231001preview.ApplicationGraphResource{} expected := `Displaying application: cool-app (empty) diff --git a/pkg/cli/cmd/app/graph/graph_test.go b/pkg/cli/cmd/app/graph/graph_test.go index 13cd207537..6482bb4c16 100644 --- a/pkg/cli/cmd/app/graph/graph_test.go +++ b/pkg/cli/cmd/app/graph/graph_test.go @@ -9,18 +9,18 @@ import ( "context" "testing" - "github.com/Azure/azure-sdk-for-go/sdk/azcore" - "github.com/golang/mock/gomock" v1 "github.com/radius-project/radius/pkg/armrpc/api/v1" "github.com/radius-project/radius/pkg/cli/clients" "github.com/radius-project/radius/pkg/cli/connections" "github.com/radius-project/radius/pkg/cli/framework" "github.com/radius-project/radius/pkg/cli/output" "github.com/radius-project/radius/pkg/cli/workspaces" - "github.com/radius-project/radius/pkg/corerp/api/v20231001preview" corerpv20231001preview "github.com/radius-project/radius/pkg/corerp/api/v20231001preview" "github.com/radius-project/radius/pkg/to" "github.com/radius-project/radius/test/radcli" + + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/golang/mock/gomock" "github.com/stretchr/testify/require" ) @@ -29,11 +29,11 @@ func Test_CommandValidation(t *testing.T) { } func Test_Validate(t *testing.T) { - application := v20231001preview.ApplicationResource{ + application := corerpv20231001preview.ApplicationResource{ Name: to.Ptr("test-app"), ID: to.Ptr(applicationResourceID), Type: to.Ptr("Applications.Core/applications"), - Properties: &v20231001preview.ApplicationProperties{ + Properties: &corerpv20231001preview.ApplicationProperties{ Environment: to.Ptr(environmentResourceID), }, } @@ -93,7 +93,7 @@ func Test_Validate(t *testing.T) { ConfigureMocks: func(mocks radcli.ValidateMocks) { mocks.ApplicationManagementClient.EXPECT(). ShowApplication(gomock.Any(), "test-app"). - Return(v20231001preview.ApplicationResource{}, &azcore.ResponseError{ErrorCode: v1.CodeNotFound}). + Return(corerpv20231001preview.ApplicationResource{}, &azcore.ResponseError{ErrorCode: v1.CodeNotFound}). Times(1) }, }, diff --git a/pkg/cli/kubernetes/portforward/util_test.go b/pkg/cli/kubernetes/portforward/util_test.go index 16de3651a5..dcdc65ebcf 100644 --- a/pkg/cli/kubernetes/portforward/util_test.go +++ b/pkg/cli/kubernetes/portforward/util_test.go @@ -24,7 +24,6 @@ import ( "github.com/stretchr/testify/require" appsv1 "k8s.io/api/apps/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/client-go/kubernetes/fake" ) @@ -34,7 +33,7 @@ func Test_findStaleReplicaSets(t *testing.T) { // Owned by d1 &appsv1.ReplicaSet{ - ObjectMeta: v1.ObjectMeta{ + ObjectMeta: metav1.ObjectMeta{ Name: "rs1a", Namespace: "default", OwnerReferences: []metav1.OwnerReference{ @@ -55,7 +54,7 @@ func Test_findStaleReplicaSets(t *testing.T) { // Also owned by d1, but newer revision &appsv1.ReplicaSet{ - ObjectMeta: v1.ObjectMeta{ + ObjectMeta: metav1.ObjectMeta{ Name: "rs1b", Namespace: "default", OwnerReferences: []metav1.OwnerReference{ @@ -76,7 +75,7 @@ func Test_findStaleReplicaSets(t *testing.T) { // Also owned by d1, but newer revision (not newest, though) &appsv1.ReplicaSet{ - ObjectMeta: v1.ObjectMeta{ + ObjectMeta: metav1.ObjectMeta{ Name: "rs1c", Namespace: "default", OwnerReferences: []metav1.OwnerReference{ @@ -97,7 +96,7 @@ func Test_findStaleReplicaSets(t *testing.T) { // Owned by d2 - only one replicaset is here, so it can't be stale &appsv1.ReplicaSet{ - ObjectMeta: v1.ObjectMeta{ + ObjectMeta: metav1.ObjectMeta{ Name: "rs2a", Namespace: "default", OwnerReferences: []metav1.OwnerReference{ @@ -118,7 +117,7 @@ func Test_findStaleReplicaSets(t *testing.T) { // No owner, ignored &appsv1.ReplicaSet{ - ObjectMeta: v1.ObjectMeta{ + ObjectMeta: metav1.ObjectMeta{ Name: "rs3a", Namespace: "default", Labels: map[string]string{ @@ -132,7 +131,7 @@ func Test_findStaleReplicaSets(t *testing.T) { // Not part of application, ignored &appsv1.ReplicaSet{ - ObjectMeta: v1.ObjectMeta{ + ObjectMeta: metav1.ObjectMeta{ Name: "rs4a", Namespace: "default", OwnerReferences: []metav1.OwnerReference{ @@ -150,7 +149,7 @@ func Test_findStaleReplicaSets(t *testing.T) { // Part of other application, ignored &appsv1.ReplicaSet{ - ObjectMeta: v1.ObjectMeta{ + ObjectMeta: metav1.ObjectMeta{ Name: "rs5a", Namespace: "default", OwnerReferences: []metav1.OwnerReference{ diff --git a/pkg/corerp/handlers/kubernetes.go b/pkg/corerp/handlers/kubernetes.go index 9555550c39..3fa5ec6d65 100644 --- a/pkg/corerp/handlers/kubernetes.go +++ b/pkg/corerp/handlers/kubernetes.go @@ -146,7 +146,7 @@ func (handler *kubernetesHandler) Put(ctx context.Context, options *PutOptions) // Delete decodes the identity data from the DeleteOptions, creates an unstructured object from the identity data, // and then attempts to delete the object from the Kubernetes cluster, returning an error if one occurs. func (handler *kubernetesHandler) Delete(ctx context.Context, options *DeleteOptions) error { - apiVersion, err := handler.lookupKubernetesAPIVersion(ctx, options.Resource.ID) + apiVersion, err := handler.lookupKubernetesAPIVersion(options.Resource.ID) if err != nil { return err } @@ -166,7 +166,7 @@ func (handler *kubernetesHandler) Delete(ctx context.Context, options *DeleteOpt return client.IgnoreNotFound(handler.client.Delete(ctx, &item)) } -func (handler *kubernetesHandler) lookupKubernetesAPIVersion(ctx context.Context, id resources.ID) (string, error) { +func (handler *kubernetesHandler) lookupKubernetesAPIVersion(id resources.ID) (string, error) { group, kind, namespace, _ := resources_kubernetes.ToParts(id) var resourceLists []*metav1.APIResourceList var err error diff --git a/pkg/corerp/handlers/kubernetes_deployment_waiter_test.go b/pkg/corerp/handlers/kubernetes_deployment_waiter_test.go index d16b6031cb..b376ebd8e3 100644 --- a/pkg/corerp/handlers/kubernetes_deployment_waiter_test.go +++ b/pkg/corerp/handlers/kubernetes_deployment_waiter_test.go @@ -91,7 +91,7 @@ func addReplicaSetToDeployment(t *testing.T, ctx context.Context, clientset *fak return replicaSet } -func startInformers(ctx context.Context, clientSet *fake.Clientset, handler *kubernetesHandler) informers.SharedInformerFactory { +func startInformers(ctx context.Context, clientSet *fake.Clientset) informers.SharedInformerFactory { // Create a fake replicaset informer and start informerFactory := informers.NewSharedInformerFactory(clientSet, 0) @@ -318,12 +318,9 @@ func TestGetPodsInDeployment(t *testing.T) { deploymentWaiter := &deploymentWaiter{ clientSet: fakeClient, } - handler := &kubernetesHandler{ - deploymentWaiter: deploymentWaiter, - } ctx := context.Background() - informerFactory := startInformers(ctx, fakeClient, handler) + informerFactory := startInformers(ctx, fakeClient) // Call the getPodsInDeployment function pods, err := deploymentWaiter.getPodsInDeployment(ctx, informerFactory, deployment, replicaset) @@ -408,12 +405,9 @@ func TestGetCurrentReplicaSetForDeployment(t *testing.T) { deploymentWaiter := &deploymentWaiter{ clientSet: fakeClient, } - handler := &kubernetesHandler{ - deploymentWaiter: deploymentWaiter, - } ctx := context.Background() - informerFactory := startInformers(ctx, fakeClient, handler) + informerFactory := startInformers(ctx, fakeClient) // Call the getNewestReplicaSetForDeployment function rs := deploymentWaiter.getCurrentReplicaSetForDeployment(ctx, informerFactory, deployment) @@ -624,7 +618,7 @@ func TestCheckAllPodsReady_Success(t *testing.T) { // Create an informer factory and add the deployment and replica set to the cache informerFactory := informers.NewSharedInformerFactory(clientset, 0) - addTestObjects(t, clientset, informerFactory, testDeployment, replicaSet, pod) + addTestObjects(t, informerFactory, testDeployment, replicaSet, pod) // Create a done channel doneCh := make(chan error) @@ -691,7 +685,7 @@ func TestCheckAllPodsReady_Fail(t *testing.T) { // Create an informer factory and add the deployment and replica set to the cache informerFactory := informers.NewSharedInformerFactory(clientset, 0) - addTestObjects(t, clientset, informerFactory, testDeployment, replicaSet, pod) + addTestObjects(t, informerFactory, testDeployment, replicaSet, pod) // Create a done channel doneCh := make(chan error) @@ -758,7 +752,7 @@ func TestCheckDeploymentStatus_AllReady(t *testing.T) { // Create an informer factory and add the deployment to the cache informerFactory := informers.NewSharedInformerFactory(fakeClient, 0) - addTestObjects(t, fakeClient, informerFactory, testDeployment, replicaSet, pod) + addTestObjects(t, informerFactory, testDeployment, replicaSet, pod) // Create a fake item and object item := &unstructured.Unstructured{ @@ -911,7 +905,7 @@ func TestCheckDeploymentStatus_PodsNotReady(t *testing.T) { // Create an informer factory and add the deployment to the cache informerFactory := informers.NewSharedInformerFactory(fakeClient, 0) - addTestObjects(t, fakeClient, informerFactory, testDeployment, replicaSet, pod) + addTestObjects(t, informerFactory, testDeployment, replicaSet, pod) // Create a fake item and object item := &unstructured.Unstructured{ @@ -993,7 +987,7 @@ func TestCheckDeploymentStatus_ObservedGenerationMismatch(t *testing.T) { // Create an informer factory and add the deployment to the cache informerFactory := informers.NewSharedInformerFactory(fakeClient, 0) - addTestObjects(t, fakeClient, informerFactory, generationMismatchDeployment, replicaSet, pod) + addTestObjects(t, informerFactory, generationMismatchDeployment, replicaSet, pod) // Create a fake item and object item := &unstructured.Unstructured{ @@ -1071,7 +1065,7 @@ func TestCheckDeploymentStatus_DeploymentNotProgressing(t *testing.T) { // Create an informer factory and add the deployment to the cache informerFactory := informers.NewSharedInformerFactory(fakeClient, 0) - addTestObjects(t, fakeClient, informerFactory, deploymentNotProgressing, replicaSet, pod) + addTestObjects(t, informerFactory, deploymentNotProgressing, replicaSet, pod) deploymentNotProgressing.Status = v1.DeploymentStatus{ Conditions: []v1.DeploymentCondition{ @@ -1106,7 +1100,7 @@ func TestCheckDeploymentStatus_DeploymentNotProgressing(t *testing.T) { require.False(t, ready) } -func addTestObjects(t *testing.T, fakeClient *fake.Clientset, informerFactory informers.SharedInformerFactory, deployment *v1.Deployment, replicaSet *v1.ReplicaSet, pod *corev1.Pod) { +func addTestObjects(t *testing.T, informerFactory informers.SharedInformerFactory, deployment *v1.Deployment, replicaSet *v1.ReplicaSet, pod *corev1.Pod) { err := informerFactory.Apps().V1().Deployments().Informer().GetIndexer().Add(deployment) require.NoError(t, err, "Failed to add deployment to informer cache") err = informerFactory.Apps().V1().ReplicaSets().Informer().GetIndexer().Add(replicaSet) diff --git a/pkg/corerp/renderers/daprextension/renderer_test.go b/pkg/corerp/renderers/daprextension/renderer_test.go index f1afe3ab67..9da41ccdd5 100644 --- a/pkg/corerp/renderers/daprextension/renderer_test.go +++ b/pkg/corerp/renderers/daprextension/renderer_test.go @@ -21,7 +21,6 @@ import ( "testing" apiv1 "github.com/radius-project/radius/pkg/armrpc/api/v1" - v1 "github.com/radius-project/radius/pkg/armrpc/api/v1" "github.com/radius-project/radius/pkg/corerp/datamodel" "github.com/radius-project/radius/pkg/corerp/renderers" "github.com/radius-project/radius/pkg/kubernetes" @@ -29,6 +28,7 @@ import ( rpv1 "github.com/radius-project/radius/pkg/rp/v1" "github.com/radius-project/radius/pkg/ucp/resources" resources_kubernetes "github.com/radius-project/radius/pkg/ucp/resources/kubernetes" + "github.com/stretchr/testify/require" appsv1 "k8s.io/api/apps/v1" ) @@ -36,11 +36,11 @@ import ( type noop struct { } -func (r *noop) GetDependencyIDs(ctx context.Context, dm v1.DataModelInterface) ([]resources.ID, []resources.ID, error) { +func (r *noop) GetDependencyIDs(ctx context.Context, dm apiv1.DataModelInterface) ([]resources.ID, []resources.ID, error) { return nil, nil, nil } -func (r *noop) Render(ctx context.Context, dm v1.DataModelInterface, options renderers.RenderOptions) (renderers.RendererOutput, error) { +func (r *noop) Render(ctx context.Context, dm apiv1.DataModelInterface, options renderers.RenderOptions) (renderers.RendererOutput, error) { // Return a deployment so the Dapr extension can modify it deployment := appsv1.Deployment{} @@ -106,7 +106,7 @@ func Test_Render_Success(t *testing.T) { func makeresource(t *testing.T, properties datamodel.ContainerProperties) *datamodel.ContainerResource { resource := datamodel.ContainerResource{ - BaseResource: v1.BaseResource{ + BaseResource: apiv1.BaseResource{ TrackedResource: apiv1.TrackedResource{ ID: "/subscriptions/test-sub-id/resourceGroups/test-group/providers/Applications.Core/containers/test-container", Name: "test-container", diff --git a/pkg/corerp/renderers/kubernetesmetadata/render_test.go b/pkg/corerp/renderers/kubernetesmetadata/render_test.go index 6baa0b49c1..9ec5f2f0fb 100644 --- a/pkg/corerp/renderers/kubernetesmetadata/render_test.go +++ b/pkg/corerp/renderers/kubernetesmetadata/render_test.go @@ -5,16 +5,15 @@ import ( "testing" apiv1 "github.com/radius-project/radius/pkg/armrpc/api/v1" - v1 "github.com/radius-project/radius/pkg/armrpc/api/v1" "github.com/radius-project/radius/pkg/corerp/datamodel" "github.com/radius-project/radius/pkg/corerp/renderers" "github.com/radius-project/radius/pkg/kubernetes" rpv1 "github.com/radius-project/radius/pkg/rp/v1" "github.com/radius-project/radius/pkg/ucp/resources" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "github.com/stretchr/testify/require" appsv1 "k8s.io/api/apps/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) var _ renderers.Renderer = (*noop)(nil) @@ -27,11 +26,11 @@ const ( type noop struct { } -func (r *noop) GetDependencyIDs(ctx context.Context, resource v1.DataModelInterface) ([]resources.ID, []resources.ID, error) { +func (r *noop) GetDependencyIDs(ctx context.Context, resource apiv1.DataModelInterface) ([]resources.ID, []resources.ID, error) { return nil, nil, nil } -func (r *noop) Render(ctx context.Context, dm v1.DataModelInterface, options renderers.RenderOptions) (renderers.RendererOutput, error) { +func (r *noop) Render(ctx context.Context, dm apiv1.DataModelInterface, options renderers.RenderOptions) (renderers.RendererOutput, error) { // Return a deployment so the kubernetes metadata extension renderer can modify it deployment := appsv1.Deployment{ ObjectMeta: metav1.ObjectMeta{ @@ -154,7 +153,7 @@ func TestApplicationDataModelToVersioned(t *testing.T) { func makeResource(t *testing.T, properties datamodel.ContainerProperties) *datamodel.ContainerResource { resource := datamodel.ContainerResource{ - BaseResource: v1.BaseResource{ + BaseResource: apiv1.BaseResource{ TrackedResource: apiv1.TrackedResource{ ID: container, Name: "test-container", diff --git a/pkg/sdk/pipeline.go b/pkg/sdk/pipeline.go index b52e1ae60c..940c537607 100644 --- a/pkg/sdk/pipeline.go +++ b/pkg/sdk/pipeline.go @@ -22,25 +22,8 @@ import ( "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" "github.com/Azure/azure-sdk-for-go/sdk/azcore/cloud" "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" - "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" ) -const ( - // module is used to build a runtime.Pipeline. This is informational text about the client that - // is added as part of the User-Agent header. - module = "v20231001preview" - - // version is used to build a runtime.Pipeline. This is informational text about the client that - // is added as part of the User-Agent header. - version = "v0.0.1" -) - -// NewPipeline builds a runtime.Pipeline from a Radius SDK connection. This is used to construct -// autorest Track2 Go clients. -func NewPipeline(connection Connection) runtime.Pipeline { - return runtime.NewPipeline(module, version, runtime.PipelineOptions{}, &NewClientOptions(connection).ClientOptions) -} - // NewClientOptions creates a new ARM client options object with the given connection's endpoint, audience, transport and // removes the authorization header policy. func NewClientOptions(connection Connection) *arm.ClientOptions { diff --git a/pkg/ucp/frontend/controller/awsproxy/deleteawsresourcewithpost.go b/pkg/ucp/frontend/controller/awsproxy/deleteawsresourcewithpost.go index a9fca38094..d7a2d89bcb 100644 --- a/pkg/ucp/frontend/controller/awsproxy/deleteawsresourcewithpost.go +++ b/pkg/ucp/frontend/controller/awsproxy/deleteawsresourcewithpost.go @@ -19,20 +19,20 @@ import ( "context" http "net/http" - "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/service/cloudcontrol" - "github.com/aws/aws-sdk-go-v2/service/cloudformation" - "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" - "github.com/google/uuid" v1 "github.com/radius-project/radius/pkg/armrpc/api/v1" armrpc_controller "github.com/radius-project/radius/pkg/armrpc/frontend/controller" armrpc_rest "github.com/radius-project/radius/pkg/armrpc/rest" "github.com/radius-project/radius/pkg/to" - awsclient "github.com/radius-project/radius/pkg/ucp/aws" - ucp_aws "github.com/radius-project/radius/pkg/ucp/aws" + ucpaws "github.com/radius-project/radius/pkg/ucp/aws" "github.com/radius-project/radius/pkg/ucp/aws/servicecontext" "github.com/radius-project/radius/pkg/ucp/datamodel" "github.com/radius-project/radius/pkg/ucp/ucplog" + + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/cloudcontrol" + "github.com/aws/aws-sdk-go-v2/service/cloudformation" + "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" + "github.com/google/uuid" ) var _ armrpc_controller.Controller = (*DeleteAWSResourceWithPost)(nil) @@ -40,7 +40,7 @@ var _ armrpc_controller.Controller = (*DeleteAWSResourceWithPost)(nil) // DeleteAWSResourceWithPost is the controller implementation to delete an AWS resource. type DeleteAWSResourceWithPost struct { armrpc_controller.Operation[*datamodel.AWSResource, datamodel.AWSResource] - awsClients ucp_aws.Clients + awsClients ucpaws.Clients } // NewDeleteAWSResourceWithPost creates a new DeleteAWSResourceWithPost. @@ -48,7 +48,7 @@ type DeleteAWSResourceWithPost struct { // NewDeleteAWSResourceWithPost creates a new DeleteAWSResourceWithPost controller which is used to delete an AWS resource // using a POST request. -func NewDeleteAWSResourceWithPost(opts armrpc_controller.Options, awsClients ucp_aws.Clients) (armrpc_controller.Controller, error) { +func NewDeleteAWSResourceWithPost(opts armrpc_controller.Options, awsClients ucpaws.Clients) (armrpc_controller.Controller, error) { return &DeleteAWSResourceWithPost{ Operation: armrpc_controller.NewOperation(opts, armrpc_controller.ResourceOptions[datamodel.AWSResource]{}), awsClients: awsClients, @@ -84,7 +84,7 @@ func (p *DeleteAWSResourceWithPost) Run(ctx context.Context, w http.ResponseWrit TypeName: to.Ptr(serviceCtx.ResourceTypeInAWSFormat()), }, cloudFormationOpts...) if err != nil { - return ucp_aws.HandleAWSError(err) + return ucpaws.HandleAWSError(err) } awsResourceIdentifier, err := getPrimaryIdentifierFromMultiIdentifiers(ctx, properties, *describeTypeOutput.Schema) @@ -104,10 +104,10 @@ func (p *DeleteAWSResourceWithPost) Run(ctx context.Context, w http.ResponseWrit Identifier: aws.String(awsResourceIdentifier), }, cloudControlOpts...) if err != nil { - if awsclient.IsAWSResourceNotFoundError(err) { + if ucpaws.IsAWSResourceNotFoundError(err) { return armrpc_rest.NewNoContentResponse(), nil } - return awsclient.HandleAWSError(err) + return ucpaws.HandleAWSError(err) } operation, err := uuid.Parse(*response.ProgressEvent.RequestToken) diff --git a/pkg/ucp/frontend/controller/awsproxy/getawsoperationresults.go b/pkg/ucp/frontend/controller/awsproxy/getawsoperationresults.go index 59a31df829..3215238ed3 100644 --- a/pkg/ucp/frontend/controller/awsproxy/getawsoperationresults.go +++ b/pkg/ucp/frontend/controller/awsproxy/getawsoperationresults.go @@ -25,8 +25,7 @@ import ( armrpcv1 "github.com/radius-project/radius/pkg/armrpc/api/v1" armrpc_controller "github.com/radius-project/radius/pkg/armrpc/frontend/controller" armrpc_rest "github.com/radius-project/radius/pkg/armrpc/rest" - awsclient "github.com/radius-project/radius/pkg/ucp/aws" - ucp_aws "github.com/radius-project/radius/pkg/ucp/aws" + ucpaws "github.com/radius-project/radius/pkg/ucp/aws" "github.com/radius-project/radius/pkg/ucp/aws/servicecontext" "github.com/radius-project/radius/pkg/ucp/datamodel" ) @@ -36,12 +35,12 @@ var _ armrpc_controller.Controller = (*GetAWSOperationResults)(nil) // GetAWSOperationResults is the controller implementation to get AWS resource operation results. type GetAWSOperationResults struct { armrpc_controller.Operation[*datamodel.AWSResource, datamodel.AWSResource] - awsClients ucp_aws.Clients + awsClients ucpaws.Clients } // NewGetAWSOperationResults creates a new GetAWSOperationResults controller with the given options and AWS clients, and // returns it without an error. -func NewGetAWSOperationResults(opts armrpc_controller.Options, awsClients ucp_aws.Clients) (armrpc_controller.Controller, error) { +func NewGetAWSOperationResults(opts armrpc_controller.Options, awsClients ucpaws.Clients) (armrpc_controller.Controller, error) { return &GetAWSOperationResults{ Operation: armrpc_controller.NewOperation(opts, armrpc_controller.ResourceOptions[datamodel.AWSResource]{}), awsClients: awsClients, @@ -62,10 +61,10 @@ func (p *GetAWSOperationResults) Run(ctx context.Context, w http.ResponseWriter, RequestToken: aws.String(serviceCtx.ResourceID.Name()), }, cloudControlOpts...) - if awsclient.IsAWSResourceNotFoundError(err) { + if ucpaws.IsAWSResourceNotFoundError(err) { return armrpc_rest.NewNotFoundResponse(serviceCtx.ResourceID), nil } else if err != nil { - return awsclient.HandleAWSError(err) + return ucpaws.HandleAWSError(err) } isTerminal := isStatusTerminal(response) diff --git a/pkg/ucp/frontend/controller/awsproxy/getawsoperationstatuses.go b/pkg/ucp/frontend/controller/awsproxy/getawsoperationstatuses.go index 7741fd1c4a..3398aceb2d 100644 --- a/pkg/ucp/frontend/controller/awsproxy/getawsoperationstatuses.go +++ b/pkg/ucp/frontend/controller/awsproxy/getawsoperationstatuses.go @@ -19,17 +19,17 @@ import ( "context" http "net/http" - "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/service/cloudcontrol" - "github.com/aws/aws-sdk-go-v2/service/cloudcontrol/types" armrpcv1 "github.com/radius-project/radius/pkg/armrpc/api/v1" manager "github.com/radius-project/radius/pkg/armrpc/asyncoperation/statusmanager" armrpc_controller "github.com/radius-project/radius/pkg/armrpc/frontend/controller" armrpc_rest "github.com/radius-project/radius/pkg/armrpc/rest" - awsclient "github.com/radius-project/radius/pkg/ucp/aws" - ucp_aws "github.com/radius-project/radius/pkg/ucp/aws" + ucpaws "github.com/radius-project/radius/pkg/ucp/aws" "github.com/radius-project/radius/pkg/ucp/aws/servicecontext" "github.com/radius-project/radius/pkg/ucp/datamodel" + + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/cloudcontrol" + "github.com/aws/aws-sdk-go-v2/service/cloudcontrol/types" ) var _ armrpc_controller.Controller = (*GetAWSOperationStatuses)(nil) @@ -37,11 +37,11 @@ var _ armrpc_controller.Controller = (*GetAWSOperationStatuses)(nil) // GetAWSOperationStatuses is the controller implementation to get AWS resource operation status. type GetAWSOperationStatuses struct { armrpc_controller.Operation[*datamodel.AWSResource, datamodel.AWSResource] - awsClients ucp_aws.Clients + awsClients ucpaws.Clients } // NewGetAWSOperationStatuses creates a new GetAWSOperationStatuses controller which is used to get the statuses of AWS operations. -func NewGetAWSOperationStatuses(opts armrpc_controller.Options, awsClients ucp_aws.Clients) (armrpc_controller.Controller, error) { +func NewGetAWSOperationStatuses(opts armrpc_controller.Options, awsClients ucpaws.Clients) (armrpc_controller.Controller, error) { return &GetAWSOperationStatuses{ Operation: armrpc_controller.NewOperation(opts, armrpc_controller.ResourceOptions[datamodel.AWSResource]{}), awsClients: awsClients, @@ -71,10 +71,10 @@ func (p *GetAWSOperationStatuses) Run(ctx context.Context, w http.ResponseWriter return armrpc_rest.NewNoContentResponse(), nil } - if awsclient.IsAWSResourceNotFoundError(err) { + if ucpaws.IsAWSResourceNotFoundError(err) { return armrpc_rest.NewNotFoundResponse(serviceCtx.ResourceID), nil } else if err != nil { - return awsclient.HandleAWSError(err) + return ucpaws.HandleAWSError(err) } opStatus := getAsyncOperationStatus(response) diff --git a/pkg/ucp/frontend/controller/awsproxy/getawsresource.go b/pkg/ucp/frontend/controller/awsproxy/getawsresource.go index 8c3131e3b6..1c266261f9 100644 --- a/pkg/ucp/frontend/controller/awsproxy/getawsresource.go +++ b/pkg/ucp/frontend/controller/awsproxy/getawsresource.go @@ -20,15 +20,15 @@ import ( "encoding/json" http "net/http" - "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/service/cloudcontrol" armrpc_controller "github.com/radius-project/radius/pkg/armrpc/frontend/controller" armrpc_rest "github.com/radius-project/radius/pkg/armrpc/rest" "github.com/radius-project/radius/pkg/to" - awsclient "github.com/radius-project/radius/pkg/ucp/aws" - ucp_aws "github.com/radius-project/radius/pkg/ucp/aws" + ucpaws "github.com/radius-project/radius/pkg/ucp/aws" "github.com/radius-project/radius/pkg/ucp/aws/servicecontext" "github.com/radius-project/radius/pkg/ucp/datamodel" + + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/cloudcontrol" ) var _ armrpc_controller.Controller = (*GetAWSResource)(nil) @@ -36,12 +36,12 @@ var _ armrpc_controller.Controller = (*GetAWSResource)(nil) // GetAWSResource is the controller implementation to get AWS resource. type GetAWSResource struct { armrpc_controller.Operation[*datamodel.AWSResource, datamodel.AWSResource] - awsClients ucp_aws.Clients + awsClients ucpaws.Clients } // NewGetAWSResource creates a new GetAWSResource controller with the given options and AWS clients, and returns it or an // error if one occurs. -func NewGetAWSResource(opts armrpc_controller.Options, awsClients ucp_aws.Clients) (armrpc_controller.Controller, error) { +func NewGetAWSResource(opts armrpc_controller.Options, awsClients ucpaws.Clients) (armrpc_controller.Controller, error) { return &GetAWSResource{ Operation: armrpc_controller.NewOperation(opts, armrpc_controller.ResourceOptions[datamodel.AWSResource]{}), awsClients: awsClients, @@ -62,10 +62,10 @@ func (p *GetAWSResource) Run(ctx context.Context, w http.ResponseWriter, req *ht TypeName: to.Ptr(serviceCtx.ResourceTypeInAWSFormat()), Identifier: aws.String(serviceCtx.ResourceID.Name()), }, cloudControlOpts...) - if awsclient.IsAWSResourceNotFoundError(err) { + if ucpaws.IsAWSResourceNotFoundError(err) { return armrpc_rest.NewNotFoundResponse(serviceCtx.ResourceID), nil } else if err != nil { - return awsclient.HandleAWSError(err) + return ucpaws.HandleAWSError(err) } properties := map[string]any{} diff --git a/pkg/ucp/frontend/controller/awsproxy/getawsresourcewithpost.go b/pkg/ucp/frontend/controller/awsproxy/getawsresourcewithpost.go index e60b63492a..aaaabfcef5 100644 --- a/pkg/ucp/frontend/controller/awsproxy/getawsresourcewithpost.go +++ b/pkg/ucp/frontend/controller/awsproxy/getawsresourcewithpost.go @@ -22,20 +22,20 @@ import ( http "net/http" "strings" - "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/service/cloudcontrol" - "github.com/aws/aws-sdk-go-v2/service/cloudformation" - "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" v1 "github.com/radius-project/radius/pkg/armrpc/api/v1" armrpc_controller "github.com/radius-project/radius/pkg/armrpc/frontend/controller" armrpc_rest "github.com/radius-project/radius/pkg/armrpc/rest" "github.com/radius-project/radius/pkg/middleware" "github.com/radius-project/radius/pkg/to" - awsclient "github.com/radius-project/radius/pkg/ucp/aws" - ucp_aws "github.com/radius-project/radius/pkg/ucp/aws" + ucpaws "github.com/radius-project/radius/pkg/ucp/aws" "github.com/radius-project/radius/pkg/ucp/aws/servicecontext" "github.com/radius-project/radius/pkg/ucp/datamodel" "github.com/radius-project/radius/pkg/ucp/ucplog" + + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/cloudcontrol" + "github.com/aws/aws-sdk-go-v2/service/cloudformation" + "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" ) var _ armrpc_controller.Controller = (*GetAWSResourceWithPost)(nil) @@ -43,11 +43,11 @@ var _ armrpc_controller.Controller = (*GetAWSResourceWithPost)(nil) // GetAWSResourceWithPost is the controller implementation to get an AWS resource. type GetAWSResourceWithPost struct { armrpc_controller.Operation[*datamodel.AWSResource, datamodel.AWSResource] - awsClients ucp_aws.Clients + awsClients ucpaws.Clients } // NewGetAWSResourceWithPost creates a new GetAWSResourceWithPost controller with the given options and AWS clients. -func NewGetAWSResourceWithPost(opts armrpc_controller.Options, awsClients ucp_aws.Clients) (armrpc_controller.Controller, error) { +func NewGetAWSResourceWithPost(opts armrpc_controller.Options, awsClients ucpaws.Clients) (armrpc_controller.Controller, error) { return &GetAWSResourceWithPost{ Operation: armrpc_controller.NewOperation(opts, armrpc_controller.ResourceOptions[datamodel.AWSResource]{}), awsClients: awsClients, @@ -83,7 +83,7 @@ func (p *GetAWSResourceWithPost) Run(ctx context.Context, w http.ResponseWriter, TypeName: to.Ptr(serviceCtx.ResourceTypeInAWSFormat()), }, cloudFormationOpts...) if err != nil { - return ucp_aws.HandleAWSError(err) + return ucpaws.HandleAWSError(err) } awsResourceIdentifier, err := getPrimaryIdentifierFromMultiIdentifiers(ctx, properties, *describeTypeOutput.Schema) @@ -105,10 +105,10 @@ func (p *GetAWSResourceWithPost) Run(ctx context.Context, w http.ResponseWriter, Identifier: aws.String(awsResourceIdentifier), }, cloudcontrolOpts...) - if awsclient.IsAWSResourceNotFoundError(err) { + if ucpaws.IsAWSResourceNotFoundError(err) { return armrpc_rest.NewNotFoundMessageResponse(constructNotFoundResponseMessage(middleware.GetRelativePath(p.Options().PathBase, req.URL.Path), awsResourceIdentifier)), nil } else if err != nil { - return awsclient.HandleAWSError(err) + return ucpaws.HandleAWSError(err) } resourceProperties := map[string]any{} diff --git a/pkg/ucp/frontend/controller/awsproxy/listawsresources.go b/pkg/ucp/frontend/controller/awsproxy/listawsresources.go index 2b9f4acf81..af6bf4884d 100644 --- a/pkg/ucp/frontend/controller/awsproxy/listawsresources.go +++ b/pkg/ucp/frontend/controller/awsproxy/listawsresources.go @@ -21,14 +21,14 @@ import ( http "net/http" "path" - "github.com/aws/aws-sdk-go-v2/service/cloudcontrol" armrpc_controller "github.com/radius-project/radius/pkg/armrpc/frontend/controller" armrpc_rest "github.com/radius-project/radius/pkg/armrpc/rest" "github.com/radius-project/radius/pkg/to" - awsclient "github.com/radius-project/radius/pkg/ucp/aws" - ucp_aws "github.com/radius-project/radius/pkg/ucp/aws" + ucpaws "github.com/radius-project/radius/pkg/ucp/aws" "github.com/radius-project/radius/pkg/ucp/aws/servicecontext" "github.com/radius-project/radius/pkg/ucp/datamodel" + + "github.com/aws/aws-sdk-go-v2/service/cloudcontrol" ) var _ armrpc_controller.Controller = (*ListAWSResources)(nil) @@ -36,11 +36,11 @@ var _ armrpc_controller.Controller = (*ListAWSResources)(nil) // ListAWSResources is the controller implementation to get/list AWS resources. type ListAWSResources struct { armrpc_controller.Operation[*datamodel.AWSResource, datamodel.AWSResource] - awsClients ucp_aws.Clients + awsClients ucpaws.Clients } // NewListAWSResources creates a new ListAWSResources controller with the given options and AWS clients. -func NewListAWSResources(opts armrpc_controller.Options, awsClients ucp_aws.Clients) (armrpc_controller.Controller, error) { +func NewListAWSResources(opts armrpc_controller.Options, awsClients ucpaws.Clients) (armrpc_controller.Controller, error) { return &ListAWSResources{ Operation: armrpc_controller.NewOperation(opts, armrpc_controller.ResourceOptions[datamodel.AWSResource]{}), awsClients: awsClients, @@ -62,7 +62,7 @@ func (p *ListAWSResources) Run(ctx context.Context, w http.ResponseWriter, req * TypeName: to.Ptr(serviceCtx.ResourceTypeInAWSFormat()), }, cloudControlOpts...) if err != nil { - return awsclient.HandleAWSError(err) + return ucpaws.HandleAWSError(err) } // TODO there some limitations with listing resources: diff --git a/pkg/ucp/frontend/controller/credentials/aws/deleteawscredential.go b/pkg/ucp/frontend/controller/credentials/aws/deleteawscredential.go index ed4800f74e..0f6b0b96aa 100644 --- a/pkg/ucp/frontend/controller/credentials/aws/deleteawscredential.go +++ b/pkg/ucp/frontend/controller/credentials/aws/deleteawscredential.go @@ -23,8 +23,7 @@ import ( v1 "github.com/radius-project/radius/pkg/armrpc/api/v1" armrpc_controller "github.com/radius-project/radius/pkg/armrpc/frontend/controller" - "github.com/radius-project/radius/pkg/armrpc/rest" - armrpc_rest "github.com/radius-project/radius/pkg/armrpc/rest" + armrpcrest "github.com/radius-project/radius/pkg/armrpc/rest" "github.com/radius-project/radius/pkg/ucp/datamodel" "github.com/radius-project/radius/pkg/ucp/datamodel/converter" "github.com/radius-project/radius/pkg/ucp/frontend/controller/credentials" @@ -56,7 +55,7 @@ func NewDeleteAWSCredential(opts armrpc_controller.Options, secretClient secret. // Run() checks if the AWS Credential exists, deletes the associated secret, and then deletes the AWS Credential from storage. // If the AWS Credential does not exist, it returns a No Content response. If an error occurs, it returns an error. -func (c *DeleteAWSCredential) Run(ctx context.Context, w http.ResponseWriter, req *http.Request) (armrpc_rest.Response, error) { +func (c *DeleteAWSCredential) Run(ctx context.Context, w http.ResponseWriter, req *http.Request) (armrpcrest.Response, error) { logger := ucplog.FromContextOrDiscard(ctx) serviceCtx := v1.ARMRequestContextFromContext(ctx) @@ -66,7 +65,7 @@ func (c *DeleteAWSCredential) Run(ctx context.Context, w http.ResponseWriter, re } if old == nil { - return rest.NewNoContentResponse(), nil + return armrpcrest.NewNoContentResponse(), nil } secretName := credentials.GetSecretName(serviceCtx.ResourceID) @@ -74,7 +73,7 @@ func (c *DeleteAWSCredential) Run(ctx context.Context, w http.ResponseWriter, re // Delete the credential secret. err = c.secretClient.Delete(ctx, secretName) if errors.Is(err, &secret.ErrNotFound{}) { - return armrpc_rest.NewNoContentResponse(), nil + return armrpcrest.NewNoContentResponse(), nil } else if err != nil { return nil, err } @@ -85,11 +84,11 @@ func (c *DeleteAWSCredential) Run(ctx context.Context, w http.ResponseWriter, re if err := c.StorageClient().Delete(ctx, serviceCtx.ResourceID.String()); err != nil { if errors.Is(&store.ErrNotFound{ID: serviceCtx.ResourceID.String()}, err) { - return rest.NewNoContentResponse(), nil + return armrpcrest.NewNoContentResponse(), nil } return nil, err } logger.Info(fmt.Sprintf("Deleted AWS Credential %s successfully", serviceCtx.ResourceID)) - return rest.NewOKResponse(nil), nil + return armrpcrest.NewOKResponse(nil), nil } diff --git a/pkg/ucp/frontend/controller/credentials/aws/deleteawscredential_test.go b/pkg/ucp/frontend/controller/credentials/aws/deleteawscredential_test.go index 5ffcf49335..5402e74c98 100644 --- a/pkg/ucp/frontend/controller/credentials/aws/deleteawscredential_test.go +++ b/pkg/ucp/frontend/controller/credentials/aws/deleteawscredential_test.go @@ -21,15 +21,15 @@ import ( "net/http" "testing" - "github.com/golang/mock/gomock" v1 "github.com/radius-project/radius/pkg/armrpc/api/v1" armrpc_controller "github.com/radius-project/radius/pkg/armrpc/frontend/controller" - "github.com/radius-project/radius/pkg/armrpc/rest" - armrpc_rest "github.com/radius-project/radius/pkg/armrpc/rest" + armrpcrest "github.com/radius-project/radius/pkg/armrpc/rest" "github.com/radius-project/radius/pkg/armrpc/rpctest" "github.com/radius-project/radius/pkg/ucp/datamodel" "github.com/radius-project/radius/pkg/ucp/secret" "github.com/radius-project/radius/pkg/ucp/store" + + "github.com/golang/mock/gomock" "github.com/stretchr/testify/require" ) @@ -47,7 +47,7 @@ func Test_Credential_Delete(t *testing.T) { url string headerfile string fn func(mockStorageClient store.MockStorageClient, mockSecretClient secret.MockClient) - expected armrpc_rest.Response + expected armrpcrest.Response err error }{ { @@ -55,7 +55,7 @@ func Test_Credential_Delete(t *testing.T) { url: "/planes/aws/awscloud/providers/System.AWS/credentials/default?api-version=2023-10-01-preview", headerfile: testHeaderFile, fn: setupCredentialDeleteSuccessMocks, - expected: rest.NewOKResponse(nil), + expected: armrpcrest.NewOKResponse(nil), err: nil, }, { @@ -63,7 +63,7 @@ func Test_Credential_Delete(t *testing.T) { url: "/planes/aws/awscloud/providers/System.AWS/credentials/default?api-version=2023-10-01-preview", headerfile: testHeaderFile, fn: setupNonExistentCredentialDeleteMocks, - expected: armrpc_rest.NewNoContentResponse(), + expected: armrpcrest.NewNoContentResponse(), err: nil, }, { @@ -79,7 +79,7 @@ func Test_Credential_Delete(t *testing.T) { url: "/planes/aws/awscloud/providers/System.AWS/credentials/default?api-version=2023-10-01-preview", headerfile: testHeaderFile, fn: setupNonExistentSecretDeleteMocks, - expected: armrpc_rest.NewNoContentResponse(), + expected: armrpcrest.NewNoContentResponse(), err: nil, }, { @@ -95,7 +95,7 @@ func Test_Credential_Delete(t *testing.T) { url: "/planes/aws/awscloud/providers/System.AWS/credentials/default?api-version=2023-10-01-preview", headerfile: testHeaderFile, fn: setupNonExistingCredentialDeleteFromStorageMocks, - expected: armrpc_rest.NewNoContentResponse(), + expected: armrpcrest.NewNoContentResponse(), err: nil, }, { diff --git a/pkg/ucp/hostoptions/hostoptions.go b/pkg/ucp/hostoptions/hostoptions.go index de4605bc3f..db708f73b5 100644 --- a/pkg/ucp/hostoptions/hostoptions.go +++ b/pkg/ucp/hostoptions/hostoptions.go @@ -20,11 +20,9 @@ package hostoptions import ( "bytes" - "context" "fmt" "os" - v1 "github.com/radius-project/radius/pkg/armrpc/api/v1" "gopkg.in/yaml.v3" ) @@ -64,13 +62,3 @@ func loadConfig(configPath string) (*UCPConfig, error) { return conf, nil } - -// FromContext extracts ProviderConfig from http context. -func FromContext(ctx context.Context) *UCPConfig { - return ctx.Value(v1.HostingConfigContextKey).(*UCPConfig) -} - -// WithContext injects ProviderConfig into the given http context. -func WithContext(ctx context.Context, cfg *UCPConfig) context.Context { - return context.WithValue(ctx, v1.HostingConfigContextKey, cfg) -} diff --git a/pkg/ucp/ucplog/log.go b/pkg/ucp/ucplog/log.go index 22f42c35a2..62b22974e0 100644 --- a/pkg/ucp/ucplog/log.go +++ b/pkg/ucp/ucplog/log.go @@ -21,7 +21,6 @@ import ( "fmt" "os" "strings" - "testing" "github.com/go-logr/logr" "github.com/go-logr/zapr" @@ -29,7 +28,6 @@ import ( "go.opentelemetry.io/otel/trace" "go.uber.org/zap" "go.uber.org/zap/zapcore" - "go.uber.org/zap/zaptest" ) // Radius uses the Zapr: https://github.com/go-logr/zapr which implements a logr interface @@ -159,13 +157,6 @@ func NewLogger(name string, options *LoggingOptions) (logr.Logger, func(), error return logger, flushLogs, nil } -// NewTestLogger creates a new logger zaptest logger implementation. -func NewTestLogger(t *testing.T) (logr.Logger, error) { - zapLogger := zaptest.NewLogger(t) - logger := zapr.NewLogger(zapLogger) - return logger, nil -} - // WrapLogContext adds key-value pairs to the context's logger for logging purposes. func WrapLogContext(ctx context.Context, keyValues ...any) context.Context { logger := logr.FromContextOrDiscard(ctx) diff --git a/pkg/version/version.go b/pkg/version/version.go index 9e4c596d2c..9e2656cc36 100644 --- a/pkg/version/version.go +++ b/pkg/version/version.go @@ -16,13 +16,6 @@ limitations under the License. package version -import ( - "encoding/json" - "fmt" - - "github.com/radius-project/radius/pkg/cli/output" -) - // Values for these are injected by the build. var ( channel = "edge" @@ -92,27 +85,3 @@ func Version() string { func ChartVersion() string { return chartVersion } - -// VersionString formats and returns a string containing version information in either JSON or plain text format. -func VersionString(format string, v VersionInfo, bicepVersion string) string { - var displayVersion = struct { - Release string `json:"release"` - Version string `json:"version"` - Bicep string `json:"bicep"` - Commit string `json:"commit"` - }{ - v.Release, - v.Version, - bicepVersion, - v.Commit, - } - - switch format { - case output.FormatJson: - jsonStr, _ := json.MarshalIndent(displayVersion, "", " ") - return fmt.Sprintln(string(jsonStr)) - default: - formatStr := "Release: %s \nVersion: %s\nBicep version: %s\nCommit: %s\n" - return fmt.Sprintf(formatStr, displayVersion.Release, displayVersion.Version, displayVersion.Bicep, displayVersion.Commit) - } -} diff --git a/test/radcli/cli.go b/test/radcli/cli.go index 9556f75bf8..0b548607cb 100644 --- a/test/radcli/cli.go +++ b/test/radcli/cli.go @@ -128,44 +128,6 @@ func (cli *CLI) Deploy(ctx context.Context, templateFilePath string, environment return cliErr } -// Run runs the rad run command. This returns the command output on success or an error. -func (cli *CLI) Run(ctx context.Context, templateFilePath string, applicationName string, parameters ...string) (string, error) { - // Check if the template file path exists - if _, err := os.Stat(templateFilePath); err != nil { - return "", fmt.Errorf("could not find template file: %s - %w", templateFilePath, err) - } - - args := []string{ - "run", - templateFilePath, - } - - if applicationName != "" { - args = append(args, "--application", applicationName) - } - - for _, parameter := range parameters { - args = append(args, "--parameters", parameter) - } - - out, cliErr := cli.RunCommand(ctx, args) - if cliErr != nil && strings.Contains(out, "Error: {") { - var errResponse v1.ErrorResponse - idx := strings.Index(out, "Error: {") - actualErr := "{\"error\": " + out[idx+7:] + "}" - - if err := json.Unmarshal([]byte(string(actualErr)), &errResponse); err != nil { - return "", err - } - - return "", &CLIError{ErrorResponse: errResponse} - } else if cliErr != nil { - return "", cliErr - } - - return out, nil -} - // ApplicationShow returns the output of running the "application show" command with the given application name as // an argument, or an error if the command fails. func (cli *CLI) ApplicationShow(ctx context.Context, applicationName string) (string, error) { @@ -179,18 +141,6 @@ func (cli *CLI) ApplicationShow(ctx context.Context, applicationName string) (st return cli.RunCommand(ctx, args) } -// ApplicationList runs a command to list applications and returns the output as a string. It returns an -// error if the command fails. -func (cli *CLI) ApplicationList(ctx context.Context) (string, error) { - command := "application" - - args := []string{ - command, - "list", - } - return cli.RunCommand(ctx, args) -} - // ApplicationDelete deletes the specified application deployed by Radius and returns an error if one occurs. func (cli *CLI) ApplicationDelete(ctx context.Context, applicationName string) error { command := "application" @@ -205,33 +155,6 @@ func (cli *CLI) ApplicationDelete(ctx context.Context, applicationName string) e return err } -// EnvStatus runs the "env status" command and returns the output as a string. It returns an error if the command fails. -func (cli *CLI) EnvStatus(ctx context.Context) (string, error) { - args := []string{ - "env", - "status", - } - return cli.RunCommand(ctx, args) -} - -// EnvShow runs the "env show" command and returns the output as a string, or an error if the command fails. -func (cli *CLI) EnvShow(ctx context.Context) (string, error) { - args := []string{ - "env", - "show", - } - return cli.RunCommand(ctx, args) -} - -// EnvList runs the "env list" command and returns the output as a string, or an error if the command fails. -func (cli *CLI) EnvList(ctx context.Context) (string, error) { - args := []string{ - "env", - "list", - } - return cli.RunCommand(ctx, args) -} - // EnvDelete runs the command to delete an environment with the given name and returns an error if the command fails. func (cli *CLI) EnvDelete(ctx context.Context, environmentName string) error { args := []string{ diff --git a/test/step/deployerrorexecutor.go b/test/step/deployerrorexecutor.go index 0132c7c994..8d9f2256b9 100644 --- a/test/step/deployerrorexecutor.go +++ b/test/step/deployerrorexecutor.go @@ -144,13 +144,6 @@ func (detail DeploymentErrorDetail) Matches(candidate v1.ErrorDetails) bool { return true } -// ValidateCode reports success if the error code matches the expected code. -func ValidateCode(code string) func(*testing.T, *radcli.CLIError) { - return func(t *testing.T, err *radcli.CLIError) { - require.Equal(t, code, err.ErrorResponse.Error.Code, "unexpected error code") - } -} - // ValidateSingleDetail reports success if the error code matches the expected code and the detail item is found in the error response.. func ValidateSingleDetail(code string, detail DeploymentErrorDetail) func(*testing.T, *radcli.CLIError) { return func(t *testing.T, err *radcli.CLIError) { diff --git a/test/testutil/testutil.go b/test/testutil/testutil.go index e76450326d..f645cd31bf 100644 --- a/test/testutil/testutil.go +++ b/test/testutil/testutil.go @@ -20,7 +20,6 @@ import ( "context" "encoding/json" "fmt" - "log" "net/http" "os" "path/filepath" @@ -246,15 +245,6 @@ func ExposePod(t *testing.T, ctx context.Context, client *k8s.Clientset, config portChan <- int(ports[0].Local) } -// NewTestLogger creates a new logger that writes to the testing.T object. -func NewTestLogger(t *testing.T) *log.Logger { - tw := TestWriter{t} - logger := log.Logger{} - logger.SetOutput(tw) - - return &logger -} - // IsMapSubSet returns true if the expectedMap is a subset of the actualMap func IsMapSubSet(expectedMap map[string]string, actualMap map[string]string) bool { if len(expectedMap) > len(actualMap) { diff --git a/test/validation/k8s.go b/test/validation/k8s.go index e612b9553f..b10e109bc9 100644 --- a/test/validation/k8s.go +++ b/test/validation/k8s.go @@ -138,67 +138,11 @@ func NewK8sSecretForResourceWithResourceName(resourceName string) K8sObject { } } -// ValidateDeploymentsRunning checks if the expected deployments have been created in the given namespace and logs any -// unrecognized deployments. If all expected deployments have been created, it returns, otherwise it retries until the -// context is done. -func ValidateDeploymentsRunning(ctx context.Context, t *testing.T, k8s *kubernetes.Clientset, expected K8sObjectSet) { - for namespace, expectedPods := range expected.Namespaces { - t.Logf("validating deployments in namespace %v", namespace) - for { - select { - case <-time.After(IntervalForDeploymentCreation): - t.Logf("at %s waiting for deployments in namespace %s to appear.. ", time.Now().Format("2006-01-02 15:04:05"), namespace) - - var err error - deployments, err := k8s.AppsV1().Deployments(namespace).List(ctx, metav1.ListOptions{}) - require.NoErrorf(t, err, "failed to list pods in namespace %v", namespace) - - remaining := make([]K8sObject, len(expectedPods)) - copy(remaining, expectedPods) - - for _, actualDeployment := range deployments.Items { - // validate that this matches one of our expected deployment - index := matchesExpectedLabels(remaining, actualDeployment.Labels) - if index == nil { - // this is not a match, check if it has a Radius Application label - t.Log(t, - "unrecognized deployment, could not find a match for Deployment with namespace: %v name: %v labels: %v", - actualDeployment.Namespace, - actualDeployment.Name, - actualDeployment.Labels) - continue - } - - // trim the list of 'remaining' deployments - remaining = append(remaining[:*index], remaining[*index+1:]...) - } - - if len(remaining) == 0 { - return - } - for _, remainingPod := range remaining { - t.Logf("failed to match deployment in namespace %v with labels %v, retrying", namespace, remainingPod.Labels) - } - - case <-ctx.Done(): - assert.Fail(t, "timed out after waiting for deployments to be created") - return - } - } - } -} - // SaveContainerLogs watches for all pods in the given namespace and saves their container logs to disk. func SaveContainerLogs(ctx context.Context, k8s *kubernetes.Clientset, namespace string, logPrefix string) (watchk8s.Interface, error) { return watchForPods(ctx, k8s, namespace, logPrefix, "") } -// SaveLogsForApplication watches for all radius pods that are part of the given application in a given namespace -// and saves their container logs to disk. -func SaveLogsForApplication(ctx context.Context, k8s *kubernetes.Clientset, namespace string, logPrefix string, appName string) (watchk8s.Interface, error) { - return watchForPods(ctx, k8s, namespace, logPrefix, fmt.Sprintf("%s=%s", kuberneteskeys.LabelRadiusApplication, appName)) -} - func watchForPods(ctx context.Context, k8s *kubernetes.Clientset, namespace string, logPrefix string, labelSelector string) (watchk8s.Interface, error) { if err := os.MkdirAll(logPrefix, os.ModePerm); err != nil { log.Printf("Failed to create output log directory '%s' Error was: '%q'. Container logs will be discarded", logPrefix, err)