mirror of
https://github.com/FairwindsOps/polaris.git
synced 2026-08-23 22:26:34 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
61e0d34e8b | ||
|
|
8b236c2fa2 |
@@ -6,6 +6,11 @@ meta:
|
||||
|
||||
---
|
||||
|
||||
## 9.1.1
|
||||
* Fix `hpaMinAvailability` failure message
|
||||
* Fix `missingPodDisruptionBudget` typo
|
||||
* Rewrite `hpaMaxAvailability` check to use go-template
|
||||
|
||||
## 9.1.0
|
||||
* Add HPA `minAvailable` and HPA `maxAvailable` checks
|
||||
* Fix typo for PDB `minAvailable`
|
||||
|
||||
@@ -1,4 +1,35 @@
|
||||
successMessage: HPA has a valid max and min replica configuration
|
||||
failureMessage: HPA maxReplicas and minReplicas should be different
|
||||
category: Reliability
|
||||
target: autoscaling/HorizontalPodAutoscaler
|
||||
target: autoscaling/HorizontalPodAutoscaler
|
||||
schemaString: |
|
||||
"$schema": http://json-schema.org/draft-07/schema#
|
||||
type: object
|
||||
properties:
|
||||
spec:
|
||||
type: object
|
||||
properties:
|
||||
minReplicas:
|
||||
type: integer
|
||||
minimum: 1
|
||||
maxReplicas:
|
||||
type: integer
|
||||
minimum: 1
|
||||
required:
|
||||
- maxReplicas
|
||||
{{- if .spec.minReplicas }}
|
||||
if:
|
||||
properties:
|
||||
minReplicas:
|
||||
type: integer
|
||||
maxReplicas:
|
||||
type: integer
|
||||
then:
|
||||
properties:
|
||||
maxReplicas:
|
||||
exclusiveMinimum: {{ .spec.minReplicas }}
|
||||
else:
|
||||
properties:
|
||||
maxReplicas:
|
||||
minimum: 1
|
||||
{{- end }}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
successMessage: HPA has a valid min replica configuration
|
||||
failureMessage: HPA maxReplicas should be greater than minReplicas
|
||||
failureMessage: HPA minReplicas should be 2 or more
|
||||
category: Reliability
|
||||
target: autoscaling/HorizontalPodAutoscaler
|
||||
schema:
|
||||
|
||||
@@ -4,9 +4,9 @@ category: Reliability
|
||||
target: Controller
|
||||
controllers:
|
||||
include:
|
||||
- Deployment
|
||||
- Deployment
|
||||
schema:
|
||||
'$schema': http://json-schema.org/draft-07/schema
|
||||
"$schema": http://json-schema.org/draft-07/schema#
|
||||
type: object
|
||||
properties:
|
||||
spec:
|
||||
@@ -14,13 +14,21 @@ schema:
|
||||
properties:
|
||||
template:
|
||||
type: object
|
||||
properites:
|
||||
properties:
|
||||
metadata:
|
||||
type: object
|
||||
properties:
|
||||
labels:
|
||||
type: object
|
||||
minProperties: 1
|
||||
required:
|
||||
- labels
|
||||
required:
|
||||
- metadata
|
||||
required:
|
||||
- template
|
||||
required:
|
||||
- spec
|
||||
additionalSchemaStrings:
|
||||
policy/PodDisruptionBudget: |
|
||||
type: object
|
||||
|
||||
@@ -369,8 +369,6 @@ func applySchemaCheck(conf *config.Configuration, checkID string, test schemaTes
|
||||
passes, issues, err = check.CheckContainer(test.Container)
|
||||
} else if check.Validator.SchemaURI != "" {
|
||||
passes, issues, err = check.CheckObject(test.Resource.Resource.Object)
|
||||
} else if customValidators[checkID] != nil {
|
||||
passes, issues, err = customValidators[checkID](test.Resource.Resource.Object)
|
||||
} else {
|
||||
passes, issues, err = true, []jsonschema.ValError{}, nil
|
||||
}
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
package validator
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/qri-io/jsonschema"
|
||||
)
|
||||
|
||||
type customValidator func(data interface{}) (bool, []jsonschema.ValError, error)
|
||||
|
||||
// customValidators is a map of validation functions that can be used in schema checks
|
||||
// sometimes we need to validate things that aren't covered by the JSON validation schema
|
||||
var customValidators = map[string]customValidator{
|
||||
"hpaMaxAvailability": validateHPAMaxAvailability,
|
||||
}
|
||||
|
||||
type HorizontalPodAutoscalerView struct {
|
||||
Spec struct {
|
||||
MinReplicas *int `json:"minReplicas"`
|
||||
MaxReplicas int `json:"maxReplicas"`
|
||||
} `json:"spec"`
|
||||
}
|
||||
|
||||
func validateHPAMaxAvailability(data any) (bool, []jsonschema.ValError, error) {
|
||||
jsonString, err := json.Marshal(data)
|
||||
if err != nil {
|
||||
return false, nil, err
|
||||
}
|
||||
|
||||
hpa := HorizontalPodAutoscalerView{}
|
||||
err = json.Unmarshal(jsonString, &hpa)
|
||||
if err != nil {
|
||||
return false, nil, err
|
||||
}
|
||||
|
||||
if hpa.Spec.MinReplicas == nil {
|
||||
return true, []jsonschema.ValError{}, nil
|
||||
}
|
||||
|
||||
if hpa.Spec.MaxReplicas != *hpa.Spec.MinReplicas {
|
||||
return true, []jsonschema.ValError{}, nil
|
||||
}
|
||||
|
||||
return false, []jsonschema.ValError{{PropertyPath: "spec.maxReplicas", Message: fmt.Sprintf("maxReplicas (%d) and minReplicas (%d) should be different", hpa.Spec.MaxReplicas, *hpa.Spec.MinReplicas)}}, nil
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: zookeeper
|
||||
spec:
|
||||
template:
|
||||
metadata:
|
||||
labels: {} # empty labels
|
||||
spec:
|
||||
containers:
|
||||
- name: zookeeper
|
||||
image: zookeeper
|
||||
---
|
||||
apiVersion: policy/v1
|
||||
kind: PodDisruptionBudget
|
||||
metadata:
|
||||
name: zookeeper-pdb
|
||||
spec:
|
||||
minAvailable: 2
|
||||
selector:
|
||||
matchLabels:
|
||||
app.kubernetes.io/name: zookeeper
|
||||
@@ -0,0 +1,21 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: zookeeper
|
||||
spec:
|
||||
template:
|
||||
metadata: {} # missing labels
|
||||
spec:
|
||||
containers:
|
||||
- name: zookeeper
|
||||
image: zookeeper
|
||||
---
|
||||
apiVersion: policy/v1
|
||||
kind: PodDisruptionBudget
|
||||
metadata:
|
||||
name: zookeeper-pdb
|
||||
spec:
|
||||
minAvailable: 2
|
||||
selector:
|
||||
matchLabels:
|
||||
app.kubernetes.io/name: zookeeper
|
||||
@@ -0,0 +1,20 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: zookeeper
|
||||
spec:
|
||||
template: # missing metadata
|
||||
spec:
|
||||
containers:
|
||||
- name: zookeeper
|
||||
image: zookeeper
|
||||
---
|
||||
apiVersion: policy/v1
|
||||
kind: PodDisruptionBudget
|
||||
metadata:
|
||||
name: zookeeper-pdb
|
||||
spec:
|
||||
minAvailable: 2
|
||||
selector:
|
||||
matchLabels:
|
||||
app.kubernetes.io/name: zookeeper
|
||||
Reference in New Issue
Block a user