Skip to content

Commit

Permalink
remove dead code (#1125)
Browse files Browse the repository at this point in the history
Signed-off-by: Kent <[email protected]>
  • Loading branch information
krancour authored Nov 17, 2023
1 parent ddf5ded commit 730e2a0
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 150 deletions.
29 changes: 0 additions & 29 deletions internal/controller/applications/applications.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,35 +47,6 @@ func SetupReconcilerWithManager(
Complete(newReconciler(kargoMgr.GetClient()))
}

func indexStagesByApp(shardName string) func(client.Object) []string {
return func(obj client.Object) []string {
// Return early if:
//
// 1. This is the default controller, but the object is labeled for a
// specific shard.
//
// 2. This is a shard-specific controller, but the object is not labeled for
// this shard.
objShardName, labeled := obj.GetLabels()[controller.ShardLabelKey]
if (shardName == "" && labeled) ||
(shardName != "" && shardName != objShardName) {
return nil
}

stage := obj.(*kargoapi.Stage) // nolint: forcetypeassert
if stage.Spec.PromotionMechanisms == nil ||
len(stage.Spec.PromotionMechanisms.ArgoCDAppUpdates) == 0 {
return nil
}
apps := make([]string, len(stage.Spec.PromotionMechanisms.ArgoCDAppUpdates))
for i, appCheck := range stage.Spec.PromotionMechanisms.ArgoCDAppUpdates {
apps[i] =
fmt.Sprintf("%s:%s", appCheck.AppNamespaceOrDefault(), appCheck.AppName)
}
return apps
}
}

func newReconciler(kubeClient client.Client) *reconciler {
return &reconciler{
kubeClient: kubeClient,
Expand Down
121 changes: 0 additions & 121 deletions internal/controller/applications/applications_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,131 +4,10 @@ import (
"testing"

"github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"sigs.k8s.io/controller-runtime/pkg/event"

kargoapi "github.com/akuity/kargo/api/v1alpha1"
"github.com/akuity/kargo/internal/controller"
)

func TestIndexStagesByApp(t *testing.T) {
const testShardName = "test-shard"
testCases := []struct {
name string
controllerShardName string
stage *kargoapi.Stage
assertions func([]string)
}{
{
name: "Stage belongs to another shard",
controllerShardName: testShardName,
stage: &kargoapi.Stage{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
controller.ShardLabelKey: "another-shard",
},
},
Spec: &kargoapi.StageSpec{
PromotionMechanisms: &kargoapi.PromotionMechanisms{
ArgoCDAppUpdates: []kargoapi.ArgoCDAppUpdate{
{
AppNamespace: "fake-namespace",
AppName: "fake-app",
},
},
},
},
},
assertions: func(res []string) {
require.Nil(t, res)
},
},

{
name: "Stage belongs to this shard",
controllerShardName: testShardName,
stage: &kargoapi.Stage{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
controller.ShardLabelKey: testShardName,
},
},
Spec: &kargoapi.StageSpec{
PromotionMechanisms: &kargoapi.PromotionMechanisms{
ArgoCDAppUpdates: []kargoapi.ArgoCDAppUpdate{
{
AppNamespace: "fake-namespace",
AppName: "fake-app",
},
},
},
},
},
assertions: func(res []string) {
require.Equal(
t,
[]string{
"fake-namespace:fake-app",
},
res,
)
},
},

{
name: "Stage is unlabeled and this is not the default controller",
controllerShardName: testShardName,
stage: &kargoapi.Stage{
Spec: &kargoapi.StageSpec{
PromotionMechanisms: &kargoapi.PromotionMechanisms{
ArgoCDAppUpdates: []kargoapi.ArgoCDAppUpdate{
{
AppNamespace: "fake-namespace",
AppName: "fake-app",
},
},
},
},
},
assertions: func(res []string) {
require.Nil(t, res)
},
},

{
name: "Stage is unlabeled and this is the default controller",
controllerShardName: "",
stage: &kargoapi.Stage{
Spec: &kargoapi.StageSpec{
PromotionMechanisms: &kargoapi.PromotionMechanisms{
ArgoCDAppUpdates: []kargoapi.ArgoCDAppUpdate{
{
AppNamespace: "fake-namespace",
AppName: "fake-app",
},
},
},
},
},
assertions: func(res []string) {
require.Equal(
t,
[]string{
"fake-namespace:fake-app",
},
res,
)
},
},
}
for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
indexStagesByApp(testCase.controllerShardName)(testCase.stage)
})
}
}

func TestAppHealthChangePredicate(t *testing.T) {
testCases := []struct {
name string
Expand Down

0 comments on commit 730e2a0

Please sign in to comment.