8
8
"errors"
9
9
"fmt"
10
10
"io"
11
- "strings"
12
11
"text/template"
13
12
"time"
14
13
@@ -17,7 +16,6 @@ import (
17
16
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
18
17
"k8s.io/apimachinery/pkg/types"
19
18
apimachineryerrors "k8s.io/apimachinery/pkg/util/errors"
20
- "k8s.io/apimachinery/pkg/util/sets"
21
19
"k8s.io/apimachinery/pkg/util/wait"
22
20
kubeyaml "k8s.io/apimachinery/pkg/util/yaml"
23
21
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -27,10 +25,10 @@ import (
27
25
// Bootstrap creates resources in a package's fs by
28
26
// continuously retrying the list. This is blocking, i.e. it only returns (with error)
29
27
// when the context is closed or with nil when the bootstrapping is successfully completed.
30
- func Bootstrap (ctx context.Context , client client.Client , fs embed.FS , batteriesIncluded sets. Set [ string ] ) error {
28
+ func Bootstrap (ctx context.Context , client client.Client , fs embed.FS ) error {
31
29
// bootstrap non-crd resources
32
30
return wait .PollUntilContextCancel (ctx , time .Second , true , func (ctx context.Context ) (bool , error ) {
33
- if err := CreateResourcesFromFS (ctx , client , fs , batteriesIncluded ); err != nil {
31
+ if err := CreateResourcesFromFS (ctx , client , fs ); err != nil {
34
32
log .FromContext (ctx ).WithValues ("err" , err ).Info ("failed to bootstrap resources, retrying" )
35
33
return false , nil
36
34
}
@@ -39,7 +37,7 @@ func Bootstrap(ctx context.Context, client client.Client, fs embed.FS, batteries
39
37
}
40
38
41
39
// CreateResourcesFromFS creates all resources from a filesystem.
42
- func CreateResourcesFromFS (ctx context.Context , client client.Client , fs embed.FS , batteriesIncluded sets. Set [ string ] ) error {
40
+ func CreateResourcesFromFS (ctx context.Context , client client.Client , fs embed.FS ) error {
43
41
files , err := fs .ReadDir ("." )
44
42
if err != nil {
45
43
return err
@@ -50,15 +48,15 @@ func CreateResourcesFromFS(ctx context.Context, client client.Client, fs embed.F
50
48
if f .IsDir () {
51
49
continue
52
50
}
53
- if err := CreateResourceFromFS (ctx , client , f .Name (), fs , batteriesIncluded ); err != nil {
51
+ if err := CreateResourceFromFS (ctx , client , f .Name (), fs ); err != nil {
54
52
errs = append (errs , err )
55
53
}
56
54
}
57
55
return apimachineryerrors .NewAggregate (errs )
58
56
}
59
57
60
58
// CreateResourceFromFS creates given resource file.
61
- func CreateResourceFromFS (ctx context.Context , client client.Client , filename string , fs embed.FS , batteriesIncluded sets. Set [ string ] ) error {
59
+ func CreateResourceFromFS (ctx context.Context , client client.Client , filename string , fs embed.FS ) error {
62
60
raw , err := fs .ReadFile (filename )
63
61
if err != nil {
64
62
return fmt .Errorf ("could not read %s: %w" , filename , err )
@@ -81,17 +79,14 @@ func CreateResourceFromFS(ctx context.Context, client client.Client, filename st
81
79
continue
82
80
}
83
81
84
- if err := createResourceFromFS (ctx , client , doc , batteriesIncluded ); err != nil {
82
+ if err := createResourceFromFS (ctx , client , doc ); err != nil {
85
83
errs = append (errs , fmt .Errorf ("failed to create resource %s doc %d: %w" , filename , i , err ))
86
84
}
87
85
}
88
86
return apimachineryerrors .NewAggregate (errs )
89
87
}
90
88
91
- const annotationCreateOnlyKey = "bootstrap.kcp.io/create-only"
92
- const annotationBattery = "bootstrap.kcp.io/battery"
93
-
94
- func createResourceFromFS (ctx context.Context , client client.Client , raw []byte , batteriesIncluded sets.Set [string ]) error {
89
+ func createResourceFromFS (ctx context.Context , client client.Client , raw []byte ) error {
95
90
log := log .FromContext (ctx )
96
91
97
92
type Input struct {
@@ -100,9 +95,6 @@ func createResourceFromFS(ctx context.Context, client client.Client, raw []byte,
100
95
input := Input {
101
96
Batteries : map [string ]bool {},
102
97
}
103
- for _ , b := range sets.List [string ](batteriesIncluded ) {
104
- input .Batteries [b ] = true
105
- }
106
98
tmpl , err := template .New ("manifest" ).Parse (string (raw ))
107
99
if err != nil {
108
100
return fmt .Errorf ("failed to parse manifest: %w" , err )
@@ -121,21 +113,6 @@ func createResourceFromFS(ctx context.Context, client client.Client, raw []byte,
121
113
return fmt .Errorf ("decoded into incorrect type, got %T, wanted %T" , obj , & unstructured.Unstructured {})
122
114
}
123
115
124
- if v , found := u .GetAnnotations ()[annotationBattery ]; found {
125
- partOf := strings .Split (v , "," )
126
- included := false
127
- for _ , p := range partOf {
128
- if batteriesIncluded .Has (strings .TrimSpace (p )) {
129
- included = true
130
- break
131
- }
132
- }
133
- if ! included {
134
- log .V (4 ).WithValues ("resource" , u .GetName (), "batteriesRequired" , v , "batteriesIncluded" , batteriesIncluded ).Info ("skipping resource because required batteries are not among included batteries" )
135
- return nil
136
- }
137
- }
138
-
139
116
key := types.NamespacedName {
140
117
Namespace : u .GetNamespace (),
141
118
Name : u .GetName (),
@@ -148,12 +125,6 @@ func createResourceFromFS(ctx context.Context, client client.Client, raw []byte,
148
125
return err
149
126
}
150
127
151
- if _ , exists := u .GetAnnotations ()[annotationCreateOnlyKey ]; exists {
152
- log .Info ("skipping update of object because it has the create-only annotation" )
153
-
154
- return nil
155
- }
156
-
157
128
u .SetResourceVersion (u .GetResourceVersion ())
158
129
err = client .Update (ctx , u )
159
130
if err != nil {
0 commit comments