Skip to content

Commit 2d1dbda

Browse files
Merge pull request #27 from segmentio/yolken-misc-updates4
Misc. fixes
2 parents af2bf34 + b9dcf7f commit 2d1dbda

File tree

16 files changed

+140
-49
lines changed

16 files changed

+140
-49
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ environments. We welcome feedback and collaboration to make `kubeapply` useful t
5656

5757
`kubeapply` depends on the following tools:
5858

59-
- [`kubectl`](https://kubernetes.io/docs/tasks/tools/install-kubectl/): v1.13 or newer
59+
- [`kubectl`](https://kubernetes.io/docs/tasks/tools/install-kubectl/): v1.16 or newer
6060
- [`helm`](https://helm.sh/docs/intro/install/): v3.5.0 or newer (only needed if using helm charts)
61-
- [`kubeval`](https://kubeval.instrumenta.dev/installation/): v1.13 or newer
61+
- [`kubeval`](https://kubeval.instrumenta.dev/installation/): v0.15.0 or newer
6262

6363
Make sure that they're installed locally and available in your path.
6464

cmd/kubeapply/subcmd/apply.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ func applyClusterPath(ctx context.Context, path string) error {
175175
return err
176176
}
177177

178-
results, rawDiffs, err := execDiff(ctx, clusterConfig, !applyFlagValues.simpleOutput)
178+
results, rawDiffs, err := execDiff(ctx, clusterConfig, applyFlagValues.simpleOutput)
179179
if err != nil {
180180
log.Errorf("Error running diff: %+v", err)
181181
log.Info(
@@ -185,7 +185,7 @@ func applyClusterPath(ctx context.Context, path string) error {
185185
}
186186

187187
if results != nil {
188-
diff.PrintSummary(results)
188+
diff.PrintFull(results)
189189
} else {
190190
log.Infof("Raw diff results:\n%s", rawDiffs)
191191
}

cmd/kubeapply/subcmd/diff_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,4 @@ func TestDiff(t *testing.T) {
2525
filepath.Join(testClusterDir, "cluster.yaml"),
2626
)
2727
require.Nil(t, err)
28-
29-
// TODO: Make this test more sophisticated.
3028
}

cmd/kubeapply/subcmd/expand.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,28 +34,28 @@ var expandCmd = &cobra.Command{
3434
}
3535

3636
type expandFlags struct {
37-
// Number of helm instances to run in parallel when expanding out charts.
38-
helmParallelism int
39-
4037
// Clean old configs in expanded directory before expanding
4138
clean bool
39+
40+
// Number of helm instances to run in parallel when expanding out charts.
41+
helmParallelism int
4242
}
4343

4444
var expandFlagsValues expandFlags
4545

4646
func init() {
47-
expandCmd.Flags().IntVar(
48-
&expandFlagsValues.helmParallelism,
49-
"parallelism",
50-
5,
51-
"Parallelism on helm expansions",
52-
)
5347
expandCmd.Flags().BoolVar(
5448
&expandFlagsValues.clean,
5549
"clean",
5650
false,
5751
"Clean out old configs in expanded directory",
5852
)
53+
expandCmd.Flags().IntVar(
54+
&expandFlagsValues.helmParallelism,
55+
"helm-parallelism",
56+
5,
57+
"Parallelism on helm expansions",
58+
)
5959

6060
RootCmd.AddCommand(expandCmd)
6161
}
@@ -211,6 +211,7 @@ func expandProfile(
211211
expandedPath,
212212
clusterConfig,
213213
true,
214+
true,
214215
)
215216
if err != nil {
216217
return err

data/data.go

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/cluster/kube/ordered_client.go

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ import (
1818
)
1919

2020
const (
21-
diffScript = "kdiff-wrapper.sh"
21+
structuredDiffScript = "kdiff-wrapper.sh"
22+
rawDiffScript = "raw-diff.sh"
2223
)
2324

2425
// TODO: Switch to a YAML library that supports doing this splitting for us.
@@ -183,24 +184,29 @@ func (k *OrderedClient) Diff(
183184
}
184185

185186
envVars := []string{}
187+
var diffScript string
186188

187189
if structured {
188-
diffCmd = filepath.Join(tempDir, diffScript)
189-
err = ioutil.WriteFile(
190-
diffCmd,
191-
data.MustAsset(fmt.Sprintf("scripts/%s", diffScript)),
192-
0755,
193-
)
194-
if err != nil {
195-
return nil, err
196-
}
190+
diffScript = structuredDiffScript
191+
} else {
192+
diffScript = rawDiffScript
193+
}
197194

198-
envVars = append(
199-
envVars,
200-
fmt.Sprintf("KUBECTL_EXTERNAL_DIFF=%s", diffCmd),
201-
)
195+
diffCmd = filepath.Join(tempDir, diffScript)
196+
err = ioutil.WriteFile(
197+
diffCmd,
198+
data.MustAsset(fmt.Sprintf("scripts/%s", diffScript)),
199+
0755,
200+
)
201+
if err != nil {
202+
return nil, err
202203
}
203204

205+
envVars = append(
206+
envVars,
207+
fmt.Sprintf("KUBECTL_EXTERNAL_DIFF=%s", diffCmd),
208+
)
209+
204210
return runKubectlOutput(
205211
ctx,
206212
args,

pkg/cluster/kube_client.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,10 @@ func (cc *KubeClusterClient) Config() *config.ClusterConfig {
266266
}
267267

268268
// GetNamespaceUID returns the kubernetes identifier for a given namespace in this cluster.
269-
func (cc *KubeClusterClient) GetNamespaceUID(ctx context.Context, namespace string) (string, error) {
269+
func (cc *KubeClusterClient) GetNamespaceUID(
270+
ctx context.Context,
271+
namespace string,
272+
) (string, error) {
270273
return cc.kubeClient.GetNamespaceUID(ctx, namespace)
271274
}
272275

pkg/events/handler.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,11 @@ func (whh *WebhookHandler) runApply(
422422
clusterClient.Config().ServerSideApply,
423423
)
424424
if err != nil {
425-
applyErr = fmt.Errorf("%+v", err)
425+
applyErr = fmt.Errorf(
426+
"Error applying for cluster %s: %+v",
427+
clusterName,
428+
err,
429+
)
426430
break
427431
}
428432

@@ -553,7 +557,11 @@ func (whh *WebhookHandler) runDiffs(
553557
clusterClient.Config().ServerSideApply,
554558
)
555559
if err != nil {
556-
diffErr = fmt.Errorf("%+v", err)
560+
diffErr = fmt.Errorf(
561+
"Error diffing for cluster %s: %+v",
562+
clusterName,
563+
err,
564+
)
557565
break
558566
}
559567

pkg/events/handler_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ func TestHandleWebhook(t *testing.T) {
338338
expComments: []commentMatch{
339339
{
340340
contains: []string{
341-
"Error comment: kubectl error",
341+
"Error comment: Error diffing for cluster test-env:test-region:test-cluster2: kubectl error",
342342
},
343343
},
344344
},
@@ -581,7 +581,7 @@ func TestHandleWebhook(t *testing.T) {
581581
expComments: []commentMatch{
582582
{
583583
contains: []string{
584-
"Error comment: kubectl error",
584+
"Error comment: Error applying for cluster test-env:test-region:test-cluster2: kubectl error",
585585
},
586586
},
587587
},

pkg/pullreq/diffs.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ func GetCoveredClusters(
5252
err := filepath.Walk(
5353
repoRoot,
5454
func(path string, info os.FileInfo, err error) error {
55+
if err != nil {
56+
return err
57+
}
5558
if info.IsDir() {
5659
return nil
5760
}
@@ -212,6 +215,9 @@ func getExpandedConfigFiles(
212215
err := filepath.Walk(
213216
configObj.ExpandedPath,
214217
func(path string, info os.FileInfo, err error) error {
218+
if err != nil {
219+
return err
220+
}
215221
if info.IsDir() {
216222
return nil
217223
}

0 commit comments

Comments
 (0)