@@ -15,6 +15,7 @@ import (
15
15
datapkgingv1alpha1 "github.com/vmware-tanzu/carvel-kapp-controller/pkg/apiserver/apis/datapackaging/v1alpha1"
16
16
"github.com/vmware-tanzu/carvel-kapp-controller/pkg/client/clientset/versioned/scheme"
17
17
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
18
+ "k8s.io/apimachinery/pkg/util/sets"
18
19
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
19
20
)
20
21
@@ -117,7 +118,10 @@ func NewApp(existingApp *v1alpha1.App, pkgInstall *pkgingv1alpha1.PackageInstall
117
118
return desiredApp , nil
118
119
}
119
120
120
- type stepClass string
121
+ type (
122
+ stepClass string
123
+ stepClasses = sets.Set [stepClass ]
124
+ )
121
125
122
126
const (
123
127
// anything that can take values
@@ -135,24 +139,24 @@ type templateStepsPatcher struct {
135
139
values []pkgingv1alpha1.PackageInstallValues
136
140
annotations map [string ]string
137
141
138
- classifiedSteps [][] stepClass
142
+ classifiedSteps []stepClasses
139
143
once sync.Once
140
144
}
141
145
142
146
func (p * templateStepsPatcher ) classifySteps () {
143
- p .classifiedSteps = make ([][] stepClass , len (p .templateSteps ))
147
+ p .classifiedSteps = make ([]stepClasses , len (p .templateSteps ))
144
148
145
149
for i , step := range p .templateSteps {
146
- classes := [] stepClass {}
150
+ classes := stepClasses {}
147
151
148
152
if step .HelmTemplate != nil {
149
- classes = append ( classes , stepClassHelm , stepClassValueable )
153
+ classes . Insert ( stepClassHelm , stepClassValueable )
150
154
}
151
155
if step .Ytt != nil {
152
- classes = append ( classes , stepClassYtt , stepClassValueable )
156
+ classes . Insert ( stepClassYtt , stepClassValueable )
153
157
}
154
158
if step .Cue != nil {
155
- classes = append ( classes , stepClassCue , stepClassValueable )
159
+ classes . Insert ( stepClassCue , stepClassValueable )
156
160
}
157
161
158
162
p .classifiedSteps [i ] = classes
@@ -161,14 +165,7 @@ func (p *templateStepsPatcher) classifySteps() {
161
165
162
166
func (p * templateStepsPatcher ) stepHasClass (stepIdx int , class stepClass ) bool {
163
167
p .once .Do (p .classifySteps )
164
-
165
- for _ , stepClass := range p .classifiedSteps [stepIdx ] {
166
- if stepClass == class {
167
- return true
168
- }
169
- }
170
-
171
- return false
168
+ return p .classifiedSteps [stepIdx ].Has (class )
172
169
}
173
170
174
171
func (p * templateStepsPatcher ) getClassifiedSteps (class stepClass ) []int {
0 commit comments