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

better support for namespaces in additional schemas #593

Merged
merged 4 commits into from
Jul 27, 2021
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
3 changes: 3 additions & 0 deletions pkg/config/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ func (check *SchemaCheck) Initialize(id string) error {
}
check.SchemaString = string(jsonBytes)
}
if check.AdditionalSchemaStrings == nil {
check.AdditionalSchemaStrings = make(map[string]string)
}
for kind, schema := range check.AdditionalSchemas {
jsonBytes, err := json.Marshal(schema)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions pkg/kube/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@ func CreateResourceProviderFromAPI(ctx context.Context, kube kubernetes.Interfac
for key := range check.AdditionalSchemas {
neededKinds = append(neededKinds, conf.TargetKind(key))
}
for key := range check.AdditionalSchemaStrings {
neededKinds = append(neededKinds, conf.TargetKind(key))
}
for _, kind := range neededKinds {
if !funk.Contains(conf.HandledTargets, kind) {
additionalKinds = append(additionalKinds, kind)
Expand Down
7 changes: 7 additions & 0 deletions pkg/validator/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,13 @@ func applySchemaCheck(conf *config.Configuration, checkID string, test schemaTes
break
}
resources := test.ResourceProvider.Resources[groupkind]
namespace := test.Resource.ObjectMeta.GetNamespace()
if test.Resource.Kind == "Namespace" {
namespace = test.Resource.ObjectMeta.GetName()
}
resources = funk.Filter(resources, func(res kube.GenericResource) bool {
return res.ObjectMeta.GetNamespace() == namespace
}).([]kube.GenericResource)
objects := funk.Map(resources, func(res kube.GenericResource) interface{} {
return res.Resource.Object
}).([]interface{})
Expand Down
24 changes: 24 additions & 0 deletions test/checks/missingPodDisruptionBudget/failure-bad-ns.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: zookeeper
namespace: rightnamespace
labels:
app: zookeeper
spec:
template:
spec:
containers:
- name: zookeeper
image: zookeeper
---
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: zk-pdb
namespace: wrongnamespace
spec:
minAvailable: 2
selector:
matchLabels:
app: zookeeper