Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add configmap support #156

Merged
merged 3 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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)

Check warning on line 75 in kubedog.go

View check run for this annotation

Codecov / codecov/patch

kubedog.go#L75

Added line #L75 was not covered by tests
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
Loading