Skip to content

Commit a0cb272

Browse files
authored
Merge branch 'main' into enable-shallow-cloning
Signed-off-by: Mmadu Manasseh <manasseh.mmadu@zapier.com>
2 parents 012a083 + 7a476ba commit a0cb272

File tree

16 files changed

+174
-74
lines changed

16 files changed

+174
-74
lines changed

charts/kubechecks/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
apiVersion: v2
22
name: kubechecks
33
description: A Helm chart for kubechecks
4-
version: 0.5.3
4+
version: 0.5.4
55
type: application
66
maintainers:
77
- name: zapier

charts/kubechecks/templates/deployment.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ metadata:
77
{{- end}}
88
labels: {{- include "kubechecks.labels" . | nindent 4 }}
99
spec:
10+
revisionHistoryLimit: {{ .Values.deployment.revisionHistoryLimit }}
1011
replicas: {{ .Values.deployment.replicaCount }}
1112
selector:
1213
matchLabels:

charts/kubechecks/values.schema.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@
9393
"readinessProbe": {
9494
"type": "object"
9595
},
96+
"revisionHistoryLimit": {
97+
"type": "integer"
98+
},
9699
"replicaCount": {
97100
"type": "integer"
98101
},

charts/kubechecks/values.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ deployment:
4040
memory: 256Mi
4141
cpu: 200m
4242

43+
revisionHistoryLimit: 10
4344
replicaCount: 1
4445

4546
image:

cmd/root.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ func init() {
122122
boolFlag(flags, "repo-shallow-clone", "Enable shallow cloning for all git repos.",
123123
newBoolOpts().
124124
withDefault(false))
125+
stringFlag(flags, "identifier", "Identifier for the kubechecks instance. Used to differentiate between multiple kubechecks instances.",
126+
newStringOpts().
127+
withDefault(""))
125128

126129
panicIfError(viper.BindPFlags(flags))
127130
setupLogOutput()

docs/usage.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ The full list of supported environment variables is described below:
5454
|`KUBECHECKS_GITHUB_APP_ID`|Github App ID.|`0`|
5555
|`KUBECHECKS_GITHUB_INSTALLATION_ID`|Github Installation ID.|`0`|
5656
|`KUBECHECKS_GITHUB_PRIVATE_KEY`|Github App Private Key.||
57+
|`KUBECHECKS_IDENTIFIER`|Identifier for the kubechecks instance. Used to differentiate between multiple kubechecks instances.||
5758
|`KUBECHECKS_KUBERNETES_CLUSTERID`|Kubernetes Cluster ID, must be specified if kubernetes-type is eks.||
5859
|`KUBECHECKS_KUBERNETES_CONFIG`|Path to your kubernetes config file, used to monitor applications.||
5960
|`KUBECHECKS_KUBERNETES_TYPE`|Kubernetes Type One of eks, or local.|`local`|

localdev/kubechecks/values.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ configMap:
2626
KUBECHECKS_TIDY_OUTDATED_COMMENTS_MODE: "delete"
2727
KUBECHECKS_ENABLE_CONFTEST: "false"
2828
KUBECHECKS_REPO_SHALLOW_CLONE: "true"
29+
KUBECHECKS_IDENTIFIER: "test"
2930

3031
deployment:
3132
annotations:

pkg/config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ type ServerConfig struct {
8686
MaxQueueSize int64 `mapstructure:"max-queue-size"`
8787
MaxConcurrenctChecks int `mapstructure:"max-concurrenct-checks"`
8888
ReplanCommentMessage string `mapstructure:"replan-comment-msg"`
89+
Identifier string `mapstructure:"identifier"`
8990
}
9091

9192
func New() (ServerConfig, error) {

pkg/events/check.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,10 @@ func (ce *CheckEvent) Process(ctx context.Context) error {
275275

276276
if len(ce.affectedItems.Applications) <= 0 && len(ce.affectedItems.ApplicationSets) <= 0 {
277277
ce.logger.Info().Msg("No affected apps or appsets, skipping")
278-
if _, err := ce.ctr.VcsClient.PostMessage(ctx, ce.pullRequest, "No changes"); err != nil {
278+
if _, err := ce.ctr.VcsClient.PostMessage(ctx, ce.pullRequest, fmt.Sprintf(`
279+
## Kubechecks %s Report
280+
No changes
281+
`, ce.ctr.Config.Identifier)); err != nil {
279282
return errors.Wrap(err, "failed to post changes")
280283
}
281284
return nil
@@ -325,7 +328,7 @@ func (ce *CheckEvent) Process(ctx context.Context) error {
325328

326329
ce.logger.Info().Msg("Finished")
327330

328-
comment := ce.vcsNote.BuildComment(ctx, start, ce.pullRequest.SHA, ce.ctr.Config.LabelFilter, ce.ctr.Config.ShowDebugInfo)
331+
comment := ce.vcsNote.BuildComment(ctx, start, ce.pullRequest.SHA, ce.ctr.Config.LabelFilter, ce.ctr.Config.ShowDebugInfo, ce.ctr.Config.Identifier)
329332

330333
if err = ce.ctr.VcsClient.UpdateMessage(ctx, ce.vcsNote, comment); err != nil {
331334
return errors.Wrap(err, "failed to push comment")
@@ -403,5 +406,7 @@ func (ce *CheckEvent) createNote(ctx context.Context) (*msg.Message, error) {
403406

404407
ce.logger.Info().Msgf("Creating note")
405408

406-
return ce.ctr.VcsClient.PostMessage(ctx, ce.pullRequest, ":hourglass: kubechecks running ... ")
409+
return ce.ctr.VcsClient.PostMessage(ctx, ce.pullRequest, fmt.Sprintf(`
410+
## Kubechecks %s Report
411+
:hourglass: kubechecks running ... `, ce.ctr.Config.Identifier))
407412
}

pkg/kustomize/process.go

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,49 @@ import (
88
"strings"
99

1010
"github.com/pkg/errors"
11+
"github.com/rs/zerolog/log"
1112
"sigs.k8s.io/kustomize/api/types"
1213
"sigs.k8s.io/kustomize/kyaml/yaml"
1314
)
1415

1516
// ProcessKustomizationFile processes a kustomization file and returns all the files and directories it references.
16-
func ProcessKustomizationFile(sourceFS fs.FS, relKustomizationPath string) (files []string, dirs []string, err error) {
17+
func ProcessKustomizationFile(sourceFS fs.FS, relKustomizationPath string) (files, dirs []string, err error) {
1718
dirName := filepath.Dir(relKustomizationPath)
18-
return processDir(sourceFS, dirName)
19+
20+
proc := processor{
21+
visitedDirs: make(map[string]struct{}),
22+
}
23+
24+
files, dirs, err = proc.processDir(sourceFS, dirName)
25+
if err != nil {
26+
return nil, nil, errors.Wrapf(err, "failed to process kustomize file %q", relKustomizationPath)
27+
}
28+
29+
return files, dirs, nil
30+
}
31+
32+
type processor struct {
33+
visitedDirs map[string]struct{}
1934
}
2035

21-
func processDir(sourceFS fs.FS, relBase string) (files []string, dirs []string, err error) {
36+
func (p processor) processDir(sourceFS fs.FS, relBase string) (files, dirs []string, err error) {
37+
if _, ok := p.visitedDirs[relBase]; ok {
38+
log.Warn().Msgf("directory %q already processed", relBase)
39+
return nil, nil, nil
40+
}
41+
42+
log.Info().Msgf("processing directory %q", relBase)
43+
p.visitedDirs[relBase] = struct{}{}
44+
2245
absKustPath := filepath.Join(relBase, "kustomization.yaml")
2346

2447
// Parse using official Kustomization type
2548
file, err := sourceFS.Open(absKustPath)
2649
if err != nil {
2750
if os.IsNotExist(err) {
28-
return nil, nil, nil // No kustomization.yaml in this directory
51+
return nil, []string{relBase}, nil // No kustomization.yaml in this directory, the dir is the important thing
2952
}
53+
3054
return nil, nil, errors.Wrapf(err, "failed to open file %q", absKustPath)
3155
}
3256

@@ -53,6 +77,10 @@ func processDir(sourceFS fs.FS, relBase string) (files []string, dirs []string,
5377
files = append(files, kust.Crds...)
5478
files = append(files, kust.Transformers...)
5579

80+
for _, helm := range kust.HelmCharts {
81+
files = append(files, helm.ValuesFile)
82+
}
83+
5684
for _, patch := range kust.Patches {
5785
if patch.Path != "" {
5886
files = append(files, patch.Path)
@@ -93,13 +121,12 @@ func processDir(sourceFS fs.FS, relBase string) (files []string, dirs []string,
93121
}
94122
}
95123

96-
// We now know this directory has a kustomization.yaml, so add it to "dirs".
97-
allDirs := append([]string(nil), relBase)
98124
allFiles := append([]string(nil), files...)
125+
var allDirs []string
99126

100127
// process directories and add them
101128
for _, relResource := range directories {
102-
subFiles, subDirs, err := processDir(sourceFS, relResource)
129+
subFiles, subDirs, err := p.processDir(sourceFS, relResource)
103130
if err != nil {
104131
return nil, nil, errors.Wrapf(err, "failed to process %q", relResource)
105132
}

0 commit comments

Comments
 (0)