Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: return error instead of log.Fatalf() #5625

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions api/internal/accumulator/namereferencetransformer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ func TestNameReferenceUnhappyRun(t *testing.T) {
func TestNameReferencePersistentVolumeHappyRun(t *testing.T) {
rf := provider.NewDefaultDepProvider().GetResourceFactory()

v1 := rf.FromMapWithName(
v1, _ := rf.FromMapWithName(
chansuke marked this conversation as resolved.
Show resolved Hide resolved
"volume1",
map[string]interface{}{
"apiVersion": "v1",
Expand All @@ -599,7 +599,7 @@ func TestNameReferencePersistentVolumeHappyRun(t *testing.T) {
"name": "someprefix-volume1",
},
})
c1 := rf.FromMapWithName(
c1, _ := rf.FromMapWithName(
"claim1",
map[string]interface{}{
"apiVersion": "v1",
Expand All @@ -614,7 +614,7 @@ func TestNameReferencePersistentVolumeHappyRun(t *testing.T) {
})

v2 := v1.DeepCopy()
c2 := rf.FromMapWithName(
c2, _ := rf.FromMapWithName(
"claim1",
map[string]interface{}{
"apiVersion": "v1",
Expand Down
33 changes: 20 additions & 13 deletions api/internal/accumulator/resaccumulator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,20 @@ func expectLog(t *testing.T, log bytes.Buffer, expect string) {
func TestResolveVarsVarNeedsDisambiguation(t *testing.T) {
ra := makeResAccumulator(t)
rm0 := resmap.New()
err := rm0.Append(
provider.NewDefaultDepProvider().GetResourceFactory().FromMap(
map[string]interface{}{
"apiVersion": "v1",
"kind": "Service",
"metadata": map[string]interface{}{
"name": "backendOne",
"namespace": "fooNamespace",
},
}))

r, err := provider.NewDefaultDepProvider().GetResourceFactory().FromMap(
map[string]interface{}{
"apiVersion": "v1",
"kind": "Service",
"metadata": map[string]interface{}{
"name": "backendOne",
"namespace": "fooNamespace",
},
})
if err != nil {
t.Fatalf("unexpected err: %v", err)
chansuke marked this conversation as resolved.
Show resolved Hide resolved
}
err = rm0.Append(r)
if err != nil {
t.Fatalf("unexpected err: %v", err)
}
Expand Down Expand Up @@ -227,7 +231,8 @@ func TestResolveVarConflicts(t *testing.T) {
// create accumulators holding apparently conflicting vars that are not
// actually in conflict because they point to the same concrete value.
rm0 := resmap.New()
err := rm0.Append(rf.FromMap(fooAws))
r0, _ := rf.FromMap(fooAws)
err := rm0.Append(r0)
require.NoError(t, err)
ac0 := MakeEmptyAccumulator()
err = ac0.AppendAll(rm0)
Expand All @@ -236,7 +241,8 @@ func TestResolveVarConflicts(t *testing.T) {
require.NoError(t, err)

rm1 := resmap.New()
err = rm1.Append(rf.FromMap(barAws))
r1, _ := rf.FromMap(barAws)
err = rm1.Append(r1)
require.NoError(t, err)
ac1 := MakeEmptyAccumulator()
err = ac1.AppendAll(rm1)
Expand All @@ -255,7 +261,8 @@ func TestResolveVarConflicts(t *testing.T) {
// two above (because it contains a variable whose name is used in the other
// accumulators AND whose concrete values are different).
rm2 := resmap.New()
err = rm2.Append(rf.FromMap(barGcp))
r2, _ := rf.FromMap(barGcp)
err = rm2.Append(r2)
require.NoError(t, err)
ac2 := MakeEmptyAccumulator()
err = ac2.AppendAll(rm2)
Expand Down
5 changes: 4 additions & 1 deletion api/internal/plugins/execplugin/execplugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ s/$BAR/bar baz/g
}
pvd := provider.NewDefaultDepProvider()
rf := resmap.NewFactory(pvd.GetResourceFactory())
pluginConfig := rf.RF().FromMap(
pluginConfig, err := rf.RF().FromMap(
map[string]interface{}{
"apiVersion": "someteam.example.com/v1",
"kind": "SedTransformer",
Expand All @@ -51,6 +51,9 @@ s/$BAR/bar baz/g
"argsOneLiner": "one two 'foo bar'",
"argsFromFile": "sed-input.txt",
})
if err != nil {
t.Fatalf("unexpected err: %v", err)
}

pluginConfig.RemoveBuildAnnotations()
pc := types.DisabledPluginConfig()
Expand Down
5 changes: 4 additions & 1 deletion api/internal/plugins/utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,14 @@ func TestDeterminePluginSrcRoot(t *testing.T) {
}

func makeConfigMap(rf *resource.Factory, name, behavior string, hashValue *string) *resource.Resource {
r := rf.FromMap(map[string]interface{}{
r, err := rf.FromMap(map[string]interface{}{
"apiVersion": "v1",
"kind": "ConfigMap",
"metadata": map[string]interface{}{"name": name},
})
if err != nil {
panic(err)
}
annotations := map[string]string{}
if behavior != "" {
annotations[BehaviorAnnotation] = behavior
Expand Down
186 changes: 94 additions & 92 deletions api/internal/target/kusttarget_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,58 @@ metadata:
pvd := provider.NewDefaultDepProvider()
resFactory := pvd.GetResourceFactory()

resources := []*resource.Resource{
resFactory.FromMapWithName("dply1", map[string]interface{}{
"apiVersion": "apps/v1",
"kind": "Deployment",
r0, _ := resFactory.FromMapWithName("dply1", map[string]interface{}{
"apiVersion": "apps/v1",
"kind": "Deployment",
"metadata": map[string]interface{}{
"name": "foo-dply1-bar",
"namespace": "ns1",
"labels": map[string]interface{}{
"app": "nginx",
},
"annotations": map[string]interface{}{
"note": "This is a test annotation",
},
},
"spec": map[string]interface{}{
"replica": "3",
"selector": map[string]interface{}{
"matchLabels": map[string]interface{}{
"app": "nginx",
},
},
"template": map[string]interface{}{
"metadata": map[string]interface{}{
"annotations": map[string]interface{}{
"note": "This is a test annotation",
},
"labels": map[string]interface{}{
"app": "nginx",
},
},
},
},
})
r1, _ := resFactory.FromMapWithName("ns1", map[string]interface{}{
"apiVersion": "v1",
"kind": "Namespace",
"metadata": map[string]interface{}{
"name": "ns1",
"labels": map[string]interface{}{
"app": "nginx",
},
"annotations": map[string]interface{}{
"note": "This is a test annotation",
},
},
})

r2, _ := resFactory.FromMapWithName("literalConfigMap",
map[string]interface{}{
"apiVersion": "v1",
"kind": "ConfigMap",
"metadata": map[string]interface{}{
"name": "foo-dply1-bar",
"name": "foo-literalConfigMap-bar-g5f6t456f5",
"namespace": "ns1",
"labels": map[string]interface{}{
"app": "nginx",
Expand All @@ -204,78 +250,34 @@ metadata:
"note": "This is a test annotation",
},
},
"spec": map[string]interface{}{
"replica": "3",
"selector": map[string]interface{}{
"matchLabels": map[string]interface{}{
"app": "nginx",
},
},
"template": map[string]interface{}{
"metadata": map[string]interface{}{
"annotations": map[string]interface{}{
"note": "This is a test annotation",
},
"labels": map[string]interface{}{
"app": "nginx",
},
},
},
"data": map[string]interface{}{
"DB_USERNAME": "admin",
"DB_PASSWORD": "somepw",
},
}),
resFactory.FromMapWithName("ns1", map[string]interface{}{
})

r3, _ := resFactory.FromMapWithName("secret",
map[string]interface{}{
"apiVersion": "v1",
"kind": "Namespace",
"kind": "Secret",
"metadata": map[string]interface{}{
"name": "ns1",
"name": "foo-secret-bar-82c2g5f8f6",
"namespace": "ns1",
"labels": map[string]interface{}{
"app": "nginx",
},
"annotations": map[string]interface{}{
"note": "This is a test annotation",
},
},
}),
resFactory.FromMapWithName("literalConfigMap",
map[string]interface{}{
"apiVersion": "v1",
"kind": "ConfigMap",
"metadata": map[string]interface{}{
"name": "foo-literalConfigMap-bar-g5f6t456f5",
"namespace": "ns1",
"labels": map[string]interface{}{
"app": "nginx",
},
"annotations": map[string]interface{}{
"note": "This is a test annotation",
},
},
"data": map[string]interface{}{
"DB_USERNAME": "admin",
"DB_PASSWORD": "somepw",
},
}),
resFactory.FromMapWithName("secret",
map[string]interface{}{
"apiVersion": "v1",
"kind": "Secret",
"metadata": map[string]interface{}{
"name": "foo-secret-bar-82c2g5f8f6",
"namespace": "ns1",
"labels": map[string]interface{}{
"app": "nginx",
},
"annotations": map[string]interface{}{
"note": "This is a test annotation",
},
},
"type": ifc.SecretTypeOpaque,
"data": map[string]interface{}{
"DB_USERNAME": base64.StdEncoding.EncodeToString([]byte("admin")),
"DB_PASSWORD": base64.StdEncoding.EncodeToString([]byte("somepw")),
},
}),
}
"type": ifc.SecretTypeOpaque,
"data": map[string]interface{}{
"DB_USERNAME": base64.StdEncoding.EncodeToString([]byte("admin")),
"DB_PASSWORD": base64.StdEncoding.EncodeToString([]byte("somepw")),
},
})

resources := []*resource.Resource{r0, r1, r2, r3}

expected := resmap.New()
for _, r := range resources {
Expand Down Expand Up @@ -352,31 +354,31 @@ metadata:
pvd := provider.NewDefaultDepProvider()
resFactory := pvd.GetResourceFactory()

resources := []*resource.Resource{
resFactory.FromMapWithName("deployment1", map[string]interface{}{
"apiVersion": "apps/v1",
"kind": "Deployment",
"metadata": map[string]interface{}{
"name": "foo-deployment1-bar",
"namespace": "ns1",
},
}), resFactory.FromMapWithName("config", map[string]interface{}{
"apiVersion": "v1",
"kind": "ConfigMap",
"metadata": map[string]interface{}{
"name": "config-bar",
"namespace": "ns1",
},
}), resFactory.FromMapWithName("secret", map[string]interface{}{
"apiVersion": "v1",
"kind": "Secret",
"metadata": map[string]interface{}{
"name": "foo-secret",
"namespace": "ns1",
},
}),
}

r0, _ := resFactory.FromMapWithName("deployment1", map[string]interface{}{
"apiVersion": "apps/v1",
"kind": "Deployment",
"metadata": map[string]interface{}{
"name": "foo-deployment1-bar",
"namespace": "ns1",
},
})
r1, _ := resFactory.FromMapWithName("config", map[string]interface{}{
"apiVersion": "v1",
"kind": "ConfigMap",
"metadata": map[string]interface{}{
"name": "config-bar",
"namespace": "ns1",
},
})
r2, _ := resFactory.FromMapWithName("secret", map[string]interface{}{
"apiVersion": "v1",
"kind": "Secret",
"metadata": map[string]interface{}{
"name": "foo-secret",
"namespace": "ns1",
},
})
var resources = []*resource.Resource{r0, r1, r2}
expected := resmap.New()
for _, r := range resources {
err := expected.Append(r)
Expand Down