Skip to content

Commit

Permalink
better support for namespaces in additional schemas (#593)
Browse files Browse the repository at this point in the history
* better support for namespaces in additional schemas

* add alertmanager check

* Revert " revert file"

This reverts commit f55839b.

* remove alertmanager check
  • Loading branch information
rbren committed Jul 27, 2021
1 parent 3e79863 commit b923caf
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
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

0 comments on commit b923caf

Please sign in to comment.