Skip to content

Commit

Permalink
fix(lifecycle-operator): introduce separate controller for removing s…
Browse files Browse the repository at this point in the history
…cheduling gates from pods (keptn#2946)

Signed-off-by: Charles-Edouard Brétéché <[email protected]>
Signed-off-by: Florian Bacher <[email protected]>
Signed-off-by: RealAnna <[email protected]>
Signed-off-by: RealAnna <[email protected]>
Signed-off-by: check-spelling-bot <[email protected]>
Signed-off-by: Meg McRoberts <[email protected]>
Signed-off-by: Moritz Wiesinger <[email protected]>
Co-authored-by: Charles-Edouard Brétéché <[email protected]>
Co-authored-by: Moritz Wiesinger <[email protected]>
Co-authored-by: RealAnna <[email protected]>
Co-authored-by: Meg McRoberts <[email protected]>
Co-authored-by: odubajDT <[email protected]>
Signed-off-by: vickysomtee <[email protected]>
  • Loading branch information
6 people authored and Vickysomtee committed Apr 22, 2024
1 parent 7d06620 commit b6f1880
Show file tree
Hide file tree
Showing 18 changed files with 743 additions and 814 deletions.
4 changes: 1 addition & 3 deletions .github/actions/spelling/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,6 @@ iobjective
IOperator
IProviders
IRound
IScheduling
Isitobservable
ISpan
ITarget
Expand Down Expand Up @@ -536,8 +535,7 @@ runtimes
runtimespec
Sambhav
sbom
schedulinggate
schedulinggateshandler
schedulinggates
sclient
screenshot
sdkmetric
Expand Down
12 changes: 12 additions & 0 deletions lifecycle-operator/controllers/common/helperfunctions.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,15 @@ func GetRequestInfo(req ctrl.Request) map[string]string {
"namespace": req.Namespace,
}
}

func KeptnWorkloadVersionResourceRefUIDIndexFunc(rawObj client.Object) []string {
// Extract the ResourceReference UID name from the KeptnWorkloadVersion Spec, if one is provided
workloadVersion, ok := rawObj.(*klcv1beta1.KeptnWorkloadVersion)
if !ok {
return nil
}
if workloadVersion.Spec.ResourceReference.UID == "" {
return nil
}
return []string{string(workloadVersion.Spec.ResourceReference.UID)}
}
81 changes: 70 additions & 11 deletions lifecycle-operator/controllers/common/helperfunctions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@ package common

import (
"context"
"reflect"
"testing"

klcv1beta1 "github.com/keptn/lifecycle-toolkit/lifecycle-operator/apis/lifecycle/v1beta1"
apicommon "github.com/keptn/lifecycle-toolkit/lifecycle-operator/apis/lifecycle/v1beta1/common"
"github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/config"
"github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/testcommon"
"github.com/stretchr/testify/require"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/kubernetes/scheme"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
)

Expand Down Expand Up @@ -130,7 +133,7 @@ func Test_GetTaskDefinition(t *testing.T) {
{
name: "taskDef not found",
taskDef: &klcv1beta1.KeptnTaskDefinition{
ObjectMeta: v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Name: "taskDef",
Namespace: "some-other-namespace",
},
Expand All @@ -143,15 +146,15 @@ func Test_GetTaskDefinition(t *testing.T) {
{
name: "taskDef found",
taskDef: &klcv1beta1.KeptnTaskDefinition{
ObjectMeta: v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Name: "taskDef",
Namespace: "some-namespace",
},
},
taskDefName: "taskDef",
taskDefNamespace: "some-namespace",
out: &klcv1beta1.KeptnTaskDefinition{
ObjectMeta: v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Name: "taskDef",
Namespace: "some-namespace",
},
Expand All @@ -161,15 +164,15 @@ func Test_GetTaskDefinition(t *testing.T) {
{
name: "taskDef found in default Keptn namespace",
taskDef: &klcv1beta1.KeptnTaskDefinition{
ObjectMeta: v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Name: "taskDef",
Namespace: testcommon.KeptnNamespace,
},
},
taskDefName: "taskDef",
taskDefNamespace: "some-namespace",
out: &klcv1beta1.KeptnTaskDefinition{
ObjectMeta: v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Name: "taskDef",
Namespace: testcommon.KeptnNamespace,
},
Expand Down Expand Up @@ -214,7 +217,7 @@ func Test_GetEvaluationDefinition(t *testing.T) {
{
name: "evalDef not found",
evalDef: &klcv1beta1.KeptnEvaluationDefinition{
ObjectMeta: v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Name: "evalDef",
Namespace: "some-other-namespace",
},
Expand All @@ -227,15 +230,15 @@ func Test_GetEvaluationDefinition(t *testing.T) {
{
name: "evalDef found",
evalDef: &klcv1beta1.KeptnEvaluationDefinition{
ObjectMeta: v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Name: "evalDef",
Namespace: "some-namespace",
},
},
evalDefName: "evalDef",
evalDefNamespace: "some-namespace",
out: &klcv1beta1.KeptnEvaluationDefinition{
ObjectMeta: v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Name: "evalDef",
Namespace: "some-namespace",
},
Expand All @@ -245,15 +248,15 @@ func Test_GetEvaluationDefinition(t *testing.T) {
{
name: "evalDef found in default Keptn namespace",
evalDef: &klcv1beta1.KeptnEvaluationDefinition{
ObjectMeta: v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Name: "evalDef",
Namespace: testcommon.KeptnNamespace,
},
},
evalDefName: "evalDef",
evalDefNamespace: "some-namespace",
out: &klcv1beta1.KeptnEvaluationDefinition{
ObjectMeta: v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Name: "evalDef",
Namespace: testcommon.KeptnNamespace,
},
Expand Down Expand Up @@ -381,3 +384,59 @@ func Test_MergeMaps(t *testing.T) {
})
}
}

func Test_resourceRefUIDIndexFunc(t *testing.T) {
type args struct {
rawObj client.Object
}
tests := []struct {
name string
args args
want []string
}{
{
name: "get uid of resource reference",
args: args{
rawObj: &klcv1beta1.KeptnWorkloadVersion{
Spec: klcv1beta1.KeptnWorkloadVersionSpec{
KeptnWorkloadSpec: klcv1beta1.KeptnWorkloadSpec{
ResourceReference: klcv1beta1.ResourceReference{
UID: "my-uid",
},
},
},
},
},
want: []string{"my-uid"},
},
{
name: "empty uid",
args: args{
rawObj: &klcv1beta1.KeptnWorkloadVersion{
Spec: klcv1beta1.KeptnWorkloadVersionSpec{
KeptnWorkloadSpec: klcv1beta1.KeptnWorkloadSpec{
ResourceReference: klcv1beta1.ResourceReference{
UID: "",
},
},
},
},
},
want: nil,
},
{
name: "not a KeptnWorkloadVersion",
args: args{
rawObj: &v1.Pod{},
},
want: nil,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := KeptnWorkloadVersionResourceRefUIDIndexFunc(tt.args.rawObj); !reflect.DeepEqual(got, tt.want) {
t.Errorf("KeptnWorkloadVersionResourceRefUIDIndexFunc() = %v, want %v", got, tt.want)
}
})
}
}

This file was deleted.

Loading

0 comments on commit b6f1880

Please sign in to comment.