Create ConfigMap through kubectl task

4/20/2020

As part of the build pipeline I wanted to create a ConfigMap with the content of a file which is part of the Git repository from which the pipeline runs.

According to the Kubectl task für Azure Pipelines, this should be possible. But I have no idea how to apply it. It doesn't matter how my YAML is look like for this task, the result is always 'success'. Even I enter foo / bar as input parameters. https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/kubernetes?view=azure-devops

I asked Microsoft whether there could be a lack in the documentation or in the implementation itself. The only answer I get was ask here. They really move the responsibility for support to the community.

This is my definition:

- task: Kubernetes@1
  displayName: 'Create ConfigMap for /data'
  inputs:
    kubernetesServiceEndpoint: 'cluster-test'
    namespace: 'app-test'
    forceUpdateConfigMap: true
    configMapName: data
    configMapArguments: --from-file $(Build.SourcesDirectory)/data/ExcelTemplate.xlsx

With this I expect, according to the documentation, that with every run the ConfigMap will be deleted and recrated with the content of the given Excel file (and ExcelTemaplte.xlsx as the key). Manuelly I can do this with:
kubectl create configmap data --from-file ExcelTemplate.xlsx

The linked documentation mention the usage like this (I d:

    - task: Kubernetes@1
      displayName: configMap with literal values
      inputs:
        azureSubscriptionEndpoint: $(azureSubscriptionEndpoint)
        azureResourceGroup: $(azureResourceGroup)
        kubernetesCluster: $(kubernetesCluster)
        command: apply
        arguments: -f mhc-aks.yaml
        secretType: generic
        secretArguments: --from-literal=contoso=$(contosovalue)
        secretName: mysecretkey4
        configMapName: myconfig
        forceUpdateConfigMap: true
        configMapArguments: --from-literal=myname=contoso
  • The first part is clear, the example uses a Azure cluster, but there can be used any kind of.
  • Why do they use apply with a .yaml file? What should be inside?
  • Why do they deal with secrets, just a combined example? It's not mentioned
  • configMapArguments is mentioned in the docs (a guess newly added, was not before)

But I can give for every of the ConfigMap parameters a random value and the task is even then successful. Or in return, I can configure correct values and the result is successful without doing anything.

- task: Kubernetes@1
  displayName: 'Create ConfigMap for /data'
  inputs:
    kubernetesServiceEndpoint: 'cluster-test'
    namespace: foobar # does not exist
    forceUpdateConfigMap: true
    configMapName: data
    configMapArguments: 'today is sunny'

Does someone already use this task for creating a ConfigMap? Or was successful in trying out this task?

For know I have to ran this task twice once with delete and once with a dedicated manifest for ConfigMap creation with the apply command. Or as a second solution just firing the kubectl commands for deletion/creation in bash script.

-- dannyyy
azure-devops
azure-pipelines
configmap
kubernetes

1 Answer

4/20/2020

It seems, that something has been fixed since last Friday. Now the following definition is working as expected:

- task: Kubernetes@1
  displayName: 'Create ConfigMap for /data'
  inputs:
    kubernetesServiceEndpoint: 'cluster-test'
    namespace: 'app-test'
    forceUpdateConfigMap: true
    configMapName: data
    configMapArguments: --from-file $(Build.SourcesDirectory)/data/ExcelTemplate.xlsx
-- dannyyy
Source: StackOverflow