Skip to content

Commit

Permalink
Remove double imports and some dead code
Browse files Browse the repository at this point in the history
Signed-off-by: ytimocin <ytimocin@microsoft.com>
  • Loading branch information
ytimocin committed Apr 4, 2024
1 parent 6b0d59a commit 66cac7f
Show file tree
Hide file tree
Showing 24 changed files with 99 additions and 348 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions pkg/cli/cmd/app/graph/display_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions pkg/cli/cmd/app/graph/graph_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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),
},
}
Expand Down Expand Up @@ -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)
},
},
Expand Down
15 changes: 7 additions & 8 deletions pkg/cli/kubernetes/portforward/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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{
Expand All @@ -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{
Expand All @@ -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{
Expand All @@ -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{
Expand All @@ -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{
Expand All @@ -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{
Expand All @@ -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{
Expand Down
4 changes: 2 additions & 2 deletions pkg/corerp/handlers/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
Expand Down
26 changes: 10 additions & 16 deletions pkg/corerp/handlers/kubernetes_deployment_waiter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions pkg/corerp/renderers/daprextension/renderer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,26 @@ 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"
"github.com/radius-project/radius/pkg/resourcemodel"
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"
)

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{}

Expand Down Expand Up @@ -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",
Expand Down
9 changes: 4 additions & 5 deletions pkg/corerp/renderers/kubernetesmetadata/render_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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{
Expand Down Expand Up @@ -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",
Expand Down
17 changes: 0 additions & 17 deletions pkg/sdk/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading

0 comments on commit 66cac7f

Please sign in to comment.