mia-platform / mlp

cli for easier deployment of Mia-Platform Console projects
https://docs.mia-platform.eu/docs/runtime_suite_tools/mlp/overview
Apache License 2.0
12 stars 2 forks source link

[Bug]: Resources deleted in target namespace if malformed yaml file is provided #96

Open peppemanzi opened 1 year ago

peppemanzi commented 1 year ago

What version or versions you have tested?

v1.2.3

Which operating systems have you used?

What did you expect to happen?

Malformed YAML file does not implies that all the already existing resources in the target kubernetes namespace are deleted

What happened instead?

The folder provider as --filename parameter to the deploy command included a malformed yaml file. When the commad was executed all the existing resources in the target kubernetes namespace were deleted.

Environment: Azure DevOps pipelines, with bash script

Executed command: mlp deploy --ensure-namespace=false --server $KUBE_URL --certificate-authority /tmp/kube-ca.pem --token $KUBE_TOKEN --deploy-type ${DEPLOY_TYPE} --force-deploy-when-no-semver=${FORCE_DEPLOY_WHEN_NO_SEMVER} -f ${DESTINATION_PATH} -n ${KUBE_NAMESPACE}

Obtained log:

accumulating resources: accumulation err='accumulating resources from '../../configuration': '/home/vsts/work/1/s/configuration' must resolve to a file': recursed accumulation of path '/home/vsts/work/1/s/configuration': accumulating resources: accumulating resources from 'omitted.networkpolicy.yaml': MalformedYAMLError: yaml: line 20: could not find expected ':' in File: omitted.networkpolicy.yaml
WARN: can't read input file at path /home/vsts/work/1/s/interpolated-files/kustomize-output.yaml

Deleting: Service omitted
Deleting: Service omitted
Deleting: Service omitted
Deleting: Service omitted
Deleting: Service omitted
Deleting: Service omitted
Deleting: ConfigMap omitted
Deleting: ConfigMap omitted
Deleting: ConfigMap omitted
Deleting: ConfigMap omitted
Deleting: ConfigMap omitted
Deleting: ConfigMap omitted
Deleting: Deployment omitted
Deleting: Deployment omitted
Deleting: Deployment omitted
Deleting: Deployment omitted
Deleting: Deployment omitted
Deleting: Deployment omitted
Deleting: IngressRoute omitted
Deleting: Secret omitted
Deleting: Secret omitted
Deleting: Secret omitted

file (before interpolation):

kind: NetworkPolicy
apiVersion: networking.k8s.io/v1
metadata:
  name: gateway-networkpolicy-ingress
spec:
  podSelector:
    matchLabels:
      app: api-gateway
  ingress:
    - from:
        - namespaceSelector:
            matchLabels:
              project: {{OMITTED_NAMESPACE}}
      ports:
        - protocol: TCP
          port: 8080
        - protocol: TCP
          port: 8081
  policyTypes:
    - Ingress

Code of Conduct

ivanpasquariello commented 11 months ago

I'll add another strange behaviour to this issue: I had the same error reported, but in my case no resources has been deleted, nor created or updated. Instead, mlp has logged the error, but the pipeline still finished with an OK status. This behaviour is wrong, I should have received from the pipeline a KO.

To give a bit of context, I've received this errors:

accumulating resources: accumulation err='accumulating resources from '../../configuration': '/home/vsts/work/1/s/configuration' must resolve to a file': recursed accumulation of path '/home/vsts/work/1/s/configuration': accumulating resources: accumulating resources from '<<name>>.cronjob.yml': MalformedYAMLError: yaml: line 31: did not find expected key in File: <<name>>.cronjob.yml
WARN: can't read input file at path /home/vsts/work/1/s/interpolated-files/kustomize-output.yaml

Due to an error in the syntax of a Cronjob YAML.

silversoul93 commented 9 months ago

Hi guys, this problem just happened again to me and @ivanpasquariello. It's very bad behaviour to delete all k8s resources due to a configuration error.

Moreover, the Job finishes with the status "OK", so you don't know the pipeline has failed until you directly check on the cluster and, surprise, nothing is left on it.

image

Did you plan to fix it?