admin管理员组

文章数量:1123142

I am trying to deploy helm chart via tanka and as I have understood - tanka does helm template and then works with the generated outputs.

The issue with this is that all the chart tests are being rendered as well and then tk diff/apply fails.

Is there a way to ignore them?

Example:

local tanka = import 'github/grafana/jsonnet-libs/tanka-util/main.libsonnet';
local helm = tanka.helm.new(std.thisFile);

{
  myChart:  helm.template('chart', '../../charts/mychart', {
     namespace: 'mychart',
     values: {
       ...
     },
   }),
}

I am trying to deploy helm chart via tanka and as I have understood - tanka does helm template and then works with the generated outputs.

The issue with this is that all the chart tests are being rendered as well and then tk diff/apply fails.

Is there a way to ignore them?

Example:

local tanka = import 'github.com/grafana/jsonnet-libs/tanka-util/main.libsonnet';
local helm = tanka.helm.new(std.thisFile);

{
  myChart:  helm.template('chart', '../../charts/mychart', {
     namespace: 'mychart',
     values: {
       ...
     },
   }),
}
Share Improve this question asked 6 hours ago Lukas IgnatavičiusLukas Ignatavičius 3,6152 gold badges27 silver badges30 bronze badges 1
  • github.com/grafana/tanka/issues/550 this is GitHub issue about the same topic – Lukas Ignatavičius Commented 6 hours ago
Add a comment  | 

2 Answers 2

Reset to default 0

I was able to write a helper function to deal with this:

local excludeChartTests(resources) =
  {
    [item.key]: item.value
    for item in std.objectKeysValues(resources)
    if !(std.type(item.value) == 'object' &&
       std.objectHas(item.value, 'metadata') &&
       std.objectHas(item.value.metadata, 'annotations') &&
       std.objectHas(item.value.metadata.annotations, 'helm.sh/hook') &&
       item.value.metadata.annotations['helm.sh/hook'] == 'test')
  };

Usage example:

local tanka = import 'github.com/grafana/jsonnet-libs/tanka-util/main.libsonnet';
local helm = tanka.helm.new(std.thisFile);

local excludeChartTests(resources) =
  {
    [item.key]: item.value
    for item in std.objectKeysValues(resources)
    if !(std.type(item.value) == 'object' &&
       std.objectHas(item.value, 'metadata') &&
       std.objectHas(item.value.metadata, 'annotations') &&
       std.objectHas(item.value.metadata.annotations, 'helm.sh/hook') &&
       item.value.metadata.annotations['helm.sh/hook'] == 'test')
  };

{
  myChart:  excludeChartTests(helm.template('chart', '../../charts/mychart', {
     namespace: 'mychart',
     values: {
       ...
     },
   })),
}

You can filter them out in your Jsonnet code by applying a filter to exclude any resource with this annotation. Here's how you can modify your Jsonnet code:

local tanka = import 'github.com/grafana/jsonnet-libs/tanka-util/main.libsonnet';
local helm = tanka.helm.new(std.thisFile);

{
  myChart: helm.template('chart', '../../charts/mychart', {
    namespace: 'mychart',
    values: {
      ...
    },
  }).filter(function(resource)
    resource.metadata.annotations['helm.sh/hook'] != 'test'
  ),
}

本文标签: kubernetesHow to skip helm tests deployment in Grafana TankaStack Overflow