diff --git a/docs/syntax.md b/docs/syntax.md index 2c262842..13343eb0 100644 --- a/docs/syntax.md +++ b/docs/syntax.md @@ -42,7 +42,7 @@ Below you will find the step syntax next to the name of the method it utilizes. - ` [I] (create|submit|update) [the] secret in namespace from [environment variable] ` kdt.KubeClientSet.SecretOperationFromEnvironmentVariable - ` [I] delete [the] secret in namespace ` kdt.KubeClientSet.SecretDelete - ` node[s] with selector should be (found|ready)` kdt.KubeClientSet.NodesWithSelectorShouldBe -- ` [the] (deployment|hpa|horizontalpodautoscaler|service|pdb|poddisruptionbudget|sa|serviceaccount) (is|is not) in namespace ` kdt.KubeClientSet.ResourceInNamespace +- ` [the] (deployment|hpa|horizontalpodautoscaler|service|pdb|poddisruptionbudget|sa|serviceaccount|configmap) (is|is not) in namespace ` kdt.KubeClientSet.ResourceInNamespace - ` [I] scale [the] deployment in namespace to ` kdt.KubeClientSet.ScaleDeployment - ` [I] validate Prometheus Statefulset in namespace has volumeClaimTemplates name ` kdt.KubeClientSet.ValidatePrometheusVolumeClaimTemplatesName - ` [I] get [the] nodes list` kdt.KubeClientSet.ListNodes diff --git a/kubedog.go b/kubedog.go index 75c66112..74f4d508 100644 --- a/kubedog.go +++ b/kubedog.go @@ -72,7 +72,7 @@ func (kdt *Test) SetScenario(scenario *godog.ScenarioContext) { kdt.scenario.Step(`^(?:I )?(create|submit|update) (?:the )?secret (\S+) in namespace (\S+) from (?:environment variable )?(\S+)$`, kdt.KubeClientSet.SecretOperationFromEnvironmentVariable) kdt.scenario.Step(`^(?:I )?delete (?:the )?secret (\S+) in namespace (\S+)$`, kdt.KubeClientSet.SecretDelete) kdt.scenario.Step(`^(\d+) node(?:s)? with selector (\S+) should be (found|ready)$`, kdt.KubeClientSet.NodesWithSelectorShouldBe) - kdt.scenario.Step(`^(?:the )?(deployment|hpa|horizontalpodautoscaler|service|pdb|poddisruptionbudget|sa|serviceaccount) ([^"]*) (is|is not) in namespace ([^"]*)$`, kdt.KubeClientSet.ResourceInNamespace) + kdt.scenario.Step(`^(?:the )?(deployment|hpa|horizontalpodautoscaler|service|pdb|poddisruptionbudget|sa|serviceaccount|configmap) ([^"]*) (is|is not) in namespace ([^"]*)$`, kdt.KubeClientSet.ResourceInNamespace) kdt.scenario.Step(`^(?:I )?scale (?:the )?deployment ([^"]*) in namespace ([^"]*) to (\d+)$`, kdt.KubeClientSet.ScaleDeployment) kdt.scenario.Step(`^(?:I )?validate Prometheus Statefulset ([^"]*) in namespace ([^"]*) has volumeClaimTemplates name ([^"]*)$`, kdt.KubeClientSet.ValidatePrometheusVolumeClaimTemplatesName) kdt.scenario.Step(`^(?:I )?get (?:the )?nodes list$`, kdt.KubeClientSet.ListNodes) diff --git a/pkg/kube/structured/structured.go b/pkg/kube/structured/structured.go index 36829e9e..88db5ca5 100644 --- a/pkg/kube/structured/structured.go +++ b/pkg/kube/structured/structured.go @@ -407,6 +407,8 @@ func ResourceInNamespace(kubeClientset kubernetes.Interface, resourceType, name, _, err = kubeClientset.PolicyV1().PodDisruptionBudgets(namespace).Get(context.Background(), name, metav1.GetOptions{}) case "sa", "serviceaccount": _, err = kubeClientset.CoreV1().ServiceAccounts(namespace).Get(context.Background(), name, metav1.GetOptions{}) + case "configmap": + _, err = kubeClientset.CoreV1().ConfigMaps(namespace).Get(context.Background(), name, metav1.GetOptions{}) default: return errors.Errorf("Invalid resource type") } diff --git a/pkg/kube/structured/structured_test.go b/pkg/kube/structured/structured_test.go index 3c232bb1..04571c5f 100644 --- a/pkg/kube/structured/structured_test.go +++ b/pkg/kube/structured/structured_test.go @@ -36,6 +36,7 @@ import ( ) const ( + configMapType = "configmap" deploymentType = "deployment" serviceType = "service" hpaType = "horizontalpodautoscaler" @@ -108,6 +109,7 @@ func TestResourceInNamespace(t *testing.T) { hpaName := "horizontalpodautoscaler1" pdbName := "poddisruptionbudget1" saName := "serviceaccount1" + configMapName := "configmap1" namespace := "namespace1" tests := []struct { @@ -125,6 +127,25 @@ func TestResourceInNamespace(t *testing.T) { namespace: namespace, }, }, + { + name: "Positive Test: configmap", + args: args{ + kubeClientset: fake.NewSimpleClientset(getResourceWithNamespace(t, configMapType, configMapName, namespace)), + resourceType: configMapType, + name: configMapName, + namespace: namespace, + }, + }, + { + name: "Negative Test: Invalid resource type", + args: args{ + kubeClientset: fake.NewSimpleClientset(getResourceWithNamespace(t, configMapType, configMapName, namespace)), + resourceType: "configmaps", + name: configMapName, + namespace: namespace, + }, + wantErr: true, + }, { name: "Positive Test: service", args: args{ @@ -684,6 +705,14 @@ func getResourceWithAll(t *testing.T, resourceType, name, namespace, label strin Labels: labels, }, } + case configMapType: + return &corev1.ConfigMap{ + ObjectMeta: metav1.ObjectMeta{ + Name: name, + Namespace: namespace, + Labels: labels, + }, + } case serviceType: return &corev1.Service{ ObjectMeta: metav1.ObjectMeta{