...
1
16
17 package serviceaccount
18
19 import (
20 "context"
21
22 "k8s.io/apimachinery/pkg/runtime"
23 "k8s.io/apimachinery/pkg/util/validation/field"
24 "k8s.io/apiserver/pkg/storage/names"
25 "k8s.io/kubernetes/pkg/api/legacyscheme"
26 api "k8s.io/kubernetes/pkg/apis/core"
27 "k8s.io/kubernetes/pkg/apis/core/validation"
28 )
29
30
31 type strategy struct {
32 runtime.ObjectTyper
33 names.NameGenerator
34 }
35
36
37
38 var Strategy = strategy{legacyscheme.Scheme, names.SimpleNameGenerator}
39
40 func (strategy) NamespaceScoped() bool {
41 return true
42 }
43
44 func (strategy) PrepareForCreate(ctx context.Context, obj runtime.Object) {
45 cleanSecretReferences(obj.(*api.ServiceAccount))
46 }
47
48 func (strategy) Validate(ctx context.Context, obj runtime.Object) field.ErrorList {
49 return validation.ValidateServiceAccount(obj.(*api.ServiceAccount))
50 }
51
52
53 func (strategy) WarningsOnCreate(ctx context.Context, obj runtime.Object) []string { return nil }
54
55
56 func (strategy) Canonicalize(obj runtime.Object) {
57 }
58
59 func (strategy) AllowCreateOnUpdate() bool {
60 return false
61 }
62
63 func (strategy) PrepareForUpdate(ctx context.Context, obj, old runtime.Object) {
64 cleanSecretReferences(obj.(*api.ServiceAccount))
65 }
66
67 func cleanSecretReferences(serviceAccount *api.ServiceAccount) {
68 for i, secret := range serviceAccount.Secrets {
69 serviceAccount.Secrets[i] = api.ObjectReference{Name: secret.Name}
70 }
71 }
72
73 func (strategy) ValidateUpdate(ctx context.Context, obj, old runtime.Object) field.ErrorList {
74 return validation.ValidateServiceAccountUpdate(obj.(*api.ServiceAccount), old.(*api.ServiceAccount))
75 }
76
77
78 func (strategy) WarningsOnUpdate(ctx context.Context, obj, old runtime.Object) []string {
79 return nil
80 }
81
82 func (strategy) AllowUnconditionalUpdate() bool {
83 return true
84 }
85
View as plain text