Skip to content

Commit

Permalink
Validating labels of k8s resources in functional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Yetkin Timocin authored and Yetkin Timocin committed Sep 19, 2023
1 parent 9511b04 commit 2d26f4a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 24 deletions.
4 changes: 2 additions & 2 deletions test/functional/shared/resources/recipe_terraform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func Test_TerraformRecipe_KubernetesRedis(t *testing.T) {
ValidateLabels(false),
},
secretNamespace: {
validation.NewK8sSecretForResourceWithResourceName(secretPrefix + secretSuffix).
validation.NewK8sSecretForResource(name, secretPrefix+secretSuffix).
ValidateLabels(false),
},
},
Expand Down Expand Up @@ -146,7 +146,7 @@ func Test_TerraformRecipe_Context(t *testing.T) {
validation.NewK8sSecretForResource(name, name),
},
secretNamespace: {
validation.NewK8sSecretForResourceWithResourceName(secretPrefix + secretSuffix).
validation.NewK8sSecretForResource(name, secretPrefix+secretSuffix).
ValidateLabels(false),
},
},
Expand Down
36 changes: 14 additions & 22 deletions test/validation/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ func NewK8sPodForResource(application string, name string) K8sObject {
Version: "v1",
Resource: "pods",
},
Kind: "Pod",
Labels: kuberneteskeys.MakeSelectorLabels(application, name),
Kind: "Pod",
Labels: kuberneteskeys.MakeSelectorLabels(application, name),
ResourceName: name,
}
}

Expand All @@ -94,8 +95,9 @@ func NewK8sHTTPProxyForResource(application string, name string) K8sObject {
Version: "v1",
Resource: "httpproxies",
},
Kind: "HTTPProxy",
Labels: kuberneteskeys.MakeSelectorLabels(application, name),
Kind: "HTTPProxy",
Labels: kuberneteskeys.MakeSelectorLabels(application, name),
ResourceName: name,
}
}

Expand All @@ -107,34 +109,23 @@ func NewK8sServiceForResource(application string, name string) K8sObject {
Version: "v1",
Resource: "services",
},
Kind: "Service",
Labels: kuberneteskeys.MakeSelectorLabels(application, name),
Kind: "Service",
Labels: kuberneteskeys.MakeSelectorLabels(application, name),
ResourceName: name,
}
}

// NewK8sSecretForResource creates a K8sObject for a secret with the Labels set to the application and name.
func NewK8sSecretForResource(application string, name string) K8sObject {
return K8sObject{
GroupVersionResource: schema.GroupVersionResource{
Group: "",
Version: "v1",
Resource: "secrets",
},
Kind: "Secret",
Labels: kuberneteskeys.MakeSelectorLabels(application, name),
}
}

// NewK8sSecretForResourceWithResourceName creates a K8sObject for a secret with the Labels set to the application and name.
func NewK8sSecretForResourceWithResourceName(resourceName string) K8sObject {
return K8sObject{
GroupVersionResource: schema.GroupVersionResource{
Group: "",
Version: "v1",
Resource: "secrets",
},
Kind: "Secret",
ResourceName: resourceName,
Labels: kuberneteskeys.MakeSelectorLabels(application, name),
ResourceName: name,
}
}

Expand Down Expand Up @@ -602,7 +593,8 @@ func NewDaprComponent(application string, name string) K8sObject {
Version: "v1alpha1",
Resource: "components",
},
Kind: "Component",
Labels: kuberneteskeys.MakeSelectorLabels(application, name),
Kind: "Component",
Labels: kuberneteskeys.MakeSelectorLabels(application, name),
ResourceName: name,
}
}

0 comments on commit 2d26f4a

Please sign in to comment.