@@ -9,8 +9,10 @@ import (
9
9
10
10
v1 "github.com/rancher/rancher/pkg/apis/rke.cattle.io/v1"
11
11
"github.com/rancher/system-agent/pkg/applyinator"
12
+ "github.com/rancher/wrangler/pkg/data/convert"
12
13
"github.com/rancher/wrangler/pkg/randomtoken"
13
14
"github.com/rancher/wrangler/pkg/yaml"
15
+ "github.com/sirupsen/logrus"
14
16
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
15
17
"k8s.io/apimachinery/pkg/runtime"
16
18
@@ -153,6 +155,32 @@ func ToBootstrapFile(config *config.Config, path string) (*applyinator.File, err
153
155
},
154
156
}), path )
155
157
}
158
+
159
+ func ToHarvesterClusterRepoFile (path string ) (* applyinator.File , error ) {
160
+ file := "/usr/share/rancher/rancherd/config.yaml.d/91-harvester-bootstrap-repo.yaml"
161
+ bytes , err := os .ReadFile (file )
162
+ if err != nil && ! os .IsNotExist (err ) {
163
+ return nil , err
164
+ }
165
+
166
+ logrus .Infof ("Loading config file [%s]" , file )
167
+ values := map [string ]interface {}{}
168
+ if err := yaml .Unmarshal (bytes , & values ); err != nil {
169
+ return nil , err
170
+ }
171
+
172
+ result := config.Config {}
173
+ convert .ToObj (values , & result )
174
+
175
+ resources := []v1.GenericMap {}
176
+ for _ , resource := range result .Resources {
177
+ if resource .Data ["kind" ] == "Deployment" || resource .Data ["kind" ] == "Service" {
178
+ resources = append (resources , resource )
179
+ }
180
+ }
181
+ return ToFile (resources , path )
182
+ }
183
+
156
184
func ToFile (resources []v1.GenericMap , path string ) (* applyinator.File , error ) {
157
185
if len (resources ) == 0 {
158
186
return nil , nil
@@ -195,3 +223,37 @@ func ToInstruction(imageOverride, systemDefaultRegistry, k8sVersion, dataDir str
195
223
Env : kubectl .Env (k8sVersion ),
196
224
}, nil
197
225
}
226
+
227
+ func GetHarvesterClusterRepoManifests (dataDir string ) string {
228
+ return fmt .Sprintf ("%s/bootstrapmanifests/harvester-cluster-repo.yaml" , dataDir )
229
+ }
230
+
231
+ func ToHarvesterClusterRepoInstruction (imageOverride , systemDefaultRegistry , k8sVersion , dataDir string ) (* applyinator.Instruction , error ) {
232
+ bootstrap := GetHarvesterClusterRepoManifests (dataDir )
233
+ cmd , err := self .Self ()
234
+ if err != nil {
235
+ return nil , fmt .Errorf ("resolving location of %s: %w" , os .Args [0 ], err )
236
+ }
237
+ return & applyinator.Instruction {
238
+ Name : "harvester-cluster-repo" ,
239
+ SaveOutput : true ,
240
+ Image : images .GetInstallerImage (imageOverride , systemDefaultRegistry , k8sVersion ),
241
+ Args : []string {"retry" , kubectl .Command (k8sVersion ), "apply" , "--validate=false" , "-f" , bootstrap },
242
+ Command : cmd ,
243
+ Env : kubectl .Env (k8sVersion ),
244
+ }, nil
245
+ }
246
+
247
+ func ToWaitHarvesterClusterRepoInstruction (k8sVersion string ) (* applyinator.Instruction , error ) {
248
+ cmd , err := self .Self ()
249
+ if err != nil {
250
+ return nil , fmt .Errorf ("resolving location of %s: %w" , os .Args [0 ], err )
251
+ }
252
+ return & applyinator.Instruction {
253
+ Name : "wait-harvester-cluster-repo" ,
254
+ SaveOutput : true ,
255
+ Args : []string {"retry" , kubectl .Command (k8sVersion ), "-n" , "cattle-system" , "rollout" , "status" , "-w" , "deploy/harvester-cluster-repo" },
256
+ Env : kubectl .Env (k8sVersion ),
257
+ Command : cmd ,
258
+ }, nil
259
+ }
0 commit comments