Skip to content

Commit

Permalink
feat: add configmap support (#156)
Browse files Browse the repository at this point in the history
* add configmap support

Signed-off-by: Phanindra Padala <[email protected]>

* generate docs

Signed-off-by: Phanindra Padala <[email protected]>

* address review

Signed-off-by: Phanindra Padala <[email protected]>

---------

Signed-off-by: Phanindra Padala <[email protected]>
Co-authored-by: Phanindra Padala <[email protected]>
  • Loading branch information
phanipadala and Phanindra Padala authored Jun 17, 2024
1 parent 5b5a76b commit a68f911
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Below you will find the step syntax next to the name of the method it utilizes.
- `<GK> [I] (create|submit|update) [the] secret <non-whitespace-characters> in namespace <non-whitespace-characters> from [environment variable] <non-whitespace-characters>` kdt.KubeClientSet.SecretOperationFromEnvironmentVariable
- `<GK> [I] delete [the] secret <non-whitespace-characters> in namespace <non-whitespace-characters>` kdt.KubeClientSet.SecretDelete
- `<GK> <digits> node[s] with selector <non-whitespace-characters> should be (found|ready)` kdt.KubeClientSet.NodesWithSelectorShouldBe
- `<GK> [the] (deployment|hpa|horizontalpodautoscaler|service|pdb|poddisruptionbudget|sa|serviceaccount) <any-characters-except-(")> (is|is not) in namespace <any-characters-except-(")>` kdt.KubeClientSet.ResourceInNamespace
- `<GK> [the] (deployment|hpa|horizontalpodautoscaler|service|pdb|poddisruptionbudget|sa|serviceaccount|configmap) <any-characters-except-(")> (is|is not) in namespace <any-characters-except-(")>` kdt.KubeClientSet.ResourceInNamespace
- `<GK> [I] scale [the] deployment <any-characters-except-(")> in namespace <any-characters-except-(")> to <digits>` kdt.KubeClientSet.ScaleDeployment
- `<GK> [I] validate Prometheus Statefulset <any-characters-except-(")> in namespace <any-characters-except-(")> has volumeClaimTemplates name <any-characters-except-(")>` kdt.KubeClientSet.ValidatePrometheusVolumeClaimTemplatesName
- `<GK> [I] get [the] nodes list` kdt.KubeClientSet.ListNodes
Expand Down
2 changes: 1 addition & 1 deletion kubedog.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions pkg/kube/structured/structured.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
29 changes: 29 additions & 0 deletions pkg/kube/structured/structured_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
)

const (
configMapType = "configmap"
deploymentType = "deployment"
serviceType = "service"
hpaType = "horizontalpodautoscaler"
Expand Down Expand Up @@ -108,6 +109,7 @@ func TestResourceInNamespace(t *testing.T) {
hpaName := "horizontalpodautoscaler1"
pdbName := "poddisruptionbudget1"
saName := "serviceaccount1"
configMapName := "configmap1"

namespace := "namespace1"
tests := []struct {
Expand All @@ -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{
Expand Down Expand Up @@ -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{
Expand Down

0 comments on commit a68f911

Please sign in to comment.