Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
2 of 4 tasks
peppemanzi opened this issue Oct 27, 2023 · 2 comments
Open
2 of 4 tasks
Labels
bug Something isn't working needs triage This issue or pull request needs to be categorized

Comments

@peppemanzi
Copy link

What version or versions you have tested?

v1.2.3

Which operating systems have you used?

  • macOS
  • Windows
  • Linux

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

  • I agree to follow this project’s Code of Conduct
@peppemanzi peppemanzi added bug Something isn't working needs triage This issue or pull request needs to be categorized labels Oct 27, 2023
@peppemanzi peppemanzi changed the title [Bug]: [Bug]: Resorce deleted in target namespace if malformed yaml file is provided Oct 27, 2023
@peppemanzi peppemanzi changed the title [Bug]: Resorce deleted in target namespace if malformed yaml file is provided [Bug]: Resources deleted in target namespace if malformed yaml file is provided Oct 27, 2023
@ivanpasquariello
Copy link

ivanpasquariello commented Nov 27, 2023

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
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage This issue or pull request needs to be categorized
Projects
None yet
Development

No branches or pull requests

3 participants