Skip to content

Commit

Permalink
pr review: added function for generating name of workload of an app
Browse files Browse the repository at this point in the history
Signed-off-by: Florian Bacher <[email protected]>
  • Loading branch information
bacherfl committed Nov 14, 2022
1 parent 3d00071 commit 2aee04e
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
4 changes: 4 additions & 0 deletions operator/api/v1alpha1/keptnappversion_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,3 +355,7 @@ func (a KeptnAppVersion) GetSpanAttributes() []attribute.KeyValue {
common.AppNamespace.String(a.Namespace),
}
}

func (v KeptnAppVersion) GetWorkloadNameOfApp(workloadName string) string {
return fmt.Sprintf("%s-%s", v.Spec.AppName, workloadName)
}
41 changes: 41 additions & 0 deletions operator/api/v1alpha1/keptnappversion_types_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package v1alpha1

import (
"testing"
)

func TestKeptnAppVersion_GetWorkloadNameOfApp(t *testing.T) {
type fields struct {
Spec KeptnAppVersionSpec
}
type args struct {
workloadName string
}
tests := []struct {
name string
fields fields
args args
want string
}{
{
name: "",
fields: fields{
Spec: KeptnAppVersionSpec{AppName: "my-app"},
},
args: args{
workloadName: "my-workload",
},
want: "my-app-my-workload",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
v := KeptnAppVersion{
Spec: tt.fields.Spec,
}
if got := v.GetWorkloadNameOfApp(tt.args.workloadName); got != tt.want {
t.Errorf("GetWorkloadNameOfApp() = %v, want %v", got, tt.want)
}
})
}
}
2 changes: 1 addition & 1 deletion operator/controllers/keptnworkloadinstance/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ func getLatestAppVersion(apps *klcv1alpha1.KeptnAppVersionList, wli *klcv1alpha1
for _, app := range apps.Items {
if app.Spec.AppName == wli.Spec.AppName {
for _, appWorkload := range app.Spec.Workloads {
if appWorkload.Version == wli.Spec.Version && fmt.Sprintf("%s-%s", app.Spec.AppName, appWorkload.Name) == wli.Spec.WorkloadName {
if appWorkload.Version == wli.Spec.Version && app.GetWorkloadNameOfApp(appWorkload.Name) == wli.Spec.WorkloadName {
workloadFound = true
newVersion, err := version.NewVersion(app.Spec.Version)
if err != nil {
Expand Down

0 comments on commit 2aee04e

Please sign in to comment.