From 913dd0053cfa5ce3ff80a47ca49e9c424271a5a9 Mon Sep 17 00:00:00 2001 From: devthejo Date: Mon, 23 Sep 2024 09:36:35 +0200 Subject: [PATCH] fix: clean oblik related after oblik webhook feat --- .../oblik-cap-resources.dev.yaml | 283 ------------------ .../samples/oblik-cap-resources/config.yaml | 3 - .../samples/oblik-cap-resources/values.yaml | 13 - .../contrib/patches/81-oblik-cap-limits.js | 137 --------- 4 files changed, 436 deletions(-) delete mode 100644 packages/kontinuous/tests/__snapshots__/oblik-cap-resources.dev.yaml delete mode 100644 packages/kontinuous/tests/samples/oblik-cap-resources/config.yaml delete mode 100644 packages/kontinuous/tests/samples/oblik-cap-resources/values.yaml delete mode 100644 plugins/contrib/patches/81-oblik-cap-limits.js diff --git a/packages/kontinuous/tests/__snapshots__/oblik-cap-resources.dev.yaml b/packages/kontinuous/tests/__snapshots__/oblik-cap-resources.dev.yaml deleted file mode 100644 index c208d460cf..0000000000 --- a/packages/kontinuous/tests/__snapshots__/oblik-cap-resources.dev.yaml +++ /dev/null @@ -1,283 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`test build manifests with snapshots oblik-cap-resources.dev 1`] = ` -"apiVersion: v1 -kind: Namespace -metadata: - annotations: - field.cattle.io/projectId: \\"1234\\" - kontinuous/gitBranch: feature-branch-1 - kontinuous/mainNamespace: \\"true\\" - kapp.k14s.io/exists: \\"\\" - kontinuous/chartPath: project.fabrique.contrib.rancher-namespace - kontinuous/source: project/charts/fabrique/charts/contrib/charts/rancher-namespace/templates/namespace.yaml - kontinuous/deployment: test-oblik-cap-resources-feature-branch-1-ffac537e6cb-5kms108e - labels: - application: test-oblik-cap-resources - kontinuous/deployment: test-oblik-cap-resources-feature-branch-1-ffac537e6cb-5kms108e - kontinuous/deployment.env: test-oblik-cap-resources-feature-branch-1 - kontinuous/ref: feature-branch-1 - kontinuous/gitSha: ffac537e6cbbf934b08745a378932722df287a53 - kontinuous/appVersion: ffac537e6cbbf934b08745a378932722df287a53 - kontinuous/resourceName: namespace-test-oblik-cap-resources-feature-branch-1-5da5kenz - app.kubernetes.io/manifest-managed-by: kontinuous - app.kubernetes.io/manifest-created-by: kontinuous - cert: wildcard - name: test-oblik-cap-resources-feature-branch-1 ---- -apiVersion: networking.k8s.io/v1 -kind: NetworkPolicy -metadata: - name: netpol-ingress - namespace: test-oblik-cap-resources-feature-branch-1 - annotations: - kontinuous/chartPath: project.fabrique.contrib.security-policies - kontinuous/source: project/charts/fabrique/charts/contrib/charts/security-policies/templates/network-policy.yml - kontinuous/deployment: test-oblik-cap-resources-feature-branch-1-ffac537e6cb-5kms108e - labels: - kontinuous/deployment: test-oblik-cap-resources-feature-branch-1-ffac537e6cb-5kms108e - kontinuous/deployment.env: test-oblik-cap-resources-feature-branch-1 - kontinuous/ref: feature-branch-1 - kontinuous/gitSha: ffac537e6cbbf934b08745a378932722df287a53 - kontinuous/appVersion: ffac537e6cbbf934b08745a378932722df287a53 - kontinuous/resourceName: networkpolicy-netpol-ingress-61ndxljw - app.kubernetes.io/manifest-managed-by: kontinuous - app.kubernetes.io/manifest-created-by: kontinuous -spec: - ingress: - - from: - - podSelector: {} - - from: - - namespaceSelector: - matchLabels: - network-policy/source: ingress-controller - - from: - - namespaceSelector: - matchLabels: - network-policy/source: monitoring - podSelector: {} - policyTypes: - - Ingress ---- -apiVersion: v1 -kind: ServiceAccount -metadata: - name: default - annotations: - kontinuous/chartPath: project.fabrique.contrib.security-policies - kontinuous/source: project/charts/fabrique/charts/contrib/charts/security-policies/templates/service-account.yaml - kontinuous/deployment: test-oblik-cap-resources-feature-branch-1-ffac537e6cb-5kms108e - labels: - kontinuous/deployment: test-oblik-cap-resources-feature-branch-1-ffac537e6cb-5kms108e - kontinuous/deployment.env: test-oblik-cap-resources-feature-branch-1 - kontinuous/ref: feature-branch-1 - kontinuous/gitSha: ffac537e6cbbf934b08745a378932722df287a53 - kontinuous/appVersion: ffac537e6cbbf934b08745a378932722df287a53 - kontinuous/resourceName: serviceaccount-default-2g5dmk74 - app.kubernetes.io/manifest-managed-by: kontinuous - app.kubernetes.io/manifest-created-by: kontinuous - namespace: test-oblik-cap-resources-feature-branch-1 -automountServiceAccountToken: false ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - labels: - component: app - application: test-oblik-cap-resources - kontinuous/deployment: test-oblik-cap-resources-feature-branch-1-ffac537e6cb-5kms108e - kontinuous/deployment.env: test-oblik-cap-resources-feature-branch-1 - kontinuous/ref: feature-branch-1 - kontinuous/gitSha: ffac537e6cbbf934b08745a378932722df287a53 - kontinuous/appVersion: ffac537e6cbbf934b08745a378932722df287a53 - kontinuous/resourceName: deployment-app-55fzcjih - app.kubernetes.io/manifest-managed-by: kontinuous - app.kubernetes.io/manifest-created-by: kontinuous - name: app - namespace: test-oblik-cap-resources-feature-branch-1 - annotations: - oblik.socialgouv.io/max-limit-cpu: 200m - oblik.socialgouv.io/max-request-memory: 100Mi - oblik.socialgouv.io/min-limit-memory: 100Mi - oblik.socialgouv.io/min-request-cpu: 50m - kontinuous/chartPath: project.fabrique.contrib.app - kontinuous/source: project/charts/fabrique/charts/contrib/charts/app/templates/deployment.yaml - kontinuous/deployment: test-oblik-cap-resources-feature-branch-1-ffac537e6cb-5kms108e - kontinuous/depname.full: project.fabrique.contrib.app.deployment.app - kontinuous/depname.chartResource: app.deployment.app - kontinuous/depname.chartName: app - kontinuous/depname.chartPath: project.fabrique.contrib.app - kontinuous/depname.resourcePath: deployment.app - kontinuous/depname.resourceName: app - kontinuous/depname.chartNameTopFull: app - kontinuous/depname.chartNameTop: app - kontinuous/plugin.log: \\"false\\" - reloader.stakater.com/auto: \\"true\\" -spec: - replicas: 1 - selector: - matchLabels: - component: app - strategy: - type: RollingUpdate - template: - metadata: - labels: - component: app - application: test-oblik-cap-resources - namespace: test-oblik-cap-resources-feature-branch-1 - kontinuous/deployment: test-oblik-cap-resources-feature-branch-1-ffac537e6cb-5kms108e - kontinuous/deployment.env: test-oblik-cap-resources-feature-branch-1 - kontinuous/ref: feature-branch-1 - kontinuous/gitSha: ffac537e6cbbf934b08745a378932722df287a53 - kontinuous/appVersion: ffac537e6cbbf934b08745a378932722df287a53 - kontinuous/resourceName: deployment-app-55fzcjih - app.kubernetes.io/manifest-managed-by: kontinuous - app.kubernetes.io/manifest-created-by: kontinuous - annotations: - kontinuous/deployment: test-oblik-cap-resources-feature-branch-1-ffac537e6cb-5kms108e - spec: - affinity: - podAntiAffinity: - preferredDuringSchedulingIgnoredDuringExecution: - - weight: 1 - podAffinityTerm: - labelSelector: - matchExpressions: - - key: namespace - operator: In - values: - - test-oblik-cap-resources-feature-branch-1 - - key: component - operator: In - values: - - app - topologyKey: kubernetes.io/hostname - containers: - - image: harbor.fabrique.social.gouv.fr/test-oblik-cap-resources/app:sha-ffac537e6cbbf934b08745a378932722df287a53 - name: app - ports: - - containerPort: 3000 - name: http - livenessProbe: - failureThreshold: 15 - httpGet: - path: /index.html - port: http - initialDelaySeconds: 30 - periodSeconds: 5 - timeoutSeconds: 5 - readinessProbe: - exec: - command: - - cat - - /var/run/readiness-check/readiness-file - initialDelaySeconds: 5 - periodSeconds: 5 - startupProbe: - failureThreshold: 20 - httpGet: - path: /index.html - port: http - initialDelaySeconds: 10 - periodSeconds: 10 - timeoutSeconds: 5 - resources: - limits: - cpu: 0.2 - memory: 104857600 - requests: - cpu: 0.05 - memory: 104857600 - lifecycle: - postStart: - exec: - command: - - sh - - -c - - touch /var/run/readiness-check/readiness-file - preStop: - exec: - command: - - sh - - -c - - rm -f /var/run/readiness-check/readiness-file; sleep 30 - volumeMounts: - - name: readiness-check-volume - mountPath: /var/run/readiness-check - volumes: - - name: readiness-check-volume - emptyDir: {} ---- -apiVersion: v1 -kind: Service -metadata: - labels: - component: app - application: test-oblik-cap-resources - kontinuous/deployment: test-oblik-cap-resources-feature-branch-1-ffac537e6cb-5kms108e - kontinuous/deployment.env: test-oblik-cap-resources-feature-branch-1 - kontinuous/ref: feature-branch-1 - kontinuous/gitSha: ffac537e6cbbf934b08745a378932722df287a53 - kontinuous/appVersion: ffac537e6cbbf934b08745a378932722df287a53 - kontinuous/resourceName: service-app-46z2o1vv - app.kubernetes.io/manifest-managed-by: kontinuous - app.kubernetes.io/manifest-created-by: kontinuous - name: app - namespace: test-oblik-cap-resources-feature-branch-1 - annotations: - oblik.socialgouv.io/max-limit-cpu: 200m - oblik.socialgouv.io/max-request-memory: 100Mi - oblik.socialgouv.io/min-limit-memory: 100Mi - oblik.socialgouv.io/min-request-cpu: 50m - kontinuous/chartPath: project.fabrique.contrib.app - kontinuous/source: project/charts/fabrique/charts/contrib/charts/app/templates/service.yaml - kontinuous/deployment: test-oblik-cap-resources-feature-branch-1-ffac537e6cb-5kms108e -spec: - ports: - - name: http - port: 80 - targetPort: 3000 - selector: - component: app - type: ClusterIP ---- -apiVersion: networking.k8s.io/v1 -kind: Ingress -metadata: - annotations: - kubernetes.io/ingress.class: nginx - kontinuous/chartPath: project.fabrique.contrib.app - kontinuous/source: project/charts/fabrique/charts/contrib/charts/app/templates/ingress.yaml - kontinuous/deployment: test-oblik-cap-resources-feature-branch-1-ffac537e6cb-5kms108e - labels: - component: app - application: test-oblik-cap-resources - kontinuous/deployment: test-oblik-cap-resources-feature-branch-1-ffac537e6cb-5kms108e - kontinuous/deployment.env: test-oblik-cap-resources-feature-branch-1 - kontinuous/ref: feature-branch-1 - kontinuous/gitSha: ffac537e6cbbf934b08745a378932722df287a53 - kontinuous/appVersion: ffac537e6cbbf934b08745a378932722df287a53 - kontinuous/resourceName: ingress-app-b4kcj2bx - app.kubernetes.io/manifest-managed-by: kontinuous - app.kubernetes.io/manifest-created-by: kontinuous - name: app - namespace: test-oblik-cap-resources-feature-branch-1 -spec: - rules: - - host: test-oblik-cap-resources-feature-branch-1.ovh.fabrique.social.gouv.fr - http: - paths: - - backend: - service: - name: app - port: - name: http - path: / - pathType: Prefix - tls: - - hosts: - - test-oblik-cap-resources-feature-branch-1.ovh.fabrique.social.gouv.fr - secretName: wildcard-crt -" -`; diff --git a/packages/kontinuous/tests/samples/oblik-cap-resources/config.yaml b/packages/kontinuous/tests/samples/oblik-cap-resources/config.yaml deleted file mode 100644 index ff779aad47..0000000000 --- a/packages/kontinuous/tests/samples/oblik-cap-resources/config.yaml +++ /dev/null @@ -1,3 +0,0 @@ -dependencies: - fabrique: - import: socialgouv/kontinuous/plugins/fabrique \ No newline at end of file diff --git a/packages/kontinuous/tests/samples/oblik-cap-resources/values.yaml b/packages/kontinuous/tests/samples/oblik-cap-resources/values.yaml deleted file mode 100644 index 8a1efab296..0000000000 --- a/packages/kontinuous/tests/samples/oblik-cap-resources/values.yaml +++ /dev/null @@ -1,13 +0,0 @@ -app: - annotations: - oblik.socialgouv.io/max-limit-cpu: 200m - oblik.socialgouv.io/min-request-cpu: 50m - oblik.socialgouv.io/min-limit-memory: 100Mi - oblik.socialgouv.io/max-request-memory: 100Mi - resources: - limits: - cpu: "10" - memory: 10Mi - requests: - cpu: "10m" - memory: 150Mi diff --git a/plugins/contrib/patches/81-oblik-cap-limits.js b/plugins/contrib/patches/81-oblik-cap-limits.js deleted file mode 100644 index 5899003e78..0000000000 --- a/plugins/contrib/patches/81-oblik-cap-limits.js +++ /dev/null @@ -1,137 +0,0 @@ -function parseQuantity(quantity) { - const quantityRegex = /^([0-9.]+)([a-zA-Z]*)$/ - const match = quantity.match(quantityRegex) - - if (!match) { - throw new Error(`Invalid quantity format: ${quantity}`) - } - - let value = parseFloat(match[1]) - const unit = match[2] - - switch (unit) { - case "m": // MilliCPU - value /= 1000 - break - case "Ki": - value *= 1024 - break - case "Mi": - value *= 1024 * 1024 - break - case "Gi": - value *= 1024 * 1024 * 1024 - break - case "Ti": - value *= 1024 * 1024 * 1024 * 1024 - break - case "Pi": - value *= 1024 * 1024 * 1024 * 1024 * 1024 - break - case "Ei": - value *= 1024 * 1024 * 1024 * 1024 * 1024 * 1024 - break - case "n": - value /= 1e9 - break - case "u": - case "ยต": - value /= 1e6 - break - case "k": - value *= 1e3 - break - case "M": - value *= 1e6 - break - case "G": - value *= 1e9 - break - case "T": - value *= 1e12 - break - case "P": - value *= 1e15 - break - case "E": - value *= 1e18 - break - default: - break - } - - return value -} - -module.exports = async function oblikCapLimits(manifests, _options, _context) { - const resourcesToCheck = ["Deployment", "StatefulSet", "CronJob"] - const annotationsToCheck = [ - "oblik.socialgouv.io/min-request-cpu", - "oblik.socialgouv.io/min-request-memory", - "oblik.socialgouv.io/max-request-cpu", - "oblik.socialgouv.io/max-request-memory", - "oblik.socialgouv.io/min-limit-cpu", - "oblik.socialgouv.io/min-limit-memory", - "oblik.socialgouv.io/max-limit-cpu", - "oblik.socialgouv.io/max-limit-memory", - ] - - manifests.forEach((manifest) => { - if (!resourcesToCheck.includes(manifest.kind)) { - return - } - const annotations = manifest.metadata.annotations || {} - const { containers } = - manifest.kind === "CronJob" - ? manifest.spec.jobTemplate.spec.template.spec - : manifest.spec.template.spec - - containers.forEach((container) => { - const containerName = container.name - const { requests = {}, limits = {} } = container.resources || {} - const containerResources = { requests, limits } - - annotationsToCheck.forEach((annotation) => { - const defaultAnnotationValue = annotations[annotation] - ? parseQuantity(annotations[annotation]) - : null - const containerSpecificAnnotation = `${annotation}.${containerName}` - const containerSpecificAnnotationValue = annotations[ - containerSpecificAnnotation - ] - ? parseQuantity(annotations[containerSpecificAnnotation]) - : null - - const annotationValue = - containerSpecificAnnotationValue !== null - ? containerSpecificAnnotationValue - : defaultAnnotationValue - - if (annotationValue === null) { - return - } - const resourceTarget = annotation.includes("cpu") ? "cpu" : "memory" - const resourceType = annotation.includes("request") - ? "requests" - : "limits" - - const resourceValue = containerResources[resourceType][resourceTarget] - ? parseQuantity(containerResources[resourceType][resourceTarget]) - : null - - if (resourceValue !== null) { - if ( - (annotation.includes("min") && resourceValue < annotationValue) || - (annotation.includes("max") && resourceValue > annotationValue) - ) { - containerResources[resourceType][resourceTarget] = annotationValue - container.resources ||= {} - container.resources[resourceType] ||= {} - container.resources[resourceType][resourceTarget] ||= - containerResources[resourceType][resourceTarget] - } - } - }) - }) - }) -}