Skip to content

Commit a473b8a

Browse files
authored
Merge pull request #11 from everettraven/kep-alignment
aligns the codebase with what is proposed in kubernetes/enhancements#5102
2 parents 8c1d23d + 690fdcb commit a473b8a

110 files changed

Lines changed: 9201 additions & 3238 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.bingo/Variables.mk

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Auto generated binary variables helper managed by https://github.com/bwplotka/bingo v0.8. DO NOT EDIT.
1+
# Auto generated binary variables helper managed by https://github.com/bwplotka/bingo v0.9. DO NOT EDIT.
22
# All tools are designed to be build inside $GOBIN.
33
BINGO_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
44
GOPATH ?= $(shell go env GOPATH)
@@ -17,9 +17,9 @@ GO ?= $(shell which go)
1717
# @echo "Running golangci-lint"
1818
# @$(GOLANGCI_LINT) <flags/args..>
1919
#
20-
GOLANGCI_LINT := $(GOBIN)/golangci-lint-v1.61.0
20+
GOLANGCI_LINT := $(GOBIN)/golangci-lint-v1.64.8
2121
$(GOLANGCI_LINT): $(BINGO_DIR)/golangci-lint.mod
2222
@# Install binary/ries using Go 1.14+ build command. This is using bwplotka/bingo-controlled, separate go module with pinned dependencies.
23-
@echo "(re)installing $(GOBIN)/golangci-lint-v1.61.0"
24-
@cd $(BINGO_DIR) && GOWORK=off $(GO) build -mod=mod -modfile=golangci-lint.mod -o=$(GOBIN)/golangci-lint-v1.61.0 "github.com/golangci/golangci-lint/cmd/golangci-lint"
23+
@echo "(re)installing $(GOBIN)/golangci-lint-v1.64.8"
24+
@cd $(BINGO_DIR) && GOWORK=off $(GO) build -mod=mod -modfile=golangci-lint.mod -o=$(GOBIN)/golangci-lint-v1.64.8 "github.com/golangci/golangci-lint/cmd/golangci-lint"
2525

.bingo/golangci-lint.mod

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
module _ // Auto generated by https://github.com/bwplotka/bingo. DO NOT EDIT
22

3-
go 1.22.5
3+
go 1.23.0
44

5-
require github.com/golangci/golangci-lint v1.61.0 // cmd/golangci-lint
5+
toolchain go1.23.4
6+
7+
require github.com/golangci/golangci-lint v1.64.8 // cmd/golangci-lint

.bingo/golangci-lint.sum

Lines changed: 207 additions & 0 deletions
Large diffs are not rendered by default.

.bingo/variables.env

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Auto generated binary variables helper managed by https://github.com/bwplotka/bingo v0.8. DO NOT EDIT.
1+
# Auto generated binary variables helper managed by https://github.com/bwplotka/bingo v0.9. DO NOT EDIT.
22
# All tools are designed to be build inside $GOBIN.
33
# Those variables will work only until 'bingo get' was invoked, or if tools were installed via Makefile's Variables.mk.
44
GOBIN=${GOBIN:=$(go env GOBIN)}
@@ -8,5 +8,5 @@ if [ -z "$GOBIN" ]; then
88
fi
99

1010

11-
GOLANGCI_LINT="${GOBIN}/golangci-lint-v1.61.0"
11+
GOLANGCI_LINT="${GOBIN}/golangci-lint-v1.64.8"
1212

.github/workflows/e2e.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: e2e
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
merge_group:
7+
push:
8+
branches:
9+
- main
10+
11+
jobs:
12+
e2e:
13+
runs-on: ubuntu-latest
14+
steps:
15+
16+
- uses: actions/checkout@v4
17+
18+
- uses: actions/setup-go@v5
19+
with:
20+
go-version-file: go.mod
21+
22+
- name: Run e2e tests
23+
run: |
24+
make e2e

.github/workflows/lint.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: lint
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
merge_group:
7+
push:
8+
branches:
9+
- main
10+
11+
jobs:
12+
lint:
13+
runs-on: ubuntu-latest
14+
steps:
15+
16+
- uses: actions/checkout@v4
17+
18+
- uses: actions/setup-go@v5
19+
with:
20+
go-version-file: go.mod
21+
22+
- name: Run linter
23+
run: |
24+
make lint

.github/workflows/verify.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: verify
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
merge_group:
7+
push:
8+
branches:
9+
- main
10+
11+
jobs:
12+
verify:
13+
runs-on: ubuntu-latest
14+
steps:
15+
16+
- uses: actions/checkout@v4
17+
18+
- uses: actions/setup-go@v5
19+
with:
20+
go-version-file: go.mod
21+
22+
- name: Run verifications
23+
run: |
24+
make verify

Makefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,23 @@ unit:
1616
.PHONY: build
1717
build:
1818
go build -o bin/crd-diff main.go
19+
20+
.PHONY: fmt
21+
fmt:
22+
go fmt ./...
23+
24+
.PHONY: verify
25+
verify: fmt tidy lint
26+
git diff --exit-code
27+
28+
.PHONY: tidy
29+
tidy:
30+
go mod tidy
31+
32+
.PHONY: e2e
33+
e2e: build
34+
go run ./test/suite.go
35+
36+
.PHONY: update-e2e
37+
update-e2e: build
38+
go run ./test/suite.go --update

cli/root.go

Lines changed: 22 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,33 @@ package cli
22

33
import (
44
"fmt"
5-
"io"
65
"log"
7-
"net/url"
86
"os"
9-
"strings"
107

118
"github.com/everettraven/crd-diff/pkg/config"
129
"github.com/everettraven/crd-diff/pkg/loaders/composite"
1310
"github.com/everettraven/crd-diff/pkg/loaders/file"
1411
"github.com/everettraven/crd-diff/pkg/loaders/git"
1512
"github.com/everettraven/crd-diff/pkg/loaders/kubernetes"
1613
"github.com/everettraven/crd-diff/pkg/loaders/scheme"
14+
"github.com/everettraven/crd-diff/pkg/runner"
1715
"github.com/spf13/afero"
1816
"github.com/spf13/cobra"
19-
"k8s.io/apimachinery/pkg/util/yaml"
17+
crconfig "sigs.k8s.io/controller-runtime/pkg/client/config"
2018
)
2119

2220
func NewRootCommand() *cobra.Command {
2321
loader := composite.NewComposite(
24-
composite.WithLoaders(map[string]composite.Loader{
25-
scheme.SchemeKubernetes: kubernetes.NewKubernetes(),
26-
scheme.SchemeFile: file.NewFile(afero.OsFs{}),
27-
scheme.SchemeGit: git.NewGit(),
28-
}),
22+
map[string]composite.Loader{
23+
scheme.SchemeKubernetes: kubernetes.New(crconfig.GetConfig),
24+
scheme.SchemeFile: file.New(afero.OsFs{}),
25+
scheme.SchemeGit: git.New(),
26+
},
2927
)
3028

3129
var configFile string
3230
var outputFormat string
3331

34-
const outputFormatJSON = "json"
35-
const outputFormatYAML = "yaml"
36-
const outputFormatPlainText = "plaintext"
37-
3832
rootCmd := &cobra.Command{
3933
Use: "crd-diff <old> <new>",
4034
Short: "crd-diff evaluates changes to Kubernetes CustomResourceDefinitions",
@@ -53,79 +47,44 @@ Example use cases:
5347
$ crd-diff git://{ref}?path={filepath} git://{ref}?path={filepath}`,
5448
Args: cobra.ExactArgs(2),
5549
Run: func(cmd *cobra.Command, args []string) {
56-
oldURL, err := url.Parse(args[0])
50+
cfg, err := config.Load(configFile)
5751
if err != nil {
58-
log.Fatalf("parsing old source: %v", err)
52+
log.Fatalf("loading config: %v", err)
5953
}
6054

61-
newURL, err := url.Parse(args[1])
55+
run, err := runner.New(cfg, runner.DefaultRegistry())
6256
if err != nil {
63-
log.Fatalf("parsing new source: %v", err)
57+
log.Fatalf("configuring validation runner: %v", err)
6458
}
6559

66-
oldCrd, err := loader.Load(cmd.Context(), *oldURL)
60+
oldCrd, err := loader.Load(cmd.Context(), args[0])
6761
if err != nil {
6862
log.Fatalf("loading old CustomResourceDefinition: %v", err)
6963
}
7064

71-
newCrd, err := loader.Load(cmd.Context(), *newURL)
65+
newCrd, err := loader.Load(cmd.Context(), args[1])
7266
if err != nil {
7367
log.Fatalf("loading new CustomResourceDefinition: %v", err)
7468
}
7569

76-
cfg := &config.StrictConfig
77-
78-
if configFile != "" {
79-
file, err := os.Open(configFile)
80-
if err != nil {
81-
log.Fatalf("loading config file %q: %v", configFile, err)
82-
}
83-
84-
configBytes, err := io.ReadAll(file)
85-
if err != nil {
86-
log.Fatalf("reading config file %q: %v", configFile, err)
87-
}
88-
file.Close()
70+
results := run.Run(oldCrd, newCrd)
8971

90-
err = yaml.Unmarshal(configBytes, cfg)
91-
if err != nil {
92-
log.Fatalf("unmarshalling config file %q contents: %v", configFile, err)
93-
}
72+
report, err := results.Render(runner.Format(outputFormat))
73+
if err != nil {
74+
// TODO: can we handle this better than spitting out an obtuse error?
75+
log.Fatalf("rendering run results: %v", err)
9476
}
9577

96-
validator := config.ValidatorForConfig(*cfg)
97-
98-
result := validator.Validate(oldCrd, newCrd)
99-
err = result.Error(0)
100-
if err != nil {
101-
switch outputFormat {
102-
case outputFormatPlainText:
103-
var out strings.Builder
104-
out.WriteString("comparing the CRDs identified incompatible changes\n\n")
105-
out.WriteString(err.Error())
106-
log.Fatal(out.String())
107-
case outputFormatJSON:
108-
jsonOut, marshalError := result.JSON()
109-
if marshalError != nil {
110-
log.Fatalf("marshalling results to JSON: %v", marshalError)
111-
}
112-
fmt.Print(string(jsonOut))
113-
os.Exit(1)
114-
case outputFormatYAML:
115-
yamlOut, marshalError := result.YAML()
116-
if marshalError != nil {
117-
log.Fatalf("marshalling results to YAML: %v", marshalError)
118-
}
119-
fmt.Print(string(yamlOut))
120-
os.Exit(1)
121-
}
78+
fmt.Print(report)
79+
if results.HasFailures() {
80+
os.Exit(1)
12281
}
12382
},
12483
}
12584

12685
rootCmd.AddCommand(NewVersionCommand())
12786
rootCmd.PersistentFlags().StringVar(&configFile, "config", "", "the filepath to load the check configurations from")
128-
rootCmd.PersistentFlags().StringVarP(&outputFormat, "output", "o", "plaintext", "the format the output should take when incompatibilities are identified. May be one of plaintext, json, yaml")
87+
rootCmd.PersistentFlags().StringVarP(&outputFormat, "output", "o", "plaintext", "the format the output should take when incompatibilities are identified. May be one of plaintext, markdown, json, yaml")
12988

13089
return rootCmd
13190
}

0 commit comments

Comments
 (0)