...
1
16
17 package servicecidr
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/registry/rest"
25 "k8s.io/apiserver/pkg/storage/names"
26 "k8s.io/kubernetes/pkg/api/legacyscheme"
27 "k8s.io/kubernetes/pkg/apis/networking"
28 "k8s.io/kubernetes/pkg/apis/networking/validation"
29 "sigs.k8s.io/structured-merge-diff/v4/fieldpath"
30 )
31
32
33 type serviceCIDRStrategy struct {
34 runtime.ObjectTyper
35 names.NameGenerator
36 }
37
38
39 var Strategy = serviceCIDRStrategy{legacyscheme.Scheme, names.SimpleNameGenerator}
40
41
42 var _ rest.RESTCreateStrategy = Strategy
43
44
45 var _ rest.RESTUpdateStrategy = Strategy
46
47
48 func (serviceCIDRStrategy) NamespaceScoped() bool {
49 return false
50 }
51
52
53
54 func (serviceCIDRStrategy) GetResetFields() map[fieldpath.APIVersion]*fieldpath.Set {
55 fields := map[fieldpath.APIVersion]*fieldpath.Set{
56 "networking/v1alpha1": fieldpath.NewSet(
57 fieldpath.MakePathOrDie("status"),
58 ),
59 }
60 return fields
61 }
62
63
64 func (serviceCIDRStrategy) PrepareForCreate(ctx context.Context, obj runtime.Object) {
65 _ = obj.(*networking.ServiceCIDR)
66
67 }
68
69
70 func (serviceCIDRStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime.Object) {
71 newServiceCIDR := obj.(*networking.ServiceCIDR)
72 oldServiceCIDR := old.(*networking.ServiceCIDR)
73
74 _, _ = newServiceCIDR, oldServiceCIDR
75 }
76
77
78 func (serviceCIDRStrategy) Validate(ctx context.Context, obj runtime.Object) field.ErrorList {
79 cidrConfig := obj.(*networking.ServiceCIDR)
80 err := validation.ValidateServiceCIDR(cidrConfig)
81 return err
82 }
83
84
85 func (serviceCIDRStrategy) Canonicalize(obj runtime.Object) {
86 }
87
88
89 func (serviceCIDRStrategy) AllowCreateOnUpdate() bool {
90 return false
91 }
92
93
94 func (serviceCIDRStrategy) WarningsOnCreate(ctx context.Context, obj runtime.Object) []string {
95 return nil
96 }
97
98
99 func (serviceCIDRStrategy) ValidateUpdate(ctx context.Context, new, old runtime.Object) field.ErrorList {
100 newServiceCIDR := new.(*networking.ServiceCIDR)
101 oldServiceCIDR := old.(*networking.ServiceCIDR)
102 errList := validation.ValidateServiceCIDR(newServiceCIDR)
103 errList = append(errList, validation.ValidateServiceCIDRUpdate(newServiceCIDR, oldServiceCIDR)...)
104 return errList
105 }
106
107
108 func (serviceCIDRStrategy) AllowUnconditionalUpdate() bool {
109 return true
110 }
111
112
113 func (serviceCIDRStrategy) WarningsOnUpdate(ctx context.Context, obj, old runtime.Object) []string {
114 return nil
115 }
116
117 type serviceCIDRStatusStrategy struct {
118 serviceCIDRStrategy
119 }
120
121
122 var StatusStrategy = serviceCIDRStatusStrategy{Strategy}
123
124
125
126 func (serviceCIDRStatusStrategy) GetResetFields() map[fieldpath.APIVersion]*fieldpath.Set {
127 fields := map[fieldpath.APIVersion]*fieldpath.Set{
128 "networking/v1alpha1": fieldpath.NewSet(
129 fieldpath.MakePathOrDie("spec"),
130 ),
131 }
132 return fields
133 }
134
135
136 func (serviceCIDRStatusStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime.Object) {
137 newServiceCIDR := obj.(*networking.ServiceCIDR)
138 oldServiceCIDR := old.(*networking.ServiceCIDR)
139
140 newServiceCIDR.Spec = oldServiceCIDR.Spec
141 }
142
143
144 func (serviceCIDRStatusStrategy) ValidateUpdate(ctx context.Context, obj, old runtime.Object) field.ErrorList {
145 return validation.ValidateServiceCIDRStatusUpdate(obj.(*networking.ServiceCIDR), old.(*networking.ServiceCIDR))
146 }
147
148
149 func (serviceCIDRStatusStrategy) WarningsOnUpdate(ctx context.Context, obj, old runtime.Object) []string {
150 return nil
151 }
152
View as plain text