Skip to content

Commit 4950d28

Browse files
author
Hannes Hörl
committed
Implement template step classes as set
Signed-off-by: Hannes Hörl <[email protected]>
1 parent abdbd47 commit 4950d28

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

pkg/packageinstall/app.go

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
datapkgingv1alpha1 "github.com/vmware-tanzu/carvel-kapp-controller/pkg/apiserver/apis/datapackaging/v1alpha1"
1616
"github.com/vmware-tanzu/carvel-kapp-controller/pkg/client/clientset/versioned/scheme"
1717
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
18+
"k8s.io/apimachinery/pkg/util/sets"
1819
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
1920
)
2021

@@ -117,7 +118,10 @@ func NewApp(existingApp *v1alpha1.App, pkgInstall *pkgingv1alpha1.PackageInstall
117118
return desiredApp, nil
118119
}
119120

120-
type stepClass string
121+
type (
122+
stepClass string
123+
stepClasses = sets.Set[stepClass]
124+
)
121125

122126
const (
123127
// anything that can take values
@@ -135,24 +139,24 @@ type templateStepsPatcher struct {
135139
values []pkgingv1alpha1.PackageInstallValues
136140
annotations map[string]string
137141

138-
classifiedSteps [][]stepClass
142+
classifiedSteps []stepClasses
139143
once sync.Once
140144
}
141145

142146
func (p *templateStepsPatcher) classifySteps() {
143-
p.classifiedSteps = make([][]stepClass, len(p.templateSteps))
147+
p.classifiedSteps = make([]stepClasses, len(p.templateSteps))
144148

145149
for i, step := range p.templateSteps {
146-
classes := []stepClass{}
150+
classes := stepClasses{}
147151

148152
if step.HelmTemplate != nil {
149-
classes = append(classes, stepClassHelm, stepClassValueable)
153+
classes.Insert(stepClassHelm, stepClassValueable)
150154
}
151155
if step.Ytt != nil {
152-
classes = append(classes, stepClassYtt, stepClassValueable)
156+
classes.Insert(stepClassYtt, stepClassValueable)
153157
}
154158
if step.Cue != nil {
155-
classes = append(classes, stepClassCue, stepClassValueable)
159+
classes.Insert(stepClassCue, stepClassValueable)
156160
}
157161

158162
p.classifiedSteps[i] = classes
@@ -161,14 +165,7 @@ func (p *templateStepsPatcher) classifySteps() {
161165

162166
func (p *templateStepsPatcher) stepHasClass(stepIdx int, class stepClass) bool {
163167
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)
172169
}
173170

174171
func (p *templateStepsPatcher) getClassifiedSteps(class stepClass) []int {

0 commit comments

Comments
 (0)