Skip to content

Commit

Permalink
add yaml lint and ci
Browse files Browse the repository at this point in the history
  • Loading branch information
yuanning6 authored and priyanshikhetwani committed Oct 27, 2024
1 parent ba92cd7 commit fdceef1
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 41 deletions.
25 changes: 11 additions & 14 deletions .github/workflows/validate-yaml-manifests.yaml
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
name: Lint

# Trigger the workflow on push and pull request
on: [push, pull_request]

jobs:
yamllint:
name: Run yamllint
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # tag=v4.1.7
with:
go-version: '1.22'

ref: ${{ matrix.branch }}
- name: Calculate go version
run: make go-version

- name: Install yamllint
run: make install-yamllint

id: vars
run: echo "go_version=$(make go-version)" >> $GITHUB_OUTPUT
- name: Set up Go
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # tag=v5.0.2
with:
go-version: ${{ steps.vars.outputs.go_version }}
# - name: Install yamllint
# run: make install-yamllint
- name: Run yamllint
run: make lint-yaml
run: make lint-yaml
15 changes: 7 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ CONVERSION_VERIFIER := $(TOOLS_BIN_DIR)/conversion-verifier
SETUP_ENVTEST := $(TOOLS_BIN_DIR)/setup-envtest
GOVULNCHECK := $(TOOLS_BIN_DIR)/govulncheck
TRIVY := $(TOOLS_BIN_DIR)/trivy
YAMLLINT := $(TOOLS_BIN_DIR)/yamllint

STAGING_REGISTRY ?= gcr.io/k8s-staging-capi-ibmcloud
STAGING_BUCKET ?= artifacts.k8s-staging-capi-ibmcloud.appspot.com
Expand Down Expand Up @@ -547,16 +548,14 @@ else
endif


.PHONY: install-yamllint
install-yamllint: ## Install yamllint if not present
@which yamllint > /dev/null || (echo "Installing yamllint..." && go install github.com/wasilibs/go-yamllint/cmd/yamllint@latest)
@echo "yamllint installed"
# .PHONY: install-yamllint
# install-yamllint: ## Install yamllint if not present
# @which yamllint > /dev/null || (echo "Installing yamllint..." && go install github.com/wasilibs/go-yamllint/cmd/yamllint@latest)
# @echo "yamllint installed"

.PHONY: lint-yaml
lint-yaml: ## Run yamllint
@echo "Running yamllint..."
@yamllint . || true
@echo "Linting Yaml files completed"
lint-yaml: $(YAMLLINT) ## Lint YAML files
$(YAMLLINT) .

.PHONY: lint-yaml-no-warnings
lint-yaml-no-warnings: ## Run yamllint and won’t output warning level problems
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require (
github.com/IBM/ibm-cos-sdk-go v1.11.1
github.com/IBM/networking-go-sdk v0.45.0
github.com/IBM/platform-services-go-sdk v0.69.2
github.com/IBM/vpc-go-sdk v0.60.1
github.com/IBM/vpc-go-sdk v0.60.0
github.com/blang/semver/v4 v4.0.0
github.com/coreos/ignition/v2 v2.19.0
github.com/go-logr/logr v1.4.2
Expand Down Expand Up @@ -154,6 +154,7 @@ require (
github.com/subosito/gotenv v1.6.0 // indirect
github.com/valyala/fastjson v1.6.4 // indirect
github.com/vincent-petithory/dataurl v1.0.0 // indirect
github.com/wasilibs/go-yamllint v1.35.1 // indirect
go.mongodb.org/mongo-driver v1.14.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
go.opentelemetry.io/otel v1.24.0 // indirect
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ github.com/IBM/networking-go-sdk v0.45.0 h1:tYgDhVDpgKvELNY7tcodbZ4ny9fatpEWM6Pw
github.com/IBM/networking-go-sdk v0.45.0/go.mod h1:NnJPA1e5GWr5opJe+5Hs6e1G6RcBIFz64TrkZsdnSp8=
github.com/IBM/platform-services-go-sdk v0.69.2 h1:8XNI8rBZShutuybFN5v8BsWlrdUa1eF0L6nOS+lDXmI=
github.com/IBM/platform-services-go-sdk v0.69.2/go.mod h1:ZP3zUDxR1qRdUqzFdnJOlQN0QpVYol2eOUCv4uk03Jc=
github.com/IBM/vpc-go-sdk v0.60.1 h1:b24Rec20laMXFlvBrSBlaEEqVFuZzqKJ8IncG3jx1bE=
github.com/IBM/vpc-go-sdk v0.60.1/go.mod h1:swmxiYLT+OfBsBYqJWGeRd6NPmBk4u/het2PZdtzIaw=
github.com/IBM/vpc-go-sdk v0.60.0 h1:4MD9dTmg+alJivsAEPmKE4qx59nv0Gsweju/XF+Z2jo=
github.com/IBM/vpc-go-sdk v0.60.0/go.mod h1:swmxiYLT+OfBsBYqJWGeRd6NPmBk4u/het2PZdtzIaw=
github.com/MakeNowJust/heredoc v1.0.0 h1:cXCdzVdstXyiTqTvfqk9SDHpKNjxuom+DOlyEeQ4pzQ=
github.com/MakeNowJust/heredoc v1.0.0/go.mod h1:mG5amYoWBHf8vpLOuehzbGGw0EHxpZZ6lCpQ4fNJ8LE=
github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI=
Expand Down Expand Up @@ -345,6 +345,8 @@ github.com/valyala/fastjson v1.6.4 h1:uAUNq9Z6ymTgGhcm0UynUAB6tlbakBrz6CQFax3BXV
github.com/valyala/fastjson v1.6.4/go.mod h1:CLCAqky6SMuOcxStkYQvblddUtoRxhYMGLrsQns1aXY=
github.com/vincent-petithory/dataurl v1.0.0 h1:cXw+kPto8NLuJtlMsI152irrVw9fRDX8AbShPRpg2CI=
github.com/vincent-petithory/dataurl v1.0.0/go.mod h1:FHafX5vmDzyP+1CQATJn7WFKc9CvnvxyvZy6I1MrG/U=
github.com/wasilibs/go-yamllint v1.35.1 h1:r4zw1XYN3EgqLH3OIkj2cm1OsEMCP5TXIG+NP0LSF+s=
github.com/wasilibs/go-yamllint v1.35.1/go.mod h1:AA6cP8coUg5KDRCZBamyK9u1Q6NWb/a872PogEAmonw=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 h1:eY9dn8+vbi4tKz5Qo6v2eYzo7kUS51QINcR5jNpbZS8=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand Down
4 changes: 4 additions & 0 deletions hack/tools/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ GOLANGCI_LINT := $(BIN_DIR)/golangci-lint
$(GOLANGCI_LINT): $(BIN_DIR) go.mod go.sum ## Build a local copy of golangci-lint.
go build -tags=capibmtools -o $@ github.com/golangci/golangci-lint/cmd/golangci-lint

YAMLLINT := $(BIN_DIR)/yamllint
$(YAMLLINT): $(BIN_DIR) go.mod go.sum ## Build a local copy of yamllint.
go build -tags=capibmtools -o $@ github.com/wasilibs/go-yamllint/cmd/yamllint

GOTESTSUM := $(BIN_DIR)/gotestsum
$(GOTESTSUM): $(BIN_DIR) go.mod go.sum
go build -tags=capibmtools -o $@ gotest.tools/gotestsum
Expand Down
16 changes: 8 additions & 8 deletions templates/bases/powervs/kcp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ spec:
permissions: "0644"
- content: |
#!/bin/bash
# Copyright 2020 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -136,30 +136,30 @@ spec:
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -e
# Configure the workaround required for kubeadm init with kube-vip:
# xref: https://github.com/kube-vip/kube-vip/issues/684
# Nothing to do for kubernetes < v1.29
KUBEADM_MINOR="$(kubeadm version -o short | cut -d '.' -f 2)"
if [[ "$KUBEADM_MINOR" -lt "29" ]]; then
exit 0
fi
IS_KUBEADM_INIT="false"
# cloud-init kubeadm init
if [[ -f /run/kubeadm/kubeadm.yaml ]]; then
IS_KUBEADM_INIT="true"
fi
# ignition kubeadm init
if [[ -f /etc/kubeadm.sh ]] && grep -q -e "kubeadm init" /etc/kubeadm.sh; then
IS_KUBEADM_INIT="true"
fi
if [[ "$IS_KUBEADM_INIT" == "true" ]]; then
sed -i 's#path: /etc/kubernetes/admin.conf#path: /etc/kubernetes/super-admin.conf#' \
/etc/kubernetes/manifests/kube-vip.yaml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ spec:
permissions: "0644"
- content: |
#!/bin/bash
# Copyright 2020 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -180,30 +179,30 @@ spec:
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -e
# Configure the workaround required for kubeadm init with kube-vip:
# xref: https://github.com/kube-vip/kube-vip/issues/684
# Nothing to do for kubernetes < v1.29
KUBEADM_MINOR="$(kubeadm version -o short | cut -d '.' -f 2)"
if [[ "$KUBEADM_MINOR" -lt "29" ]]; then
exit 0
fi
IS_KUBEADM_INIT="false"
# cloud-init kubeadm init
if [[ -f /run/kubeadm/kubeadm.yaml ]]; then
IS_KUBEADM_INIT="true"
fi
# ignition kubeadm init
if [[ -f /etc/kubeadm.sh ]] && grep -q -e "kubeadm init" /etc/kubeadm.sh; then
IS_KUBEADM_INIT="true"
fi
if [[ "$IS_KUBEADM_INIT" == "true" ]]; then
sed -i 's#path: /etc/kubernetes/admin.conf#path: /etc/kubernetes/super-admin.conf#' \
/etc/kubernetes/manifests/kube-vip.yaml
Expand Down

0 comments on commit fdceef1

Please sign in to comment.