This repository has been archived by the owner on Mar 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 100
/
secrets.go
85 lines (71 loc) · 2.22 KB
/
secrets.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package appstatus
import (
"fmt"
"strconv"
"github.com/acorn-io/baaah/pkg/router"
"github.com/acorn-io/baaah/pkg/typed"
v1 "github.com/acorn-io/runtime/pkg/apis/internal.acorn.io/v1"
"github.com/acorn-io/runtime/pkg/labels"
"github.com/acorn-io/runtime/pkg/publicname"
"github.com/acorn-io/runtime/pkg/ref"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
)
func linkedSecret(app *v1.AppInstance, name string) string {
if name == "" {
return ""
}
for _, binding := range app.Spec.Secrets {
if binding.Target == name {
return binding.Secret
}
}
return ""
}
func (a *appStatusRenderer) readSecrets() (err error) {
var (
existingStatus = a.app.Status.AppStatus.Secrets
)
// reset state
a.app.Status.AppStatus.Secrets = map[string]v1.SecretStatus{}
for secretName, secretDef := range a.app.Status.AppSpec.Secrets {
s := v1.SecretStatus{
CommonStatus: v1.CommonStatus{
LinkOverride: linkedSecret(a.app, secretName),
ErrorMessages: existingStatus[secretName].LookupErrors,
TransitioningMessages: existingStatus[secretName].LookupTransitioning,
},
}
secret := &corev1.Secret{}
if err := ref.Lookup(a.ctx, a.c, secret, a.app.Status.Namespace, secretName); apierrors.IsNotFound(err) {
a.app.Status.AppStatus.Secrets[secretName] = s
continue
} else if err != nil {
return err
}
s.UpToDate = secret.Annotations[labels.AcornAppGeneration] == strconv.Itoa(int(a.app.Generation))
s.Defined = true
s.Ready = true
sourceSecret := &corev1.Secret{}
if err := a.c.Get(a.ctx, router.Key(a.app.Namespace, secret.Labels[labels.AcornSecretSourceName]), sourceSecret); apierrors.IsNotFound(err) {
a.app.Status.AppStatus.Secrets[secretName] = s
continue
} else if err != nil {
return err
}
s.SecretName = publicname.Get(sourceSecret)
if secretDef.Type == string(v1.SecretTypeGenerated) && secretDef.Params["job"] != "" {
s.JobName = fmt.Sprint(secretDef.Params["job"])
s.JobReady, err = a.isJobReady(s.JobName)
if err != nil {
return err
}
} else {
s.JobReady = true
}
s.Ready = s.Ready && s.JobReady
s.DataKeys = typed.SortedKeys(sourceSecret.Data)
a.app.Status.AppStatus.Secrets[secretName] = s
}
return nil
}