Skip to content
This repository was archived by the owner on Mar 16, 2024. It is now read-only.

Commit ebd5f0a

Browse files
Properly communicate missing secrets from secret:// syntax to user
Signed-off-by: Darren Shepherd <[email protected]>
1 parent adbb4ca commit ebd5f0a

File tree

8 files changed

+33
-24
lines changed

8 files changed

+33
-24
lines changed

pkg/apis/internal.acorn.io/v1/appstatus.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ func (e *ExpressionError) String() string {
3030
if e.DependencyNotFound == nil {
3131
return "error [" + e.Error + "] expression [" + e.Expression + "]"
3232
}
33+
if e.Expression != "" {
34+
return fmt.Sprintf("missing %s [%s] from expression [%s]", e.DependencyNotFound.DependencyType, e.DependencyNotFound.Name, e.Expression)
35+
}
3336
return fmt.Sprintf("missing %s [%s]", e.DependencyNotFound.DependencyType, e.DependencyNotFound.Name)
3437
}
3538

pkg/apis/internal.acorn.io/v1/unmarshal.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -273,29 +273,20 @@ func (in *VolumeBinding) UnmarshalJSON(data []byte) error {
273273

274274
func impliedSecretsForContainer(app *AppSpec, container Container) {
275275
for _, env := range container.Environment {
276-
if strings.Contains(env.Secret.Name, ".") {
277-
continue
278-
}
279276
if _, ok := app.Secrets[env.Secret.Name]; env.Secret.Name != "" && !ok {
280277
app.Secrets[env.Secret.Name] = Secret{
281278
Type: "opaque",
282279
}
283280
}
284281
}
285282
for _, dir := range container.Dirs {
286-
if strings.Contains(dir.Secret.Name, ".") {
287-
continue
288-
}
289283
if _, ok := app.Secrets[dir.Secret.Name]; dir.Secret.Name != "" && !ok {
290284
app.Secrets[dir.Secret.Name] = Secret{
291285
Type: "opaque",
292286
}
293287
}
294288
}
295289
for _, file := range container.Files {
296-
if strings.Contains(file.Secret.Name, ".") {
297-
continue
298-
}
299290
if _, ok := app.Secrets[file.Secret.Name]; file.Secret.Name != "" && !ok {
300291
app.Secrets[file.Secret.Name] = Secret{
301292
Type: "opaque",

pkg/controller/appdefinition/deploy.go

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"strconv"
1111
"strings"
1212

13-
"github.com/acorn-io/baaah/pkg/apply"
1413
"github.com/acorn-io/baaah/pkg/router"
1514
"github.com/acorn-io/baaah/pkg/typed"
1615
v1 "github.com/acorn-io/runtime/pkg/apis/internal.acorn.io/v1"
@@ -551,36 +550,40 @@ func getRevision(req router.Request, namespace, secretName string) (string, erro
551550

552551
func getSecretAnnotations(req router.Request, appInstance *v1.AppInstance, container v1.Container, interpolator *secrets.Interpolator) (map[string]string, error) {
553552
var (
554-
secrets []string
555-
result = map[string]string{}
553+
secretNames = sets.New[string]()
554+
result = map[string]string{}
556555
)
557556

558557
for _, env := range container.Environment {
559558
if env.Secret.OnChange == v1.ChangeTypeRedeploy {
560-
secrets = append(secrets, env.Secret.Name)
559+
secretNames.Insert(env.Secret.Name)
561560
}
562561
}
563562
for _, file := range container.Files {
564563
if file.Secret.OnChange == v1.ChangeTypeRedeploy {
565-
secrets = append(secrets, file.Secret.Name)
564+
secretNames.Insert(file.Secret.Name)
566565
}
567566
}
568567
for _, dir := range container.Dirs {
569568
if dir.Secret.OnChange == v1.ChangeTypeRedeploy {
570-
secrets = append(secrets, dir.Secret.Name)
569+
secretNames.Insert(dir.Secret.Name)
571570
}
572571
}
573572

574-
for _, secret := range secrets {
573+
for _, secret := range sets.List(secretNames) {
575574
if secret == "" {
576575
continue
577576
}
578577
rev, err := getRevision(req, appInstance.Status.Namespace, secret)
579578
if apierror.IsNotFound(err) {
580-
if !appInstance.GetStopped() {
581-
result[apply.AnnotationUpdate] = "false"
582-
}
583-
result[apply.AnnotationCreate] = "false"
579+
interpolator.AddError(&secrets.ErrInterpolation{
580+
ExpressionError: v1.ExpressionError{
581+
DependencyNotFound: &v1.DependencyNotFound{
582+
DependencyType: v1.DependencySecret,
583+
Name: secret,
584+
},
585+
},
586+
})
584587
} else if err != nil {
585588
return nil, err
586589
}
@@ -659,7 +662,7 @@ func toDeployment(req router.Request, appInstance *v1.AppInstance, tag name.Refe
659662
if appInstance.Spec.Stop != nil && *appInstance.Spec.Stop {
660663
dep.Spec.Replicas = new(int32)
661664
} else {
662-
interpolator.AddMissingAnnotations(dep.Annotations)
665+
interpolator.AddMissingAnnotations(appInstance.GetStopped(), dep.Annotations)
663666
}
664667

665668
return dep, nil

pkg/controller/appdefinition/jobs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ func toJob(req router.Request, appInstance *v1.AppInstance, pullSecrets *PullSec
156156
},
157157
}
158158

159-
interpolator.AddMissingAnnotations(baseAnnotations)
159+
interpolator.AddMissingAnnotations(appInstance.GetStopped(), baseAnnotations)
160160

161161
if container.Schedule == "" {
162162
jobSpec.BackoffLimit = &[]int32{1000}[0]

pkg/controller/appstatus/appstatus.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@ func PrepareStatus(req router.Request, _ router.Response) error {
2828
// dependency status will be set correctly.
2929
status.Ready = status.Ready && app.Generation == app.Status.ObservedGeneration
3030
status.ExpressionErrors = nil
31+
status.Dependencies = nil
3132
app.Status.AppStatus.Containers[name] = status
3233
}
3334

3435
for name, status := range app.Status.AppStatus.Jobs {
3536
status.ExpressionErrors = nil
37+
status.Dependencies = nil
3638
if app.Generation != app.Status.ObservedGeneration && jobs.ShouldRun(name, app) {
3739
// If a job is going to run again, then set its status to not ready so that the controller will run it again and the
3840
// dependency status will be set correctly.

pkg/controller/appstatus/containers.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ func (a *appStatusRenderer) readContainers() error {
3838
cs.LinkOverride = ports.LinkService(a.app, containerName)
3939
cs.ErrorMessages = append(cs.ErrorMessages, summary.ErrorMessages...)
4040
cs.ExpressionErrors = existingStatus[containerName].ExpressionErrors
41+
cs.Dependencies = existingStatus[containerName].Dependencies
4142
cs.TransitioningMessages = append(cs.TransitioningMessages, summary.TransitioningMessages...)
4243
cs.MaxReplicaRestartCount = summary.MaxReplicaRestartCount
4344

pkg/controller/appstatus/jobs.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ func (a *appStatusRenderer) readJobs() error {
3131
CreateEventSucceeded: existingStatus[jobName].CreateEventSucceeded,
3232
Skipped: existingStatus[jobName].Skipped,
3333
ExpressionErrors: existingStatus[jobName].ExpressionErrors,
34+
Dependencies: existingStatus[jobName].Dependencies,
3435
}
3536
summary := summary[jobName]
3637

pkg/secrets/interpolation.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,11 @@ func (i *Interpolator) Incomplete() bool {
123123
return len(i.incomplete) > 0
124124
}
125125

126-
func (i *Interpolator) AddMissingAnnotations(annotations map[string]string) {
126+
func (i *Interpolator) AddMissingAnnotations(stopped bool, annotations map[string]string) {
127127
if i.Incomplete() {
128-
annotations[apply.AnnotationUpdate] = "false"
128+
if !stopped {
129+
annotations[apply.AnnotationUpdate] = "false"
130+
}
129131
annotations[apply.AnnotationCreate] = "false"
130132
}
131133
}
@@ -423,6 +425,12 @@ func (i *Interpolator) saveError(err error) {
423425
exprError := v1.ExpressionError{
424426
Error: err.Error(),
425427
}
428+
if ee := (*ErrInterpolation)(nil); errors.As(err, &ee) {
429+
exprError = ee.ExpressionError
430+
if exprError.Error == "" {
431+
exprError.Error = exprError.String()
432+
}
433+
}
426434
if i.containerName != "" {
427435
i.incomplete[i.containerName] = true
428436
c := i.app.Status.AppStatus.Containers[i.containerName]

0 commit comments

Comments
 (0)