-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathclusteraddon_controller.go
1423 lines (1190 loc) · 54.4 KB
/
clusteraddon_controller.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright 2023 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package controller
import (
"archive/tar"
"bytes"
"compress/gzip"
"context"
"errors"
"fmt"
"io"
"os"
"os/exec"
"path/filepath"
"reflect"
"strings"
"sync"
"text/template"
"time"
csov1alpha1 "github.com/SovereignCloudStack/cluster-stack-operator/api/v1alpha1"
"github.com/SovereignCloudStack/cluster-stack-operator/pkg/assetsclient"
"github.com/SovereignCloudStack/cluster-stack-operator/pkg/clusteraddon"
"github.com/SovereignCloudStack/cluster-stack-operator/pkg/kube"
"github.com/SovereignCloudStack/cluster-stack-operator/pkg/release"
"github.com/SovereignCloudStack/cluster-stack-operator/pkg/workloadcluster"
sprig "github.com/go-task/slim-sprig"
"github.com/google/cel-go/cel"
celtypes "github.com/google/cel-go/common/types"
"gopkg.in/yaml.v3"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/discovery"
"k8s.io/client-go/discovery/cached/memory"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/restmapper"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
"sigs.k8s.io/cluster-api/controllers/external"
"sigs.k8s.io/cluster-api/util/conditions"
"sigs.k8s.io/cluster-api/util/patch"
"sigs.k8s.io/cluster-api/util/predicates"
"sigs.k8s.io/cluster-api/util/record"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/event"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"
)
const clusterAddonNamespace = "kube-system"
const (
beforeClusterUpgradeHook = "BeforeClusterUpgrade"
afterControlPlaneInitialized = "AfterControlPlaneInitialized"
)
// RestConfigSettings contains Kubernetes rest config settings.
type RestConfigSettings struct {
QPS float32
Burst int
}
// ClusterAddonReconciler reconciles a ClusterAddon object.
type ClusterAddonReconciler struct {
client.Client
RestConfigSettings
ReleaseDirectory string
KubeClientFactory kube.Factory
AssetsClientFactory assetsclient.Factory
WatchFilterValue string
WorkloadClusterFactory workloadcluster.Factory
clusterStackRelDownloadDirectoryMutex sync.Mutex
}
//+kubebuilder:rbac:groups=clusterstack.x-k8s.io,resources=clusteraddons,verbs=get;list;watch;create;update;patch;delete
//+kubebuilder:rbac:groups=clusterstack.x-k8s.io,resources=clusteraddons/status,verbs=get;update;patch
//+kubebuilder:rbac:groups=clusterstack.x-k8s.io,resources=clusteraddons/finalizers,verbs=update
//+kubebuilder:rbac:groups=cluster.x-k8s.io,resources=clusters,verbs=get
// Reconcile is part of the main Kubernetes reconciliation loop which aims to
// move the current state of the cluster closer to the desired state.
func (r *ClusterAddonReconciler) Reconcile(ctx context.Context, req reconcile.Request) (res reconcile.Result, reterr error) {
clusterAddon := &csov1alpha1.ClusterAddon{}
if err := r.Get(ctx, req.NamespacedName, clusterAddon); err != nil {
if apierrors.IsNotFound(err) {
return reconcile.Result{}, nil
}
return reconcile.Result{}, fmt.Errorf("failed to get cluster addon %s/%s: %w", req.Name, req.Namespace, err)
}
patchHelper, err := patch.NewHelper(clusterAddon, r.Client)
if err != nil {
return reconcile.Result{}, fmt.Errorf("failed to init patch helper: %w", err)
}
defer func() {
conditions.SetSummary(clusterAddon)
if err := patchHelper.Patch(ctx, clusterAddon); err != nil {
reterr = fmt.Errorf("failed to patch clusterAddon: %w", err)
}
}()
controllerutil.AddFinalizer(clusterAddon, csov1alpha1.ClusterAddonFinalizer)
// retrieve associated cluster object
cluster := &clusterv1.Cluster{}
clusterName := client.ObjectKey{
Name: clusterAddon.Spec.ClusterRef.Name,
Namespace: clusterAddon.Spec.ClusterRef.Namespace,
}
if err := r.Get(ctx, clusterName, cluster); err != nil {
if apierrors.IsNotFound(err) && !clusterAddon.DeletionTimestamp.IsZero() {
controllerutil.RemoveFinalizer(clusterAddon, csov1alpha1.ClusterAddonFinalizer)
return reconcile.Result{}, nil
}
return ctrl.Result{}, fmt.Errorf("failed to find cluster %v: %w", clusterName, err)
}
restConfigClient := r.WorkloadClusterFactory.NewClient(cluster.Name, req.Namespace, r.Client)
restConfig, err := restConfigClient.RestConfig(ctx)
if err != nil {
conditions.MarkFalse(
clusterAddon,
csov1alpha1.ClusterReadyCondition,
csov1alpha1.ControlPlaneNotReadyReason,
clusterv1.ConditionSeverityWarning,
"kubeconfig not there (yet)",
)
return ctrl.Result{RequeueAfter: 10 * time.Second}, nil
}
// usually this is only nil in unit tests
if restConfig != nil {
restConfig.QPS = r.RestConfigSettings.QPS
restConfig.Burst = r.RestConfigSettings.Burst
clientSet, err := kubernetes.NewForConfig(restConfig)
if err != nil {
return ctrl.Result{}, fmt.Errorf("failed to create Kubernetes interface from config: %w", err)
}
if _, err := clientSet.Discovery().RESTClient().Get().AbsPath("/readyz").DoRaw(ctx); err != nil {
conditions.MarkFalse(
clusterAddon,
csov1alpha1.ClusterReadyCondition,
csov1alpha1.ControlPlaneNotReadyReason,
clusterv1.ConditionSeverityInfo,
"control plane not ready yet",
)
// wait for cluster to be ready
return reconcile.Result{RequeueAfter: 10 * time.Second}, nil
}
}
// cluster is ready, so we set a condition and can continue as well
conditions.MarkTrue(clusterAddon, csov1alpha1.ClusterReadyCondition)
releaseAsset, download, err := release.New(release.ConvertFromClusterClassToClusterStackFormat(cluster.Spec.Topology.Class), r.ReleaseDirectory)
if err != nil {
conditions.MarkFalse(clusterAddon, csov1alpha1.ClusterStackReleaseAssetsReadyCondition, csov1alpha1.IssueWithReleaseAssetsReason, clusterv1.ConditionSeverityError, "%s", err.Error())
return ctrl.Result{RequeueAfter: 10 * time.Second}, nil
}
if download {
conditions.MarkFalse(clusterAddon, csov1alpha1.ClusterStackReleaseAssetsReadyCondition, csov1alpha1.ReleaseAssetsNotDownloadedYetReason, clusterv1.ConditionSeverityInfo, "release assets not downloaded yet")
return ctrl.Result{RequeueAfter: 10 * time.Second}, nil
}
// Check for helm charts in the release assets. If they are not present, then something went wrong.
if err := releaseAsset.CheckHelmCharts(); err != nil {
msg := fmt.Sprintf("failed to validate helm charts: %s", err.Error())
conditions.MarkFalse(
clusterAddon,
csov1alpha1.ClusterStackReleaseAssetsReadyCondition,
csov1alpha1.IssueWithReleaseAssetsReason,
clusterv1.ConditionSeverityError,
"%s", msg,
)
record.Warn(clusterAddon, "ValidateHelmChartFailed", msg)
return reconcile.Result{}, nil
}
// set downloaded condition if able to read metadata file
conditions.MarkTrue(clusterAddon, csov1alpha1.ClusterStackReleaseAssetsReadyCondition)
in := &templateAndApplyClusterAddonInput{
clusterAddonChartPath: releaseAsset.ClusterAddonChartPath(),
clusterAddonValuesPath: releaseAsset.ClusterAddonValuesPath(),
kubernetesVersion: releaseAsset.Meta.Versions.Kubernetes,
clusterAddon: clusterAddon,
cluster: cluster,
restConfig: restConfig,
}
in.clusterAddonConfigPath, err = r.getClusterAddonConfigPath(cluster.Spec.Topology.Class)
if err != nil {
return reconcile.Result{}, fmt.Errorf("failed to get cluster addon config path: %w", err)
}
// Check whether current Helm chart has been applied in the workload cluster. If not, then we need to apply the helm chart (again).
// the spec.clusterStack is only set after a Helm chart from a ClusterStack has been applied successfully.
// If it is not set, the Helm chart has never been applied.
// If it is set and does not equal the ClusterClass of the cluster, then it is outdated and has to be updated.
if in.clusterAddonConfigPath == "" {
if clusterAddon.Spec.ClusterStack != cluster.Spec.Topology.Class {
metadata := releaseAsset.Meta
// only apply the Helm chart again if the Helm chart version has also changed from one cluster stack release to the other
if clusterAddon.Spec.Version != metadata.Versions.Components.ClusterAddon {
clusterAddon.Status.Ready = false
shouldRequeue, err := r.templateAndApplyClusterAddonHelmChart(ctx, in)
if err != nil {
conditions.MarkFalse(clusterAddon, csov1alpha1.HelmChartAppliedCondition, csov1alpha1.FailedToApplyObjectsReason, clusterv1.ConditionSeverityError, "failed to apply: %s", err.Error())
return ctrl.Result{}, fmt.Errorf("failed to apply helm chart: %w", err)
}
if shouldRequeue {
// set latest version and requeue
clusterAddon.Spec.Version = metadata.Versions.Components.ClusterAddon
clusterAddon.Spec.ClusterStack = cluster.Spec.Topology.Class
// set condition to false as we have not successfully applied Helm chart
conditions.MarkFalse(
clusterAddon,
csov1alpha1.HelmChartAppliedCondition,
csov1alpha1.FailedToApplyObjectsReason,
clusterv1.ConditionSeverityInfo,
"failed to successfully apply everything",
)
return ctrl.Result{RequeueAfter: 20 * time.Second}, nil
}
// Helm chart has been applied successfully
clusterAddon.Spec.Version = metadata.Versions.Components.ClusterAddon
conditions.MarkTrue(clusterAddon, csov1alpha1.HelmChartAppliedCondition)
}
clusterAddon.SetStageAnnotations(csov1alpha1.StageAnnotationValueCreated)
clusterAddon.Spec.Hook = ""
clusterAddon.Spec.ClusterStack = cluster.Spec.Topology.Class
clusterAddon.Status.Ready = true
return ctrl.Result{}, nil
}
// if condition is false we have not yet successfully applied the helm chart
if conditions.IsFalse(clusterAddon, csov1alpha1.HelmChartAppliedCondition) {
shouldRequeue, err := r.templateAndApplyClusterAddonHelmChart(ctx, in)
if err != nil {
conditions.MarkFalse(clusterAddon, csov1alpha1.HelmChartAppliedCondition, csov1alpha1.FailedToApplyObjectsReason, clusterv1.ConditionSeverityError, "failed to apply: %s", err.Error())
return ctrl.Result{}, fmt.Errorf("failed to apply helm chart: %w", err)
}
if shouldRequeue {
// set condition to false as we have not yet successfully applied helm chart
conditions.MarkFalse(clusterAddon, csov1alpha1.HelmChartAppliedCondition, csov1alpha1.FailedToApplyObjectsReason, clusterv1.ConditionSeverityInfo, "failed to successfully apply everything")
return ctrl.Result{RequeueAfter: 20 * time.Second}, nil
}
// set condition that helm chart has been applied successfully
conditions.MarkTrue(clusterAddon, csov1alpha1.HelmChartAppliedCondition)
}
clusterAddon.Spec.Hook = ""
clusterAddon.SetStageAnnotations(csov1alpha1.StageAnnotationValueCreated)
clusterAddon.Status.Ready = true
return ctrl.Result{}, nil
}
// multi-stage cluster addon flow
in.addonStagesInput, err = r.getAddonStagesInput(in.restConfig, in.clusterAddonChartPath)
if err != nil {
conditions.MarkFalse(
clusterAddon,
csov1alpha1.ClusterAddonConfigValidatedCondition,
csov1alpha1.ParsingClusterAddonConfigFailedReason,
clusterv1.ConditionSeverityError,
"cluster addon config (clusteraddon.yaml) is wrong: %s", err.Error(),
)
record.Warnf(
clusterAddon,
csov1alpha1.ParsingClusterAddonConfigFailedReason,
"cluster addon config (clusteraddon.yaml) is wrong: %s", err.Error(),
)
return reconcile.Result{}, nil
}
conditions.MarkTrue(clusterAddon, csov1alpha1.ClusterAddonConfigValidatedCondition)
// clusteraddon.yaml in the release.
clusterAddonConfig, err := clusteraddon.ParseConfig(in.clusterAddonConfigPath)
if err != nil {
return reconcile.Result{}, fmt.Errorf("failed to parse clusteraddon.yaml config: %w", err)
}
var (
oldRelease *release.Release
requeue bool
)
if clusterAddon.Spec.ClusterStack != "" {
oldRelease, requeue, err = r.downloadOldClusterStackRelease(ctx, clusterAddon)
if err != nil {
return reconcile.Result{}, fmt.Errorf("failed to download old cluster stack releases: %w", err)
}
if requeue {
return reconcile.Result{RequeueAfter: 10 * time.Second}, nil
}
// src - /tmp/cluster-stacks/docker-ferrol-1-27-v1/docker-ferrol-1-27-cluster-addon-v1.tgz
// dst - /tmp/cluster-stacks/docker-ferrol-1-27-v1/docker-ferrol-1-27-cluster-addon-v1/
in.oldDestinationClusterAddonChartDir = strings.TrimSuffix(oldRelease.ClusterAddonChartPath(), ".tgz")
in.oldKubernetesVersion = oldRelease.Meta.Versions.Kubernetes
if err := unTarContent(oldRelease.ClusterAddonChartPath(), in.oldDestinationClusterAddonChartDir); err != nil {
return reconcile.Result{}, fmt.Errorf("failed to untar old cluster stack cluster addon chart: %q: %w", oldRelease.ClusterAddonChartPath(), err)
}
}
// if a hook is specified, we cannot be ready yet
// if a hook is set, it is expected that HelmChartAppliedCondition is removed
if clusterAddon.Spec.Hook != "" {
// if the clusterAddon was ready before, it means this hook is fresh and we have to reset the status
if clusterAddon.Status.Ready || len(clusterAddon.Status.Stages) == 0 {
clusterAddon.Status.Stages = make([]csov1alpha1.StageStatus, len(clusterAddonConfig.AddonStages[clusterAddon.Spec.Hook]))
for i, stage := range clusterAddonConfig.AddonStages[clusterAddon.Spec.Hook] {
clusterAddon.Status.Stages[i].Name = stage.Name
clusterAddon.Status.Stages[i].Action = stage.Action
clusterAddon.Status.Stages[i].Phase = csov1alpha1.StagePhasePending
}
}
clusterAddon.Status.Ready = false
}
// In case the Kubernetes version stays the same, the hook server does not trigger.
// Therefore, we have to check whether the ClusterStack is upgraded and if that is the case, the ClusterAddons have to be upgraded as well.
if clusterAddon.Spec.ClusterStack != cluster.Spec.Topology.Class && oldRelease != nil && oldRelease.Meta.Versions.Kubernetes == releaseAsset.Meta.Versions.Kubernetes {
if clusterAddon.Spec.Version != releaseAsset.Meta.Versions.Components.ClusterAddon {
if clusterAddon.Status.Ready || len(clusterAddon.Status.Stages) == 0 {
clusterAddon.Status.Stages = make([]csov1alpha1.StageStatus, len(clusterAddonConfig.AddonStages[beforeClusterUpgradeHook]))
for i, stage := range clusterAddonConfig.AddonStages[beforeClusterUpgradeHook] {
clusterAddon.Status.Stages[i].Name = stage.Name
clusterAddon.Status.Stages[i].Action = stage.Action
clusterAddon.Status.Stages[i].Phase = csov1alpha1.StagePhasePending
}
}
clusterAddon.Status.Ready = false
conditions.Delete(clusterAddon, csov1alpha1.HelmChartAppliedCondition)
} else {
// If the cluster addon version don't change we don't want to apply helm charts again.
clusterAddon.Spec.ClusterStack = cluster.Spec.Topology.Class
clusterAddon.Status.Ready = true
}
}
clusterAddon.Spec.Version = releaseAsset.Meta.Versions.Components.ClusterAddon
if clusterAddon.Status.Ready {
return reconcile.Result{}, nil
}
// In case the Kubernetes version stayed the same during an upgrade, the hook server does not trigger and
// we just take the Helm charts that are supposed to be installed in the BeforeClusterUpgrade hook and apply them.
if oldRelease != nil && oldRelease.Meta.Versions.Kubernetes == releaseAsset.Meta.Versions.Kubernetes {
clusterAddon.Spec.Hook = beforeClusterUpgradeHook
for _, stage := range clusterAddonConfig.AddonStages[beforeClusterUpgradeHook] {
shouldRequeue, err := r.executeStage(ctx, stage, in)
if err != nil {
return reconcile.Result{}, fmt.Errorf("failed to execute stage: %w", err)
}
if shouldRequeue {
return reconcile.Result{RequeueAfter: 20 * time.Second}, nil
}
}
// create the list of old release objects
oldClusterStackObjectList, err := r.getOldReleaseObjects(ctx, in, clusterAddonConfig, oldRelease)
if err != nil {
return reconcile.Result{}, fmt.Errorf("failed to get old cluster stack object list from helm charts: %w", err)
}
newClusterStackObjectList, err := r.getNewReleaseObjects(ctx, in, clusterAddonConfig)
if err != nil {
return reconcile.Result{}, fmt.Errorf("failed to get new cluster stack object list from helm charts: %w", err)
}
shouldRequeue, err := cleanUpResources(ctx, in, oldClusterStackObjectList, newClusterStackObjectList)
if err != nil {
return reconcile.Result{}, fmt.Errorf("failed to clean up resources: %w", err)
}
if shouldRequeue {
return reconcile.Result{RequeueAfter: 20 * time.Second}, nil
}
// set upgrade annotation once done
clusterAddon.SetStageAnnotations(csov1alpha1.StageAnnotationValueUpgraded)
// Helm chart has been applied successfully
conditions.MarkTrue(clusterAddon, csov1alpha1.HelmChartAppliedCondition)
// remove the status resource if hook is finished
clusterAddon.Status.Resources = make([]*csov1alpha1.Resource, 0)
// remove the helm chart status from the status.
clusterAddon.Status.Stages = make([]csov1alpha1.StageStatus, 0)
// update the latest cluster class
clusterAddon.Spec.ClusterStack = cluster.Spec.Topology.Class
clusterAddon.Status.Ready = true
// unset spec hook and make cluster addon ready
clusterAddon.Spec.Hook = ""
return ctrl.Result{}, nil
}
// If hook is empty we can don't want to proceed executing staged according to current hook
// hence we can return.
if clusterAddon.Spec.Hook == "" {
conditions.MarkFalse(clusterAddon,
csov1alpha1.HookServerReadyCondition,
csov1alpha1.HookServerUnresponsiveReason,
clusterv1.ConditionSeverityInfo,
"hook server hasn't updated the spec.hook yet",
)
return reconcile.Result{}, nil
}
conditions.MarkTrue(clusterAddon, csov1alpha1.HookServerReadyCondition)
for _, stage := range clusterAddonConfig.AddonStages[clusterAddon.Spec.Hook] {
shouldRequeue, err := r.executeStage(ctx, stage, in)
if err != nil {
return reconcile.Result{}, fmt.Errorf("failed to execute stage: %q: %w", stage.Name, err)
}
if shouldRequeue {
return reconcile.Result{RequeueAfter: 20 * time.Second}, nil
}
}
if clusterAddon.Spec.Hook == afterControlPlaneInitialized || clusterAddon.Spec.Hook == beforeClusterUpgradeHook {
if clusterAddon.Spec.Hook == beforeClusterUpgradeHook {
// create the list of old release objects
oldClusterStackObjectList, err := r.getOldReleaseObjects(ctx, in, clusterAddonConfig, oldRelease)
if err != nil {
return reconcile.Result{}, fmt.Errorf("failed to get old cluster stack object list from helm charts: %w", err)
}
newClusterStackObjectList, err := r.getNewReleaseObjects(ctx, in, clusterAddonConfig)
if err != nil {
return reconcile.Result{}, fmt.Errorf("failed to get new cluster stack object list from helm charts: %w", err)
}
shouldRequeue, err := cleanUpResources(ctx, in, oldClusterStackObjectList, newClusterStackObjectList)
if err != nil {
return reconcile.Result{}, fmt.Errorf("failed to clean up resources: %w", err)
}
if shouldRequeue {
return reconcile.Result{RequeueAfter: 20 * time.Second}, nil
}
// set upgrade annotation once done
clusterAddon.SetStageAnnotations(csov1alpha1.StageAnnotationValueUpgraded)
}
// if upgrade annotation is not present add the create annotation
clusterAddon.SetStageAnnotations(csov1alpha1.StageAnnotationValueCreated)
clusterAddon.Spec.ClusterStack = cluster.Spec.Topology.Class
clusterAddon.Status.Ready = true
}
// Helm chart has been applied successfully
// clusterAddon.Spec.Version = metadata.Versions.Components.ClusterAddon
conditions.MarkTrue(clusterAddon, csov1alpha1.HelmChartAppliedCondition)
// remove the helm chart status from the status.
clusterAddon.Status.Stages = make([]csov1alpha1.StageStatus, 0)
// remove the status resource if hook is finished
clusterAddon.Status.Resources = make([]*csov1alpha1.Resource, 0)
// unset spec hook
clusterAddon.Spec.Hook = ""
return ctrl.Result{}, nil
}
func (r *ClusterAddonReconciler) getNewReleaseObjects(ctx context.Context, in *templateAndApplyClusterAddonInput, clusterAddonConfig clusteraddon.Config) ([]*csov1alpha1.Resource, error) {
var (
newBuildTemplate []byte
resources []*csov1alpha1.Resource
)
for _, stage := range clusterAddonConfig.AddonStages[in.clusterAddon.Spec.Hook] {
if _, err := os.Stat(filepath.Join(in.newDestinationClusterAddonChartDir, stage.Name, release.OverwriteYaml)); err == nil {
newBuildTemplate, err = buildTemplateFromClusterAddonValues(ctx, filepath.Join(in.newDestinationClusterAddonChartDir, stage.Name, release.OverwriteYaml), in.cluster, r.Client)
if err != nil {
return nil, fmt.Errorf("failed to build template from new cluster addon values of the latest cluster stack: %w", err)
}
}
helmTemplate, err := helmTemplateClusterAddon(filepath.Join(in.newDestinationClusterAddonChartDir, stage.Name), newBuildTemplate, in.kubernetesVersion)
if err != nil {
return nil, fmt.Errorf("failed to template new helm chart of the latest cluster stack: %w", err)
}
resource, err := kube.GetResourcesFromHelmTemplate(helmTemplate)
if err != nil {
return nil, fmt.Errorf("failed to get resources form old cluster stack helm template of the latest cluster stack: %w", err)
}
if stage.Action == clusteraddon.Apply {
resources = append(resources, resource...)
} else {
resources = removeResourcesFromCurrentListOfObjects(resources, resource)
}
}
return resources, nil
}
// getOldReleaseObjects returns the old cluster stack objects in the workload cluster.
func (r *ClusterAddonReconciler) getOldReleaseObjects(ctx context.Context, in *templateAndApplyClusterAddonInput, clusterAddonConfig clusteraddon.Config, oldRelease *release.Release) ([]*csov1alpha1.Resource, error) {
// clusteraddon.yaml
clusterAddonConfigPath, err := r.getClusterAddonConfigPath(in.clusterAddon.Spec.ClusterStack)
if err != nil {
return nil, fmt.Errorf("failed to get old cluster stack cluster addon config path: %w", err)
}
if _, err := os.Stat(clusterAddonConfigPath); err != nil {
if !os.IsNotExist(err) {
return nil, fmt.Errorf("failed to verify the clusteraddon.yaml on old cluster stack release path %q with error: %w", clusterAddonConfigPath, err)
}
// this is the old way
buildTemplate, err := buildTemplateFromClusterAddonValues(ctx, oldRelease.ClusterAddonValuesPath(), in.cluster, r.Client)
if err != nil {
return nil, fmt.Errorf("failed to build template from the old cluster stack cluster addon values: %w", err)
}
helmTemplate, err := helmTemplateClusterAddon(oldRelease.ClusterAddonChartPath(), buildTemplate, oldRelease.Meta.Versions.Kubernetes)
if err != nil {
return nil, fmt.Errorf("failed to template helm chart: %w", err)
}
resources, err := kube.GetResourcesFromHelmTemplate(helmTemplate)
if err != nil {
return nil, fmt.Errorf("failed to get resources form old cluster stack helm template: %w", err)
}
return resources, nil
}
// this is the new way
// Read all the helm charts in new the un-tared cluster addon.
var (
newBuildTemplate []byte
resources []*csov1alpha1.Resource
hook string
)
if in.clusterAddon.HasStageAnnotation(csov1alpha1.StageAnnotationValueCreated) {
hook = afterControlPlaneInitialized
} else {
hook = beforeClusterUpgradeHook
}
for _, stage := range clusterAddonConfig.AddonStages[hook] {
if _, err := os.Stat(filepath.Join(in.oldDestinationClusterAddonChartDir, stage.Name, release.OverwriteYaml)); err == nil {
newBuildTemplate, err = buildTemplateFromClusterAddonValues(ctx, filepath.Join(in.oldDestinationClusterAddonChartDir, stage.Name, release.OverwriteYaml), in.cluster, r.Client)
if err != nil {
return nil, fmt.Errorf("failed to build template from new cluster addon values: %w", err)
}
}
helmTemplate, err := helmTemplateClusterAddon(filepath.Join(in.oldDestinationClusterAddonChartDir, stage.Name), newBuildTemplate, oldRelease.Meta.Versions.Kubernetes)
if err != nil {
return nil, fmt.Errorf("failed to template new helm chart: %w", err)
}
resource, err := kube.GetResourcesFromHelmTemplate(helmTemplate)
if err != nil {
return nil, fmt.Errorf("failed to get resources form old cluster stack helm template: %w", err)
}
if stage.Action == clusteraddon.Apply {
resources = append(resources, resource...)
} else {
resources = removeResourcesFromCurrentListOfObjects(resources, resource)
}
}
return resources, nil
}
func cleanUpResources(ctx context.Context, in *templateAndApplyClusterAddonInput, oldList, newList []*csov1alpha1.Resource) (shouldRequeue bool, err error) {
// Create a map of items in the new slice for faster lookup
newMap := make(map[csov1alpha1.Resource]bool)
for i := range newList {
newMap[*newList[i]] = true
}
// Find extra objects in the old slice
var extraResources []csov1alpha1.Resource
for i, item := range oldList {
if !newMap[*item] {
extraResources = append(extraResources, *oldList[i])
}
}
for _, resource := range extraResources {
if resource.Namespace == "" {
resource.Namespace = clusterAddonNamespace
}
dr, err := kube.GetDynamicResourceInterface(resource.Namespace, in.restConfig, resource.GroupVersionKind())
if err != nil {
return false, fmt.Errorf("failed to get dynamic resource interface: %w", err)
}
if err := dr.Delete(ctx, resource.Name, metav1.DeleteOptions{}); err != nil && !apierrors.IsNotFound(err) {
reterr := fmt.Errorf("failed to delete object %q: %w", resource.GroupVersionKind(), err)
resource.Error = reterr.Error()
shouldRequeue = true
}
}
return shouldRequeue, nil
}
func (r *ClusterAddonReconciler) getClusterAddonConfigPath(clusterClassName string) (string, error) {
// path to the clusteraddon config /tmp/cluster-stacks/docker-ferrol-1-27-v1/clusteraddon.yaml
// if present then new way of cluster stack otherwise old way.
clusterAddonConfigPath := filepath.Join(r.ReleaseDirectory, release.ClusterStackSuffix, release.ConvertFromClusterClassToClusterStackFormat(clusterClassName), release.ClusterAddonYamlName)
if _, err := os.Stat(clusterAddonConfigPath); err != nil {
if !os.IsNotExist(err) {
return "", fmt.Errorf("failed to verify the clusteraddon.yaml path %s with error: %w", clusterAddonConfigPath, err)
}
return "", nil
}
return clusterAddonConfigPath, nil
}
type templateAndApplyClusterAddonInput struct {
clusterAddonChartPath string
// cluster-addon-values.yaml
clusterAddonValuesPath string
// clusteraddon.yaml
clusterAddonConfigPath string
clusterAddon *csov1alpha1.ClusterAddon
kubernetesVersion string
oldKubernetesVersion string
cluster *clusterv1.Cluster
restConfig *rest.Config
addonStagesInput
}
type addonStagesInput struct {
kubeClient kube.Client
dynamicClient *dynamic.DynamicClient
discoverClient *discovery.DiscoveryClient
chartMap map[string]os.DirEntry
newDestinationClusterAddonChartDir string
oldDestinationClusterAddonChartDir string
}
func (r *ClusterAddonReconciler) getAddonStagesInput(restConfig *rest.Config, clusterAddonChart string) (addonStagesInput, error) {
var (
addonStages addonStagesInput
err error
)
addonStages.kubeClient = r.KubeClientFactory.NewClient(clusterAddonNamespace, restConfig)
addonStages.dynamicClient, err = dynamic.NewForConfig(restConfig)
if err != nil {
return addonStagesInput{}, fmt.Errorf("failed to build dynamic client from restConfig: %w", err)
}
addonStages.discoverClient, err = discovery.NewDiscoveryClientForConfig(restConfig)
if err != nil {
return addonStagesInput{}, fmt.Errorf("error creating discovery client: %w", err)
}
// src - /tmp/cluster-stacks/docker-ferrol1-27-v1/docker-ferrol-27-cluster-addon-v1.tgz
// dst - /tmp/cluster-stacks/docker-ferrol-1-27-v1/docker-ferrol-1-27-cluster-addon-v1/
addonStages.newDestinationClusterAddonChartDir = strings.TrimSuffix(clusterAddonChart, ".tgz")
if err := unTarContent(clusterAddonChart, addonStages.newDestinationClusterAddonChartDir); err != nil {
return addonStagesInput{}, fmt.Errorf("failed to untar new cluster stack cluster addon chart: %q: %w", clusterAddonChart, err)
}
// Read all the helm charts in the un-tared cluster addon.
subDirs, err := os.ReadDir(addonStages.newDestinationClusterAddonChartDir)
if err != nil {
return addonStagesInput{}, fmt.Errorf("failed to read directories inside: %q: %w", addonStages.newDestinationClusterAddonChartDir, err)
}
// Create a map for faster lookup
chartMap := make(map[string]os.DirEntry)
for _, subDir := range subDirs {
chartMap[subDir.Name()] = subDir
}
addonStages.chartMap = chartMap
return addonStages, nil
}
func (r *ClusterAddonReconciler) templateAndApplyClusterAddonHelmChart(ctx context.Context, in *templateAndApplyClusterAddonInput) (bool, error) {
clusterAddonChart := in.clusterAddonChartPath
var shouldRequeue bool
buildTemplate, err := buildTemplateFromClusterAddonValues(ctx, in.clusterAddonValuesPath, in.cluster, r.Client)
if err != nil {
return false, fmt.Errorf("failed to build template from cluster addon values: %w", err)
}
helmTemplate, err := helmTemplateClusterAddon(clusterAddonChart, buildTemplate, in.kubernetesVersion)
if err != nil {
return false, fmt.Errorf("failed to template helm chart: %w", err)
}
kubeClient := r.KubeClientFactory.NewClient(clusterAddonNamespace, in.restConfig)
newResources, shouldRequeue, err := kubeClient.Apply(ctx, helmTemplate, in.clusterAddon.Status.Resources)
if err != nil {
return false, fmt.Errorf("failed to apply objects from cluster addon Helm chart: %w", err)
}
in.clusterAddon.Status.Resources = newResources
return shouldRequeue, nil
}
func (r *ClusterAddonReconciler) executeStage(ctx context.Context, stage *clusteraddon.Stage, in *templateAndApplyClusterAddonInput) (bool, error) {
logger := log.FromContext(ctx)
_, exists := in.chartMap[stage.Name]
if !exists {
// do not reconcile by returning error, just create an event.
conditions.MarkFalse(
in.clusterAddon,
csov1alpha1.HelmChartFoundCondition,
csov1alpha1.HelmChartMissingReason,
clusterv1.ConditionSeverityInfo,
"helm chart name doesn't exists in the cluster addon helm chart: %q",
stage.Name,
)
return false, nil
}
check:
switch in.clusterAddon.GetStagePhase(stage.Name, stage.Action) {
case csov1alpha1.StagePhasePending, csov1alpha1.StagePhaseWaitingForPreCondition:
// If WaitForPreCondition is mentioned.
if !reflect.DeepEqual(stage.WaitForPreCondition, clusteraddon.WaitForCondition{}) {
// Evaluate the condition.
logger.V(1).Info("starting to evaluate pre condition", "clusterStack", in.clusterAddon.Spec.ClusterStack, "name", stage.Name, "hook", in.clusterAddon.Spec.Hook)
if err := getDynamicResourceAndEvaluateCEL(ctx, in.dynamicClient, in.discoverClient, stage.WaitForPreCondition); err != nil {
if errors.Is(err, clusteraddon.ErrConditionNotMatch) {
conditions.MarkFalse(
in.clusterAddon,
csov1alpha1.EvaluatedCELCondition,
csov1alpha1.FailedToEvaluatePreConditionReason,
clusterv1.ConditionSeverityInfo,
"failed to successfully evaluate pre condition: %q: %s", stage.Name, err.Error(),
)
in.clusterAddon.SetStagePhase(stage.Name, stage.Action, csov1alpha1.StagePhaseWaitingForPreCondition)
return true, nil
}
return false, fmt.Errorf("failed to get dynamic resource and evaluate cel expression for pre condition: %w", err)
}
conditions.Delete(in.clusterAddon, csov1alpha1.EvaluatedCELCondition)
logger.V(1).Info("finished evaluating pre condition", "clusterStack", in.clusterAddon.Spec.ClusterStack, "name", stage.Name, "hook", in.clusterAddon.Spec.Hook)
}
in.clusterAddon.SetStagePhase(stage.Name, stage.Action, csov1alpha1.StagePhaseApplyingOrDeleting)
goto check
case csov1alpha1.StagePhaseApplyingOrDeleting:
if stage.Action == clusteraddon.Apply {
logger.V(1).Info("starting to template helm chart", "clusterStack", in.clusterAddon.Spec.ClusterStack, "name", stage.Name, "hook", in.clusterAddon.Spec.Hook)
shouldReturn, oldTemplate, newTemplate, err := r.templateNewClusterStackAddonHelmChart(ctx, in, stage.Name)
if err != nil {
return false, fmt.Errorf("failed to helm template: %w", err)
}
if shouldReturn {
return false, nil
}
logger.V(1).Info("finished templating helm chart and starting to apply helm chart", "clusterStack", in.clusterAddon.Spec.ClusterStack, "name", stage.Name, "hook", in.clusterAddon.Spec.Hook)
newResources, shouldRequeue, err := in.kubeClient.ApplyNewClusterStack(ctx, oldTemplate, newTemplate)
if err != nil {
conditions.MarkFalse(
in.clusterAddon,
csov1alpha1.HelmChartAppliedCondition,
csov1alpha1.FailedToApplyObjectsReason,
clusterv1.ConditionSeverityInfo,
"failed to successfully apply helm chart: %q: %s", stage.Name, err.Error(),
)
return false, fmt.Errorf("failed to apply objects from cluster addon Helm chart: %w", err)
}
if shouldRequeue {
conditions.MarkFalse(
in.clusterAddon,
csov1alpha1.HelmChartAppliedCondition,
csov1alpha1.FailedToApplyObjectsReason,
clusterv1.ConditionSeverityInfo,
"failed to successfully apply helm chart: %q", stage.Name,
)
return true, nil
}
// This is for the current stage objects and will be removed once done.
in.clusterAddon.Status.Resources = newResources
logger.V(1).Info("finished applying helm chart", "clusterStack", in.clusterAddon.Spec.ClusterStack, "name", stage.Name, "hook", in.clusterAddon.Spec.Hook)
// delete the false condition with failed to apply reason
conditions.Delete(in.clusterAddon, csov1alpha1.HelmChartAppliedCondition)
// remove status resource if applied successfully
in.clusterAddon.Status.Resources = make([]*csov1alpha1.Resource, 0)
in.clusterAddon.SetStagePhase(stage.Name, stage.Action, csov1alpha1.StagePhaseWaitingForPostCondition)
goto check
} else {
// Delete part
logger.V(1).Info("starting to template helm chart", "clusterStack", in.clusterAddon.Spec.ClusterStack, "name", stage.Name, "hook", in.clusterAddon.Spec.Hook)
helmTemplate, err := helmTemplateNewClusterStack(in, stage.Name)
if err != nil {
conditions.MarkFalse(
in.clusterAddon,
csov1alpha1.HelmChartTemplatedCondition,
csov1alpha1.TemplateNewClusterStackFailedReason,
clusterv1.ConditionSeverityError,
"failed to template new helm chart: %s", err.Error(),
)
return false, nil
}
logger.V(1).Info("finished templating helm chart and starting to delete helm chart", "clusterStack", in.clusterAddon.Spec.ClusterStack, "name", stage.Name, "hook", in.clusterAddon.Spec.Hook)
deletedResources, shouldRequeue, err := in.kubeClient.DeleteNewClusterStack(ctx, helmTemplate)
if err != nil {
conditions.MarkFalse(
in.clusterAddon,
csov1alpha1.HelmChartDeletedCondition,
csov1alpha1.FailedToDeleteObjectsReason,
clusterv1.ConditionSeverityInfo,
"failed to successfully delete helm chart: %q", stage.Name,
)
return false, fmt.Errorf("failed to delete objects from cluster addon Helm chart: %w", err)
}
if shouldRequeue {
return true, nil
}
// This is for the current stage objects and will be removed once done.
in.clusterAddon.Status.Resources = deletedResources
logger.V(1).Info("finished deleting helm chart", "clusterStack", in.clusterAddon.Spec.ClusterStack, "name", stage.Name, "hook", in.clusterAddon.Spec.Hook)
// remove status resource if deleted successfully
in.clusterAddon.Status.Resources = make([]*csov1alpha1.Resource, 0)
// delete the false condition with failed to apply reason
conditions.Delete(in.clusterAddon, csov1alpha1.HelmChartDeletedCondition)
in.clusterAddon.SetStagePhase(stage.Name, stage.Action, csov1alpha1.StagePhaseWaitingForPostCondition)
goto check
}
case csov1alpha1.StagePhaseWaitingForPostCondition:
// If WaitForPostCondition is mentioned.
if !reflect.DeepEqual(stage.WaitForPostCondition, clusteraddon.WaitForCondition{}) {
// Evaluate the condition.
logger.V(1).Info("starting to evaluate post condition", "clusterStack", in.clusterAddon.Spec.ClusterStack, "name", stage.Name, "hook", in.clusterAddon.Spec.Hook)
if err := getDynamicResourceAndEvaluateCEL(ctx, in.dynamicClient, in.discoverClient, stage.WaitForPostCondition); err != nil {
if errors.Is(err, clusteraddon.ErrConditionNotMatch) {
conditions.MarkFalse(
in.clusterAddon,
csov1alpha1.EvaluatedCELCondition,
csov1alpha1.FailedToEvaluatePostConditionReason,
clusterv1.ConditionSeverityInfo,
"failed to successfully evaluate post condition: %q: %s", stage.Name, err.Error(),
)
return true, nil
}
return false, fmt.Errorf("failed to get dynamic resource and evaluate cel expression for post condition: %w", err)
}
conditions.Delete(in.clusterAddon, csov1alpha1.EvaluatedCELCondition)
logger.V(1).Info("finished evaluating post condition", "clusterStack", in.clusterAddon.Spec.ClusterStack, "name", stage.Name, "hook", in.clusterAddon.Spec.Hook)
}
in.clusterAddon.SetStagePhase(stage.Name, stage.Action, csov1alpha1.StagePhaseDone)
}
return false, nil
}
// downloadOldClusterStackRelease downloads the old cluster stack if not present and returns release clusterAddon chart path if requeue and error.
func (r *ClusterAddonReconciler) downloadOldClusterStackRelease(ctx context.Context, clusterAddon *csov1alpha1.ClusterAddon) (*release.Release, bool, error) {
// initiate assets client.
gc, err := r.AssetsClientFactory.NewClient(ctx)
if err != nil {
isSet := conditions.IsFalse(clusterAddon, csov1alpha1.AssetsClientAPIAvailableCondition)
conditions.MarkFalse(clusterAddon,
csov1alpha1.AssetsClientAPIAvailableCondition,
csov1alpha1.FailedCreateAssetsClientReason,
clusterv1.ConditionSeverityError,
"%s", err.Error(),
)
record.Warn(clusterAddon, "FailedCreateAssetsClient", err.Error())
// give the assets client a second change
if isSet {
return nil, true, nil
}
return nil, false, nil
}
conditions.MarkTrue(clusterAddon, csov1alpha1.AssetsClientAPIAvailableCondition)
// check if old cluster stack release is present or not.
releaseAsset, download, err := release.New(release.ConvertFromClusterClassToClusterStackFormat(clusterAddon.Spec.ClusterStack), r.ReleaseDirectory)
if err != nil {
conditions.MarkFalse(clusterAddon,
csov1alpha1.ClusterStackReleaseAssetsReadyCondition,
csov1alpha1.IssueWithReleaseAssetsReason,
clusterv1.ConditionSeverityError, "%s", err.Error())
return nil, true, nil
}
if download {
// if download is true, it means that the release assets have not been downloaded yet
conditions.MarkFalse(clusterAddon, csov1alpha1.ClusterStackReleaseAssetsReadyCondition, csov1alpha1.ReleaseAssetsNotDownloadedYetReason, clusterv1.ConditionSeverityInfo, "assets not downloaded yet")
// this is the point where we download the release.
// acquire lock so that only one reconcile loop can download the release
r.clusterStackRelDownloadDirectoryMutex.Lock()
if err := downloadReleaseAssets(ctx, release.ConvertFromClusterClassToClusterStackFormat(clusterAddon.Spec.ClusterStack), releaseAsset.LocalDownloadPath, gc); err != nil {
return nil, false, fmt.Errorf("failed to download release assets: %w", err)
}
r.clusterStackRelDownloadDirectoryMutex.Unlock()
// requeue to make sure release assets can be accessed
return nil, true, nil
}
if err := releaseAsset.CheckHelmCharts(); err != nil {
msg := fmt.Sprintf("failed to validate helm charts: %s", err.Error())
conditions.MarkFalse(
clusterAddon,
csov1alpha1.ClusterStackReleaseAssetsReadyCondition,
csov1alpha1.IssueWithReleaseAssetsReason,
clusterv1.ConditionSeverityError,
"%s", msg,
)
record.Warn(clusterAddon, "ValidateHelmChartFailed", msg)
return nil, false, nil
}