-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This gauge records any related objects monitored by multiple policies. ref: stolostron/backlog#25357 Signed-off-by: Dale Haiducek <19750917+dhaiducek@users.noreply.github.com>
- Loading branch information
Showing
7 changed files
with
281 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package e2e | ||
|
||
import ( | ||
"fmt" | ||
"os/exec" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
||
"open-cluster-management.io/config-policy-controller/test/utils" | ||
) | ||
|
||
var _ = Describe("Test related object metrics", Ordered, func() { | ||
const ( | ||
policy1Name = "case25-test-policy-1" | ||
policy2Name = "case25-test-policy-2" | ||
relatedObject = "case25-configmap" | ||
policyYaml = "../resources/case25_related_object_metric/case25-test-policy.yaml" | ||
) | ||
It("should create policies and related objects", func() { | ||
By("Creating " + policyYaml) | ||
utils.Kubectl("apply", | ||
"-f", policyYaml, | ||
"-n", testNamespace) | ||
By("Verifying the policies were created") | ||
plc1 := utils.GetWithTimeout( | ||
clientManagedDynamic, gvrConfigPolicy, policy1Name, testNamespace, true, defaultTimeoutSeconds, | ||
) | ||
Expect(plc1).NotTo(BeNil()) | ||
plc2 := utils.GetWithTimeout( | ||
clientManagedDynamic, gvrConfigPolicy, policy2Name, testNamespace, true, defaultTimeoutSeconds, | ||
) | ||
By("Verifying the related object was created") | ||
Expect(plc2).NotTo(BeNil()) | ||
obj := utils.GetWithTimeout( | ||
clientManagedDynamic, gvrConfigMap, relatedObject, "default", true, defaultTimeoutSeconds, | ||
) | ||
Expect(obj).NotTo(BeNil()) | ||
}) | ||
|
||
It("should correctly report common related objects", func() { | ||
By("Checking metric endpoint for relate object gauge for policy " + policy1Name) | ||
Eventually(func() interface{} { | ||
return utils.GetMetrics( | ||
"common_related_objects", fmt.Sprintf(`policy=\"%s/%s\"`, testNamespace, policy1Name)) | ||
}, defaultTimeoutSeconds, 1).Should(Equal([]string{"2"})) | ||
By("Checking metric endpoint for relate object gauge for policy " + policy2Name) | ||
Eventually(func() interface{} { | ||
return utils.GetMetrics( | ||
"common_related_objects", fmt.Sprintf(`policy=\"%s/%s\"`, testNamespace, policy2Name)) | ||
}, defaultTimeoutSeconds, 1).Should(Equal([]string{"2"})) | ||
}) | ||
|
||
cleanup := func() { | ||
// Delete the policies and ignore any errors (in case it was deleted previously) | ||
cmd := exec.Command("kubectl", "delete", | ||
"-f", policyYaml, | ||
"-n", testNamespace) | ||
_, _ = cmd.CombinedOutput() | ||
opt := metav1.ListOptions{} | ||
utils.ListWithTimeout( | ||
clientManagedDynamic, gvrConfigPolicy, opt, 0, false, defaultTimeoutSeconds) | ||
utils.GetWithTimeout( | ||
clientManagedDynamic, gvrConfigMap, relatedObject, "default", false, defaultTimeoutSeconds) | ||
} | ||
|
||
It("should clean up", cleanup) | ||
|
||
It("should have no common related object metrics after clean up", func() { | ||
By("Checking metric endpoint for related object gauges") | ||
Eventually(func() interface{} { | ||
return utils.GetMetrics("common_related_objects") | ||
}, defaultTimeoutSeconds, 1).Should(Equal([]string{})) | ||
}) | ||
|
||
AfterAll(cleanup) | ||
}) |
37 changes: 37 additions & 0 deletions
37
test/resources/case25_related_object_metric/case25-test-policy.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
--- | ||
apiVersion: policy.open-cluster-management.io/v1 | ||
kind: ConfigurationPolicy | ||
metadata: | ||
name: case25-test-policy-1 | ||
spec: | ||
remediationAction: enforce | ||
pruneObjectBehavior: DeleteAll | ||
object-templates: | ||
- complianceType: musthave | ||
objectDefinition: | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: case25-configmap | ||
namespace: default | ||
data: | ||
name: testvalue | ||
--- | ||
apiVersion: policy.open-cluster-management.io/v1 | ||
kind: ConfigurationPolicy | ||
metadata: | ||
name: case25-test-policy-2 | ||
spec: | ||
remediationAction: enforce | ||
pruneObjectBehavior: DeleteAll | ||
namespaceSelector: | ||
include: ["default"] | ||
object-templates: | ||
- complianceType: musthave | ||
objectDefinition: | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: case25-configmap | ||
data: | ||
name: testvalue |
Oops, something went wrong.