Script 'mail_helper' called by obssrc Hello community, here is the log from the commit of package polaris for openSUSE:Factory checked in at 2024-07-11 20:30:17 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/polaris (Old) and /work/SRC/openSUSE:Factory/.polaris.new.17339 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Package is "polaris" Thu Jul 11 20:30:17 2024 rev:29 rq:1186558 version:9.2.0 Changes: -------- --- /work/SRC/openSUSE:Factory/polaris/polaris.changes 2024-07-04 16:25:51.761182214 +0200 +++ /work/SRC/openSUSE:Factory/.polaris.new.17339/polaris.changes 2024-07-11 20:30:33.527104788 +0200 @@ -1,0 +2,6 @@ +Wed Jul 10 08:28:39 UTC 2024 - opensuse_buildservice@ojkastl.de + +- Update to version 9.2.0: + * INSIGHTS-157 - PDB <> HPA check (#1057) + +------------------------------------------------------------------- Old: ---- polaris-9.1.1.obscpio New: ---- polaris-9.2.0.obscpio ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ polaris.spec ++++++ --- /var/tmp/diff_new_pack.hiTeJ2/_old 2024-07-11 20:30:34.511141153 +0200 +++ /var/tmp/diff_new_pack.hiTeJ2/_new 2024-07-11 20:30:34.511141153 +0200 @@ -19,7 +19,7 @@ %define __arch_install_post export NO_BRP_STRIP_DEBUG=true Name: polaris -Version: 9.1.1 +Version: 9.2.0 Release: 0 Summary: Validation of best practices in your Kubernetes clusters License: Apache-2.0 ++++++ _service ++++++ --- /var/tmp/diff_new_pack.hiTeJ2/_old 2024-07-11 20:30:34.555142779 +0200 +++ /var/tmp/diff_new_pack.hiTeJ2/_new 2024-07-11 20:30:34.555142779 +0200 @@ -3,7 +3,7 @@ <param name="url">https://github.com/FairwindsOps/polaris</param> <param name="scm">git</param> <param name="exclude">.git</param> - <param name="revision">9.1.1</param> + <param name="revision">9.2.0</param> <param name="versionformat">@PARENT_TAG@</param> <param name="changesgenerate">enable</param> </service> ++++++ _servicedata ++++++ --- /var/tmp/diff_new_pack.hiTeJ2/_old 2024-07-11 20:30:34.575143518 +0200 +++ /var/tmp/diff_new_pack.hiTeJ2/_new 2024-07-11 20:30:34.579143666 +0200 @@ -1,6 +1,6 @@ <servicedata> <service name="tar_scm"> <param name="url">https://github.com/FairwindsOps/polaris</param> - <param name="changesrevision">61e0d34e8bedb447bd3e59e6aee580e9a14c190d</param></service></servicedata> + <param name="changesrevision">952b6aed65ed971bf64a64c2698c3df3905248cc</param></service></servicedata> (No newline at EOF) ++++++ polaris-9.1.1.obscpio -> polaris-9.2.0.obscpio ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/polaris-9.1.1/CODEOWNERS new/polaris-9.2.0/CODEOWNERS --- old/polaris-9.1.1/CODEOWNERS 2024-06-27 22:10:21.000000000 +0200 +++ new/polaris-9.2.0/CODEOWNERS 2024-07-08 19:47:54.000000000 +0200 @@ -1,2 +1,2 @@ ## DO NOT EDIT - Managed by Terraform -* @rbren @sudermanjr +* @sudermanjr diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/polaris-9.1.1/docs/checks/reliability.md new/polaris-9.2.0/docs/checks/reliability.md --- old/polaris-9.1.1/docs/checks/reliability.md 2024-06-27 22:10:21.000000000 +0200 +++ new/polaris-9.2.0/docs/checks/reliability.md 2024-07-08 19:47:54.000000000 +0200 @@ -21,6 +21,7 @@ `topologySpreadConstraint` | `warning` | Fails when there is no topology spread constraint on the pod `hpaMaxAvailability` | `warning` | Fails when `maxAvailable` lesser or equal than `minAvailable` (if defined) for a HorizontalPodAutoscaler `hpaMinAvailability` | `warning` | Fails when `minAvailable` (if defined) lesser or equal to one for a HorizontalPodAutoscaler +`pdbMinAvailableGreaterThanHPAMinReplicas` | `warning` | Fails when PDB `minAvailable` is greater than HPA `minReplicas` ## Background diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/polaris-9.1.1/pkg/config/checks/missingPodDisruptionBudget.yaml new/polaris-9.2.0/pkg/config/checks/missingPodDisruptionBudget.yaml --- old/polaris-9.1.1/pkg/config/checks/missingPodDisruptionBudget.yaml 2024-06-27 22:10:21.000000000 +0200 +++ new/polaris-9.2.0/pkg/config/checks/missingPodDisruptionBudget.yaml 2024-07-08 19:47:54.000000000 +0200 @@ -8,27 +8,23 @@ schema: "$schema": http://json-schema.org/draft-07/schema# type: object + required: [spec] properties: spec: type: object + required: [template] properties: template: type: object + required: [metadata] properties: metadata: type: object + required: [labels] properties: labels: type: object minProperties: 1 - required: - - labels - required: - - metadata - required: - - template - required: - - spec additionalSchemaStrings: policy/PodDisruptionBudget: | type: object diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/polaris-9.1.1/pkg/config/checks/pdbMinAvailableGreaterThanHPAMinReplicas.yaml new/polaris-9.2.0/pkg/config/checks/pdbMinAvailableGreaterThanHPAMinReplicas.yaml --- old/polaris-9.1.1/pkg/config/checks/pdbMinAvailableGreaterThanHPAMinReplicas.yaml 1970-01-01 01:00:00.000000000 +0100 +++ new/polaris-9.2.0/pkg/config/checks/pdbMinAvailableGreaterThanHPAMinReplicas.yaml 2024-07-08 19:47:54.000000000 +0200 @@ -0,0 +1,7 @@ +successMessage: PDB and HPA are correctly configured +failureMessage: PDB minAvailable is greater than HPA minReplicas +category: Reliability +target: Controller +controllers: + include: + - Deployment diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/polaris-9.1.1/pkg/config/checks.go new/polaris-9.2.0/pkg/config/checks.go --- old/polaris-9.1.1/pkg/config/checks.go 2024-06-27 22:10:21.000000000 +0200 +++ new/polaris-9.2.0/pkg/config/checks.go 2024-07-08 19:47:54.000000000 +0200 @@ -69,6 +69,7 @@ "rolebindingClusterAdminRole", "hpaMaxAvailability", "hpaMinAvailability", + "pdbMinAvailableGreaterThanHPAMinReplicas", } // BuiltInChecks contains the checks that come pre-installed w/ Polaris diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/polaris-9.1.1/pkg/config/default.yaml new/polaris-9.2.0/pkg/config/default.yaml --- old/polaris-9.1.1/pkg/config/default.yaml 2024-06-27 22:10:21.000000000 +0200 +++ new/polaris-9.2.0/pkg/config/default.yaml 2024-07-08 19:47:54.000000000 +0200 @@ -12,6 +12,7 @@ topologySpreadConstraint: warning hpaMaxAvailability: warning hpaMinAvailability: warning + pdbMinAvailableGreaterThanHPAMinReplicas: warning # efficiency cpuRequestsMissing: warning diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/polaris-9.1.1/pkg/config/examples/config-full.yaml new/polaris-9.2.0/pkg/config/examples/config-full.yaml --- old/polaris-9.1.1/pkg/config/examples/config-full.yaml 2024-06-27 22:10:21.000000000 +0200 +++ new/polaris-9.2.0/pkg/config/examples/config-full.yaml 2024-07-08 19:47:54.000000000 +0200 @@ -12,6 +12,7 @@ metadataAndInstanceMismatched: warning hpaMaxAvailability: warning hpaMinAvailability: warning + pdbMinAvailableGreaterThanHPAMinReplicas: warning # efficiency cpuRequestsMissing: warning diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/polaris-9.1.1/pkg/kube/resource.go new/polaris-9.2.0/pkg/kube/resource.go --- old/polaris-9.1.1/pkg/kube/resource.go 2024-06-27 22:10:21.000000000 +0200 +++ new/polaris-9.2.0/pkg/kube/resource.go 2024-07-08 19:47:54.000000000 +0200 @@ -181,7 +181,7 @@ err = cacheAllObjectsOfKind(ctx, firstOwner.APIVersion, firstOwner.Kind, dynamicClient, restMapper, objectCache) } if err != nil { - logrus.Warnf("Error caching objects of Kind %s %v", firstOwner.Kind, err) + logrus.Warnf("error caching objects of Kind %s %v", firstOwner.Kind, err) break } abstractObject, ok = objectCache[key] @@ -193,7 +193,7 @@ objMeta, err := meta.Accessor(&abstractObject) if err != nil { - logrus.Warnf("Error retrieving parent metadata %s of API %s and Kind %s because of error: %v ", firstOwner.Name, firstOwner.APIVersion, firstOwner.Kind, err) + logrus.Warnf("error retrieving parent metadata %s of API %s and Kind %s because of error: %v ", firstOwner.Name, firstOwner.APIVersion, firstOwner.Kind, err) return GenericResource{}, err } podSpec := GetPodSpec(abstractObject.Object) @@ -221,7 +221,7 @@ logrus.Debugf("Caching a single %s", kind) object, err := getObject(ctx, namespace, kind, apiVersion, name, dynamicClient, restMapper) if err != nil { - logrus.Warnf("Error retrieving object %s/%s/%s/%s because of error: %v", kind, apiVersion, namespace, name, err) + logrus.Warnf("error retrieving object %s/%s/%s/%s because of error: %v", kind, apiVersion, namespace, name, err) return err } key := fmt.Sprintf("%s/%s/%s", object.GetKind(), object.GetNamespace(), object.GetName()) @@ -235,13 +235,13 @@ fqKind := schema.FromAPIVersionAndKind(apiVersion, kind) mapping, err := restMapper.RESTMapping(fqKind.GroupKind(), fqKind.Version) if err != nil { - logrus.Warnf("Error retrieving mapping of API %s and Kind %s because of error: %v", apiVersion, kind, err) + logrus.Warnf("error retrieving mapping of API %s and Kind %s because of error: %v", apiVersion, kind, err) return err } objects, err := dynamicClient.Resource(mapping.Resource).Namespace("").List(ctx, kubeAPIMetaV1.ListOptions{}) if err != nil { - logrus.Warnf("Error retrieving parent object API %s and Kind %s because of error: %v", mapping.Resource.Version, mapping.Resource.Resource, err) + logrus.Warnf("error retrieving parent object API %s and Kind %s because of error: %v", mapping.Resource.Version, mapping.Resource.Resource, err) return err } for idx, object := range objects.Items { diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/polaris-9.1.1/pkg/kube/resources.go new/polaris-9.2.0/pkg/kube/resources.go --- old/polaris-9.1.1/pkg/kube/resources.go 2024-06-27 22:10:21.000000000 +0200 +++ new/polaris-9.2.0/pkg/kube/resources.go 2024-07-08 19:47:54.000000000 +0200 @@ -206,7 +206,7 @@ } err = resources.addResourcesFromYaml(string(contents)) if err != nil { - logrus.Warnf("Skipping %s: cannot add resource from YAML: %v", path, err) + logrus.Warnf("skipping %s: cannot add resource from YAML: %v", path, err) } return nil } @@ -340,7 +340,7 @@ groupKind := parseGroupKind(maybeTransformKindIntoGroupKind(string(kind))) mapping, err := restMapper.RESTMapping(groupKind) if err != nil { - logrus.Warnf("Error retrieving mapping of Kind %s because of error: %v", kind, err) + logrus.Warnf("error retrieving mapping of Kind %s because of error: %v", kind, err) return nil, err } if c.Namespace != "" && mapping.Scope.Name() != meta.RESTScopeNameNamespace { @@ -351,7 +351,7 @@ logrus.Info("Loading " + kind) objects, err := dynamic.Resource(mapping.Resource).Namespace(c.Namespace).List(ctx, metav1.ListOptions{}) if err != nil { - logrus.Warnf("Error retrieving parent object API %s and Kind %s because of error: %v", mapping.Resource.Version, mapping.Resource.Resource, err) + logrus.Warnf("error retrieving parent object API %s and Kind %s because of error: %v", mapping.Resource.Version, mapping.Resource.Resource, err) return nil, err } for _, obj := range objects.Items { diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/polaris-9.1.1/pkg/validator/custom.go new/polaris-9.2.0/pkg/validator/custom.go --- old/polaris-9.1.1/pkg/validator/custom.go 1970-01-01 01:00:00.000000000 +0100 +++ new/polaris-9.2.0/pkg/validator/custom.go 2024-07-08 19:47:54.000000000 +0200 @@ -0,0 +1,19 @@ +package validator + +import ( + "sync" + + "github.com/qri-io/jsonschema" +) + +type validatorFunction func(test schemaTestCase) (bool, []jsonschema.ValError, error) + +var validatorMapper = map[string]validatorFunction{} +var lock = &sync.Mutex{} + +func registerCustomChecks(name string, check validatorFunction) { + lock.Lock() + defer lock.Unlock() + + validatorMapper[name] = check +} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/polaris-9.1.1/pkg/validator/pdb_hpa_validator.go new/polaris-9.2.0/pkg/validator/pdb_hpa_validator.go --- old/polaris-9.1.1/pkg/validator/pdb_hpa_validator.go 1970-01-01 01:00:00.000000000 +0100 +++ new/polaris-9.2.0/pkg/validator/pdb_hpa_validator.go 2024-07-08 19:47:54.000000000 +0200 @@ -0,0 +1,150 @@ +package validator + +import ( + "fmt" + "strconv" + "strings" + + "github.com/fairwindsops/polaris/pkg/kube" + "github.com/qri-io/jsonschema" + "github.com/sirupsen/logrus" + appsv1 "k8s.io/api/apps/v1" + autoscalingv1 "k8s.io/api/autoscaling/v1" + policyv1 "k8s.io/api/policy/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/util/intstr" +) + +func init() { + registerCustomChecks("pdbMinAvailableGreaterThanHPAMinReplicas", pdbMinAvailableGreaterThanHPAMinReplicas) +} + +func pdbMinAvailableGreaterThanHPAMinReplicas(test schemaTestCase) (bool, []jsonschema.ValError, error) { + if test.ResourceProvider == nil { + logrus.Debug("ResourceProvider is nil") + return true, nil, nil + } + + deployment := &appsv1.Deployment{} + err := runtime.DefaultUnstructuredConverter.FromUnstructured(test.Resource.Resource.Object, deployment) + if err != nil { + logrus.Warnf("error converting unstructured to Deployment: %v", err) + return true, nil, nil + } + + attachedPDB, err := hasPDBAttached(*deployment, test.ResourceProvider.Resources["policy/PodDisruptionBudget"]) + if err != nil { + logrus.Warnf("error getting PodDisruptionBudget: %v", err) + return true, nil, nil + } + + attachedHPA, err := hasHPAAttached(*deployment, test.ResourceProvider.Resources["autoscaling/HorizontalPodAutoscaler"]) + if err != nil { + logrus.Warnf("error getting HorizontalPodAutoscaler: %v", err) + return true, nil, nil + } + + if attachedPDB != nil && attachedHPA != nil { + logrus.Debugf("both PDB and HPA are attached to deployment %s", deployment.Name) + + pdbMinAvailable, isPercent, err := getIntOrPercentValueSafely(attachedPDB.Spec.MinAvailable) + if err != nil { + logrus.Warnf("error getting getIntOrPercentValueSafely: %v", err) + return true, nil, nil + } + + if isPercent { + // if the value is a percentage, we need to calculate the actual value + if attachedHPA.Spec.MinReplicas == nil { + logrus.Debug("attachedHPA.Spec.MinReplicas is nil") + return true, nil, nil + } + + pdbMinAvailable, err = intstr.GetScaledValueFromIntOrPercent(attachedPDB.Spec.MinAvailable, int(*attachedHPA.Spec.MinReplicas), true) + if err != nil { + logrus.Warnf("error getting minAvailable value from PodDisruptionBudget: %v", err) + return true, nil, nil + } + } + + if attachedHPA.Spec.MinReplicas != nil && pdbMinAvailable >= int(*attachedHPA.Spec.MinReplicas) { + return false, []jsonschema.ValError{ + { + PropertyPath: "spec.minAvailable", + InvalidValue: pdbMinAvailable, + Message: fmt.Sprintf("The minAvailable value in the PodDisruptionBudget(%s) is %d, which is greater or equal than the minReplicas value in the HorizontalPodAutoscaler(%s) (%d)", attachedPDB.Name, pdbMinAvailable, attachedHPA.Name, *attachedHPA.Spec.MinReplicas), + }, + }, nil + } + } + + return true, nil, nil +} + +func hasPDBAttached(deployment appsv1.Deployment, pdbs []kube.GenericResource) (*policyv1.PodDisruptionBudget, error) { + for _, generic := range pdbs { + pdb := &policyv1.PodDisruptionBudget{} + err := runtime.DefaultUnstructuredConverter.FromUnstructured(generic.Resource.Object, pdb) + if err != nil { + return nil, fmt.Errorf("error converting unstructured to PodDisruptionBudget: %v", err) + } + + if pdb.Spec.Selector == nil { + logrus.Debug("pdb.Spec.Selector is nil") + continue + } + + if matchesPDBForDeployment(deployment.Spec.Template.Labels, pdb.Spec.Selector.MatchLabels) { + return pdb, nil + } + } + return nil, nil +} + +// matchesPDBForDeployment checks if the labels of the deployment match the labels of the PDB +func matchesPDBForDeployment(deploymentLabels, pdbLabels map[string]string) bool { + for key, value := range pdbLabels { + if deploymentLabels[key] == value { + return true + } + } + return false +} + +func hasHPAAttached(deployment appsv1.Deployment, hpas []kube.GenericResource) (*autoscalingv1.HorizontalPodAutoscaler, error) { + for _, generic := range hpas { + hpa := &autoscalingv1.HorizontalPodAutoscaler{} + err := runtime.DefaultUnstructuredConverter.FromUnstructured(generic.Resource.Object, hpa) + if err != nil { + return nil, fmt.Errorf("error converting unstructured to HorizontalPodAutoscaler: %v", err) + } + + if hpa.Spec.ScaleTargetRef.Kind == "Deployment" && hpa.Spec.ScaleTargetRef.Name == deployment.Name { + return hpa, nil + } + } + return nil, nil +} + +// getIntOrPercentValueSafely is a safer version of getIntOrPercentValue based on private function intstr.getIntOrPercentValueSafely +func getIntOrPercentValueSafely(intOrStr *intstr.IntOrString) (int, bool, error) { + switch intOrStr.Type { + case intstr.Int: + return intOrStr.IntValue(), false, nil + case intstr.String: + isPercent := false + s := intOrStr.StrVal + if strings.HasSuffix(s, "%") { + isPercent = true + s = strings.TrimSuffix(intOrStr.StrVal, "%") + } else { + return 0, false, fmt.Errorf("invalid type: string is not a percentage") + } + v, err := strconv.Atoi(s) + if err != nil { + return 0, false, fmt.Errorf("invalid value %q: %v", intOrStr.StrVal, err) + } + return int(v), isPercent, nil + } + return 0, false, fmt.Errorf("invalid type: neither int nor percentage") +} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/polaris-9.1.1/pkg/validator/schema.go new/polaris-9.2.0/pkg/validator/schema.go --- old/polaris-9.1.1/pkg/validator/schema.go 2024-06-27 22:10:21.000000000 +0200 +++ new/polaris-9.2.0/pkg/validator/schema.go 2024-07-08 19:47:54.000000000 +0200 @@ -369,6 +369,8 @@ passes, issues, err = check.CheckContainer(test.Container) } else if check.Validator.SchemaURI != "" { passes, issues, err = check.CheckObject(test.Resource.Resource.Object) + } else if validatorMapper[checkID] != nil { + passes, issues, err = validatorMapper[checkID](test) } else { passes, issues, err = true, []jsonschema.ValError{}, nil } @@ -380,7 +382,7 @@ break } if test.ResourceProvider == nil { - logrus.Warnf("No ResourceProvider available, check %s will not work in this context (e.g. admission control)", checkID) + logrus.Warnf("no ResourceProvider available, check %s will not work in this context (e.g. admission control)", checkID) break } resources := test.ResourceProvider.Resources[groupkind] diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/polaris-9.1.1/test/checks/pdbMinAvailableGreaterThanHPAMinReplicas/failure-gt-percent.yaml new/polaris-9.2.0/test/checks/pdbMinAvailableGreaterThanHPAMinReplicas/failure-gt-percent.yaml --- old/polaris-9.1.1/test/checks/pdbMinAvailableGreaterThanHPAMinReplicas/failure-gt-percent.yaml 1970-01-01 01:00:00.000000000 +0100 +++ new/polaris-9.2.0/test/checks/pdbMinAvailableGreaterThanHPAMinReplicas/failure-gt-percent.yaml 2024-07-08 19:47:54.000000000 +0200 @@ -0,0 +1,44 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: zookeeper +spec: + replicas: 10 + template: + metadata: + labels: + app.kubernetes.io/name: zookeeper + foo: bar + spec: + containers: + - name: zookeeper + image: zookeeper +--- +apiVersion: policy/v1 +kind: PodDisruptionBudget +metadata: + name: zookeeper-pdb +spec: + minAvailable: 150% # 1.5 * 10 = 15 + selector: + matchLabels: + app.kubernetes.io/name: zookeeper +--- +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: zookeeper-hpa +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: zookeeper + minReplicas: 10 + maxReplicas: 15 + metrics: + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: 50 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/polaris-9.1.1/test/checks/pdbMinAvailableGreaterThanHPAMinReplicas/failure-gt-scalar.yaml new/polaris-9.2.0/test/checks/pdbMinAvailableGreaterThanHPAMinReplicas/failure-gt-scalar.yaml --- old/polaris-9.1.1/test/checks/pdbMinAvailableGreaterThanHPAMinReplicas/failure-gt-scalar.yaml 1970-01-01 01:00:00.000000000 +0100 +++ new/polaris-9.2.0/test/checks/pdbMinAvailableGreaterThanHPAMinReplicas/failure-gt-scalar.yaml 2024-07-08 19:47:54.000000000 +0200 @@ -0,0 +1,43 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: zookeeper +spec: + template: + metadata: + labels: + app.kubernetes.io/name: zookeeper + foo: bar + spec: + containers: + - name: zookeeper + image: zookeeper +--- +apiVersion: policy/v1 +kind: PodDisruptionBudget +metadata: + name: zookeeper-pdb +spec: + minAvailable: 10 + selector: + matchLabels: + app.kubernetes.io/name: zookeeper +--- +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: zookeeper-hpa +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: zookeeper + minReplicas: 5 + maxReplicas: 7 + metrics: + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: 50 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/polaris-9.1.1/test/checks/pdbMinAvailableGreaterThanHPAMinReplicas/failure.equals.yaml new/polaris-9.2.0/test/checks/pdbMinAvailableGreaterThanHPAMinReplicas/failure.equals.yaml --- old/polaris-9.1.1/test/checks/pdbMinAvailableGreaterThanHPAMinReplicas/failure.equals.yaml 1970-01-01 01:00:00.000000000 +0100 +++ new/polaris-9.2.0/test/checks/pdbMinAvailableGreaterThanHPAMinReplicas/failure.equals.yaml 2024-07-08 19:47:54.000000000 +0200 @@ -0,0 +1,43 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: zookeeper +spec: + template: + metadata: + labels: + app.kubernetes.io/name: zookeeper + foo: bar + spec: + containers: + - name: zookeeper + image: zookeeper +--- +apiVersion: policy/v1 +kind: PodDisruptionBudget +metadata: + name: zookeeper-pdb +spec: + minAvailable: 5 + selector: + matchLabels: + app.kubernetes.io/name: zookeeper +--- +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: zookeeper-hpa +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: zookeeper + minReplicas: 5 + maxReplicas: 7 + metrics: + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: 50 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/polaris-9.1.1/test/checks/pdbMinAvailableGreaterThanHPAMinReplicas/success-lt-percent.yaml new/polaris-9.2.0/test/checks/pdbMinAvailableGreaterThanHPAMinReplicas/success-lt-percent.yaml --- old/polaris-9.1.1/test/checks/pdbMinAvailableGreaterThanHPAMinReplicas/success-lt-percent.yaml 1970-01-01 01:00:00.000000000 +0100 +++ new/polaris-9.2.0/test/checks/pdbMinAvailableGreaterThanHPAMinReplicas/success-lt-percent.yaml 2024-07-08 19:47:54.000000000 +0200 @@ -0,0 +1,44 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: zookeeper +spec: + replicas: 10 + template: + metadata: + labels: + app.kubernetes.io/name: zookeeper + foo: bar + spec: + containers: + - name: zookeeper + image: zookeeper +--- +apiVersion: policy/v1 +kind: PodDisruptionBudget +metadata: + name: zookeeper-pdb +spec: + minAvailable: 50% # 0.5 * 10 = 5 + selector: + matchLabels: + app.kubernetes.io/name: zookeeper +--- +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: zookeeper-hpa +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: zookeeper + minReplicas: 10 + maxReplicas: 15 + metrics: + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: 50 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/polaris-9.1.1/test/checks/pdbMinAvailableGreaterThanHPAMinReplicas/success.hpa-no-match.yaml new/polaris-9.2.0/test/checks/pdbMinAvailableGreaterThanHPAMinReplicas/success.hpa-no-match.yaml --- old/polaris-9.1.1/test/checks/pdbMinAvailableGreaterThanHPAMinReplicas/success.hpa-no-match.yaml 1970-01-01 01:00:00.000000000 +0100 +++ new/polaris-9.2.0/test/checks/pdbMinAvailableGreaterThanHPAMinReplicas/success.hpa-no-match.yaml 2024-07-08 19:47:54.000000000 +0200 @@ -0,0 +1,43 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: zookeeper +spec: + template: + metadata: + labels: + app.kubernetes.io/name: zookeeper + foo: bar + spec: + containers: + - name: zookeeper + image: zookeeper +--- +apiVersion: policy/v1 +kind: PodDisruptionBudget +metadata: + name: zookeeper-pdb +spec: + minAvailable: 5 + selector: + matchLabels: + app.kubernetes.io/name: zookeeper +--- +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: zookeeper-hpa +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: no-match + minReplicas: 5 + maxReplicas: 7 + metrics: + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: 50 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/polaris-9.1.1/test/checks/pdbMinAvailableGreaterThanHPAMinReplicas/success.lt.yaml new/polaris-9.2.0/test/checks/pdbMinAvailableGreaterThanHPAMinReplicas/success.lt.yaml --- old/polaris-9.1.1/test/checks/pdbMinAvailableGreaterThanHPAMinReplicas/success.lt.yaml 1970-01-01 01:00:00.000000000 +0100 +++ new/polaris-9.2.0/test/checks/pdbMinAvailableGreaterThanHPAMinReplicas/success.lt.yaml 2024-07-08 19:47:54.000000000 +0200 @@ -0,0 +1,43 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: zookeeper +spec: + template: + metadata: + labels: + app.kubernetes.io/name: zookeeper + foo: bar + 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 +--- +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: zookeeper-hpa +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: zookeeper + minReplicas: 5 + maxReplicas: 7 + metrics: + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: 50 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/polaris-9.1.1/test/checks/pdbMinAvailableGreaterThanHPAMinReplicas/success.no-hpa.yaml new/polaris-9.2.0/test/checks/pdbMinAvailableGreaterThanHPAMinReplicas/success.no-hpa.yaml --- old/polaris-9.1.1/test/checks/pdbMinAvailableGreaterThanHPAMinReplicas/success.no-hpa.yaml 1970-01-01 01:00:00.000000000 +0100 +++ new/polaris-9.2.0/test/checks/pdbMinAvailableGreaterThanHPAMinReplicas/success.no-hpa.yaml 2024-07-08 19:47:54.000000000 +0200 @@ -0,0 +1,24 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: zookeeper +spec: + template: + metadata: + labels: + app.kubernetes.io/name: zookeeper + foo: bar + spec: + containers: + - name: zookeeper + image: zookeeper +--- +apiVersion: policy/v1 +kind: PodDisruptionBudget +metadata: + name: zookeeper-pdb +spec: + minAvailable: 5 + selector: + matchLabels: + app.kubernetes.io/name: zookeeper diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/polaris-9.1.1/test/checks/pdbMinAvailableGreaterThanHPAMinReplicas/success.no-match.yaml new/polaris-9.2.0/test/checks/pdbMinAvailableGreaterThanHPAMinReplicas/success.no-match.yaml --- old/polaris-9.1.1/test/checks/pdbMinAvailableGreaterThanHPAMinReplicas/success.no-match.yaml 1970-01-01 01:00:00.000000000 +0100 +++ new/polaris-9.2.0/test/checks/pdbMinAvailableGreaterThanHPAMinReplicas/success.no-match.yaml 2024-07-08 19:47:54.000000000 +0200 @@ -0,0 +1,43 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: zookeeper +spec: + template: + metadata: + labels: + app.kubernetes.io/name: zookeeper + foo: bar + spec: + containers: + - name: zookeeper + image: zookeeper +--- +apiVersion: policy/v1 +kind: PodDisruptionBudget +metadata: + name: zookeeper-pdb +spec: + minAvailable: 5 + selector: + matchLabels: + app.kubernetes.io/name: no-match +--- +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: zookeeper-hpa +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: no-match + minReplicas: 5 + maxReplicas: 7 + metrics: + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: 50 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/polaris-9.1.1/test/checks/pdbMinAvailableGreaterThanHPAMinReplicas/success.no-min-replicas.yaml new/polaris-9.2.0/test/checks/pdbMinAvailableGreaterThanHPAMinReplicas/success.no-min-replicas.yaml --- old/polaris-9.1.1/test/checks/pdbMinAvailableGreaterThanHPAMinReplicas/success.no-min-replicas.yaml 1970-01-01 01:00:00.000000000 +0100 +++ new/polaris-9.2.0/test/checks/pdbMinAvailableGreaterThanHPAMinReplicas/success.no-min-replicas.yaml 2024-07-08 19:47:54.000000000 +0200 @@ -0,0 +1,42 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: zookeeper +spec: + template: + metadata: + labels: + app.kubernetes.io/name: zookeeper + foo: bar + 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 +--- +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: zookeeper-hpa +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: zookeeper + maxReplicas: 5 + metrics: + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: 50 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/polaris-9.1.1/test/checks/pdbMinAvailableGreaterThanHPAMinReplicas/success.no-pdb.yaml new/polaris-9.2.0/test/checks/pdbMinAvailableGreaterThanHPAMinReplicas/success.no-pdb.yaml --- old/polaris-9.1.1/test/checks/pdbMinAvailableGreaterThanHPAMinReplicas/success.no-pdb.yaml 1970-01-01 01:00:00.000000000 +0100 +++ new/polaris-9.2.0/test/checks/pdbMinAvailableGreaterThanHPAMinReplicas/success.no-pdb.yaml 2024-07-08 19:47:54.000000000 +0200 @@ -0,0 +1,33 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: zookeeper +spec: + template: + metadata: + labels: + app.kubernetes.io/name: zookeeper + foo: bar + spec: + containers: + - name: zookeeper + image: zookeeper +--- +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: zookeeper-hpa +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: zookeeper + minReplicas: 5 + maxReplicas: 7 + metrics: + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: 50 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/polaris-9.1.1/test/checks/pdbMinAvailableGreaterThanHPAMinReplicas/success.pdb-no-match.yaml new/polaris-9.2.0/test/checks/pdbMinAvailableGreaterThanHPAMinReplicas/success.pdb-no-match.yaml --- old/polaris-9.1.1/test/checks/pdbMinAvailableGreaterThanHPAMinReplicas/success.pdb-no-match.yaml 1970-01-01 01:00:00.000000000 +0100 +++ new/polaris-9.2.0/test/checks/pdbMinAvailableGreaterThanHPAMinReplicas/success.pdb-no-match.yaml 2024-07-08 19:47:54.000000000 +0200 @@ -0,0 +1,43 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: zookeeper +spec: + template: + metadata: + labels: + app.kubernetes.io/name: zookeeper + foo: bar + spec: + containers: + - name: zookeeper + image: zookeeper +--- +apiVersion: policy/v1 +kind: PodDisruptionBudget +metadata: + name: zookeeper-pdb +spec: + minAvailable: 5 + selector: + matchLabels: + app.kubernetes.io/name: no-match +--- +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: zookeeper-hpa +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: zookeeper + minReplicas: 5 + maxReplicas: 7 + metrics: + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: 50 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/polaris-9.1.1/test/checks/pdbMinAvailableGreaterThanHPAMinReplicas/success.percent-no-replica.yaml new/polaris-9.2.0/test/checks/pdbMinAvailableGreaterThanHPAMinReplicas/success.percent-no-replica.yaml --- old/polaris-9.1.1/test/checks/pdbMinAvailableGreaterThanHPAMinReplicas/success.percent-no-replica.yaml 1970-01-01 01:00:00.000000000 +0100 +++ new/polaris-9.2.0/test/checks/pdbMinAvailableGreaterThanHPAMinReplicas/success.percent-no-replica.yaml 2024-07-08 19:47:54.000000000 +0200 @@ -0,0 +1,43 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: zookeeper +spec: + template: + metadata: + labels: + app.kubernetes.io/name: zookeeper + foo: bar + spec: + containers: + - name: zookeeper + image: zookeeper +--- +apiVersion: policy/v1 +kind: PodDisruptionBudget +metadata: + name: zookeeper-pdb +spec: + minAvailable: 50% + selector: + matchLabels: + app.kubernetes.io/name: zookeeper +--- +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: zookeeper-hpa +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: zookeeper + minReplicas: 5 + maxReplicas: 7 + metrics: + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: 50 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/polaris-9.1.1/test/checks/pdbMinAvailableGreaterThanHPAMinReplicas/success.yaml new/polaris-9.2.0/test/checks/pdbMinAvailableGreaterThanHPAMinReplicas/success.yaml --- old/polaris-9.1.1/test/checks/pdbMinAvailableGreaterThanHPAMinReplicas/success.yaml 1970-01-01 01:00:00.000000000 +0100 +++ new/polaris-9.2.0/test/checks/pdbMinAvailableGreaterThanHPAMinReplicas/success.yaml 2024-07-08 19:47:54.000000000 +0200 @@ -0,0 +1,14 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: zookeeper +spec: + template: + metadata: + labels: + app.kubernetes.io/name: zookeeper + foo: bar + spec: + containers: + - name: zookeeper + image: zookeeper \ No newline at end of file diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/polaris-9.1.1/test/mutation_test.go new/polaris-9.2.0/test/mutation_test.go --- old/polaris-9.1.1/test/mutation_test.go 2024-06-27 22:10:21.000000000 +0200 +++ new/polaris-9.2.0/test/mutation_test.go 2024-07-08 19:47:54.000000000 +0200 @@ -34,6 +34,8 @@ c, err := config.Parse([]byte(configYaml)) assert.NoError(t, err) assert.Len(t, c.Mutations, 0) + + _, mutatedYamlContentMap, mutationTestCasesMap := initTestCases() for mutationStr := range mutationTestCasesMap { if len(mutationTestCasesMap[mutationStr]) == 0 { panic("No test cases found for " + mutationStr) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/polaris-9.1.1/test/schema_test.go new/polaris-9.2.0/test/schema_test.go --- old/polaris-9.1.1/test/schema_test.go 2024-06-27 22:10:21.000000000 +0200 +++ new/polaris-9.2.0/test/schema_test.go 2024-07-08 19:47:54.000000000 +0200 @@ -29,8 +29,6 @@ "github.com/fairwindsops/polaris/pkg/validator" ) -var testCases = []testCase{} - type testCase struct { check string filename string @@ -40,10 +38,7 @@ manifest string } -var mutatedYamlContentMap = map[string]string{} -var mutationTestCasesMap = map[string][]testCase{} - -func init() { +func initTestCases() ([]testCase, map[string]string, map[string][]testCase) { checkToTest := os.Getenv("POLARIS_CHECK_TEST") // if set, only run tests for this check _, baseDir, _, _ := runtime.Caller(0) baseDir = filepath.Dir(baseDir) + "/checks" @@ -51,6 +46,12 @@ if err != nil { panic(err) } + if checkToTest != "" { + fmt.Printf("POLARIS_CHECK_TEST is set... Running tests for '%s' only\n", checkToTest) + } + var testCases = []testCase{} + var mutatedYamlContentMap = map[string]string{} + var mutationTestCasesMap = map[string][]testCase{} for _, dir := range dirs { check := dir.Name() if checkToTest != "" && checkToTest != check { @@ -116,9 +117,11 @@ } } } + return testCases, mutatedYamlContentMap, mutationTestCasesMap } func TestChecks(t *testing.T) { + testCases, _, _ := initTestCases() for _, tc := range testCases { results, err := validator.ApplyAllSchemaChecksToResourceProvider(&tc.config, tc.resources) if err != nil { ++++++ polaris.obsinfo ++++++ --- /var/tmp/diff_new_pack.hiTeJ2/_old 2024-07-11 20:30:34.871154458 +0200 +++ /var/tmp/diff_new_pack.hiTeJ2/_new 2024-07-11 20:30:34.875154605 +0200 @@ -1,5 +1,5 @@ name: polaris -version: 9.1.1 -mtime: 1719519021 -commit: 61e0d34e8bedb447bd3e59e6aee580e9a14c190d +version: 9.2.0 +mtime: 1720460874 +commit: 952b6aed65ed971bf64a64c2698c3df3905248cc ++++++ vendor.tar.gz ++++++ /work/SRC/openSUSE:Factory/polaris/vendor.tar.gz /work/SRC/openSUSE:Factory/.polaris.new.17339/vendor.tar.gz differ: char 5, line 1
participants (1)
-
Source-Sync