Giter Club home page Giter Club logo

Comments (3)

MatteoVoges avatar MatteoVoges commented on June 8, 2024

Hey @jyepesr1
could you add some steps to reproduce this issue, maybe sharing your inventory-specification of the relevant file.
Note that there were several issues regarding the kube-prometheus-stack with pyYaml.
Is it just the empty alert: {} property, or is there anything else, that changed?

from kapitan.

jyepesr1 avatar jyepesr1 commented on June 8, 2024

Hi @MatteoVoges, The most relevant issue at least with kube-prometheus-stack is this empty map, we haven't tested other components since we had to roll back to v0.30.0, we are using the following configuration:

 chart_name: kube-prometheus-stack
 chart_version: 34-9-0-kp-0-9
    - name: helm3-template-prometheus
       input_type: kadet
       output_path: ${prometheus:manifests_output_location}
       input_paths:
         - kadet_functions/helm3_template
       input_params:
         chart_location: shared/${prometheus:chart_name}/${prometheus:chart_version}
         clean_manifests: false
         helm_values_files:
           - ${prometheus:helm_values_files_location}/common.yml
           - ${prometheus:helm_values_files_location}/grafana.yml
         helm_values: ${prometheus:helm_values}
         helm_params:
           - --namespace ${prometheus:namespace}
           - --name-template ${prometheus:chart_name}
           - --api-versions 1.22.0
           - --include-crds
           
    - name: remove-prometheus-rules
       input_type: kadet
       output_path: .
       input_paths:
         - kadet_functions/remove_prometheus_rules
       input_params:
         alerting_rules_to_remove:
           - KubePersistentVolumeFillingUp # noisy alert that we will change in the future
           - TargetDown # Too broad of an alert. We don't control all pods in the cluster
         chart_compiled_dir: ${prometheus:manifests_output_location}/${prometheus:chart_name}

We realized the issue is happening in the Kadet function we use to delete some Prometheus rules. This script works as expected as I mentioned in the 0.30.0, but in this new version produces this output. Not sure if is related as you mentioned to the PyYaml version. This is the script content

import os
from kapitan.inputs import kadet
import yaml
import sys

curr_dir = os.path.dirname(__file__)
sys.path.append(os.path.abspath(os.path.join(curr_dir, "..", "common")))
import common

inventory = kadet.inventory()


def is_prometheus_rule(resource):
    if resource.root.kind == "PrometheusRule":
        return True

    return False


def remove_alerting_rule_if_present(resource, alerting_rules):
    for g_idx, group in enumerate(resource.root.spec.groups):
        for r_idx, rule in enumerate(group.rules):
            if rule.alert in alerting_rules:
                resource.root.spec.groups[g_idx].rules.pop(r_idx)

    return resource


def main(input_params):
    if "chart_compiled_dir" in input_params:
        chart_compiled_dir = input_params.get("chart_compiled_dir")
    else:
        raise ValueError("'chart_compiled_dir' key not found in 'input_params'")

    if "alerting_rules_to_remove" in input_params:
        alerting_rules_to_remove = input_params.get("alerting_rules_to_remove")
    else:
        raise ValueError(
            "'alerting_rules_to_remove' key not found in 'alerting_rules_to_remove'"
        )

    # get path where files have been compiled on this run
    inventory.parameters.kapitan.vars.target

    compile_path = input_params.get("compile_path")

    all_objects = {}
    prometheus_sub_chart = os.path.join(chart_compiled_dir, "templates", "prometheus")
    manifest_files = common.get_compiled_manifest_files_for_component(
        compile_path, prometheus_sub_chart
    )

    for file in manifest_files:
        file_name_kadet_format = common.format_file_name_for_kadet(compile_path, file)
        with open(file) as fp:
            yaml_stream = yaml.safe_load_all(fp)
            objects_for_file = []
            for obj in yaml_stream:
                o = kadet.BaseObj.from_dict(obj)
                # ensure yaml object is valid k8s resource
                # cleans up any cruft from helm template
                if common.kadet_object_has_kind(o) is not True:
                    continue
                if is_prometheus_rule(o):
                    o = remove_alerting_rule_if_present(o, alerting_rules_to_remove)

                objects_for_file.append(o)
            all_objects.update({file_name_kadet_format: objects_for_file})
        fp.close()

    output = kadet.BaseObj()
    for file_name, obj in all_objects.items():
        # TODO: output the object with the naming style we want
        # kind = obj.root.kind
        # name = obj.root.metadata.name
        output.root[file_name] = obj
    return output

from kapitan.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.