@@ -20,16 +20,39 @@ import (
20
20
"bytes"
21
21
"context"
22
22
"io"
23
+ "sort"
23
24
"strings"
24
25
25
- "k8s.io/apimachinery/pkg/util/sets"
26
-
27
26
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/build"
28
27
)
29
28
30
29
type DeployerMux []Deployer
31
30
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
+ }
33
56
34
57
func (m DeployerMux ) Labels () map [string ]string {
35
58
labels := make (map [string ]string )
@@ -40,27 +63,27 @@ func (m DeployerMux) Labels() map[string]string {
40
63
}
41
64
42
65
func (m DeployerMux ) Deploy (ctx context.Context , w io.Writer , as []build.Artifact , ls []Labeller ) * Result {
43
- seenNamespaces := sets. String {}
66
+ seenNamespaces := newStringSet ()
44
67
for _ , deployer := range m {
45
68
result := deployer .Deploy (ctx , w , as , ls )
46
69
if result .err != nil {
47
70
return result
48
71
}
49
- seenNamespaces .Insert (result .Namespaces ()... )
72
+ seenNamespaces .insert (result .Namespaces ()... )
50
73
}
51
- return NewDeploySuccessResult (seenNamespaces .List ())
74
+ return NewDeploySuccessResult (seenNamespaces .toList ())
52
75
}
53
76
54
77
func (m DeployerMux ) Dependencies () ([]string , error ) {
55
- deps := sets. String {}
78
+ deps := newStringSet ()
56
79
for _ , deployer := range m {
57
80
result , err := deployer .Dependencies ()
58
81
if err != nil {
59
82
return nil , err
60
83
}
61
- deps .Insert (result ... )
84
+ deps .insert (result ... )
62
85
}
63
- return deps .List (), nil
86
+ return deps .toList (), nil
64
87
}
65
88
66
89
func (m DeployerMux ) Cleanup (ctx context.Context , w io.Writer ) error {
0 commit comments