1 Star 0 Fork 0

jasongwq / prometheus-operator

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
linting.md 1.51 KB
一键复制 编辑 原始数据 按行查看 历史

Linting

This document describes how to use the standalone linting tool to validate your Prometheus Operator CRD-based configuration files.

Getting linter

To use the linter either get it with go get -u github.com/coreos/prometheus-operator/cmd/po-lint and executable is $GOPATH/bin/po-lint, or use the container image from quay.io/coreos/po-tooling and executable is /go/bin/po-lint.

Using linter

The po-lint executable takes a list of yaml files to check as command arguments. It will output any errors to stderr and returns with exit code 1 on errors, 0 otherwise.

Example

Here is an example script to lint a src sub-directory full of Prometheus Operator CRD files with ether local po-lint or Dockerized version:

#!/bin/sh

LINTER="quay.io/coreos/prometheus-operator-lint"
SCRIPT=$(basename "$0")

lint_files() {
  if [ -x "$(command -v po-lint)" ]; then
    echo "Linting '${2}' files in directory '${1}'..."
    had_errors=0
    for file in $(find "${1}" -name "${2}"); do
      echo "${file}"
      po-lint "${file}"
      retval=$?
      if [ $retval -ne 0 ]; then
        had_errors=1
      fi
    done
    exit ${had_errors}
  elif [ -x "$(command -v docker)" ]; then
    echo "Using Dockerized linter."
    docker run \
           --rm \
           --volume "$(pwd):/data:ro" \
           --entrypoint "/data/${SCRIPT}" \
           --workdir /data \
           "${LINTER}" "${1}" "${2}"
  else
    echo "Linter executable not found."
    exit 1
  fi
}

lint_files "src" "*.yaml"
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/jasongwq/prometheus-operator.git
git@gitee.com:jasongwq/prometheus-operator.git
jasongwq
prometheus-operator
prometheus-operator
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891