Skip to content

Commit d746cfc

Browse files
committed
Review comments: prefer not to depend on external utils
Signed-off-by: Cornelius Weig <[email protected]>
1 parent 3bdb882 commit d746cfc

File tree

2 files changed

+32
-11
lines changed

2 files changed

+32
-11
lines changed

pkg/skaffold/deploy/deploy_mux.go

+32-9
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,39 @@ import (
2020
"bytes"
2121
"context"
2222
"io"
23+
"sort"
2324
"strings"
2425

25-
"k8s.io/apimachinery/pkg/util/sets"
26-
2726
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/build"
2827
)
2928

3029
type DeployerMux []Deployer
3130

32-
var _ Deployer = DeployerMux{}
31+
type unit struct{}
32+
33+
// stringSet helps to de-duplicate a set of strings.
34+
type stringSet map[string]unit
35+
36+
func newStringSet() stringSet {
37+
return make(map[string]unit)
38+
}
39+
40+
// insert adds strings to the set.
41+
func (s stringSet) insert(strings ...string) {
42+
for _, item := range strings {
43+
s[item] = unit{}
44+
}
45+
}
46+
47+
// toList returns the sorted list of inserted strings.
48+
func (s stringSet) toList() []string {
49+
res := make([]string, 0, len(s))
50+
for item := range s {
51+
res = append(res, item)
52+
}
53+
sort.Strings(res)
54+
return res
55+
}
3356

3457
func (m DeployerMux) Labels() map[string]string {
3558
labels := make(map[string]string)
@@ -40,27 +63,27 @@ func (m DeployerMux) Labels() map[string]string {
4063
}
4164

4265
func (m DeployerMux) Deploy(ctx context.Context, w io.Writer, as []build.Artifact, ls []Labeller) *Result {
43-
seenNamespaces := sets.String{}
66+
seenNamespaces := newStringSet()
4467
for _, deployer := range m {
4568
result := deployer.Deploy(ctx, w, as, ls)
4669
if result.err != nil {
4770
return result
4871
}
49-
seenNamespaces.Insert(result.Namespaces()...)
72+
seenNamespaces.insert(result.Namespaces()...)
5073
}
51-
return NewDeploySuccessResult(seenNamespaces.List())
74+
return NewDeploySuccessResult(seenNamespaces.toList())
5275
}
5376

5477
func (m DeployerMux) Dependencies() ([]string, error) {
55-
deps := sets.String{}
78+
deps := newStringSet()
5679
for _, deployer := range m {
5780
result, err := deployer.Dependencies()
5881
if err != nil {
5982
return nil, err
6083
}
61-
deps.Insert(result...)
84+
deps.insert(result...)
6285
}
63-
return deps.List(), nil
86+
return deps.toList(), nil
6487
}
6588

6689
func (m DeployerMux) Cleanup(ctx context.Context, w io.Writer) error {

pkg/skaffold/deploy/deploy_mux_test.go

-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ type MockDeployer struct {
4040
renderErr error
4141
}
4242

43-
var _ Deployer = &MockDeployer{}
44-
4543
func (m *MockDeployer) Labels() map[string]string { return m.labels }
4644
func (m *MockDeployer) Dependencies() ([]string, error) { return m.dependencies, m.dependenciesErr }
4745
func (m *MockDeployer) Cleanup(context.Context, io.Writer) error { return m.cleanupErr }

0 commit comments

Comments
 (0)