-
Notifications
You must be signed in to change notification settings - Fork 453
/
operation.go
641 lines (562 loc) · 24.3 KB
/
operation.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
// Copyright (c) 2018 SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under the Apache Software License, v. 2 except as noted otherwise in the LICENSE file
//
// 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 operation
import (
"context"
"crypto/x509"
"fmt"
"net"
"strings"
gardencorev1alpha1 "github.com/gardener/gardener/pkg/apis/core/v1alpha1"
gardencorev1alpha1helper "github.com/gardener/gardener/pkg/apis/core/v1alpha1/helper"
gardencorev1beta1 "github.com/gardener/gardener/pkg/apis/core/v1beta1"
v1beta1constants "github.com/gardener/gardener/pkg/apis/core/v1beta1/constants"
gardencorev1beta1helper "github.com/gardener/gardener/pkg/apis/core/v1beta1/helper"
extensionsv1alpha1 "github.com/gardener/gardener/pkg/apis/extensions/v1alpha1"
"github.com/gardener/gardener/pkg/chartrenderer"
gardencoreinformers "github.com/gardener/gardener/pkg/client/core/informers/externalversions/core/v1beta1"
"github.com/gardener/gardener/pkg/client/kubernetes"
"github.com/gardener/gardener/pkg/gardenlet/apis/config"
"github.com/gardener/gardener/pkg/operation/common"
"github.com/gardener/gardener/pkg/operation/etcdencryption"
"github.com/gardener/gardener/pkg/operation/garden"
"github.com/gardener/gardener/pkg/operation/seed"
"github.com/gardener/gardener/pkg/operation/shoot"
shootpkg "github.com/gardener/gardener/pkg/operation/shoot"
"github.com/gardener/gardener/pkg/utils"
"github.com/gardener/gardener/pkg/utils/chart"
"github.com/gardener/gardener/pkg/utils/flow"
"github.com/gardener/gardener/pkg/utils/imagevector"
kutil "github.com/gardener/gardener/pkg/utils/kubernetes"
"github.com/gardener/gardener/pkg/utils/secrets"
prometheusapi "github.com/prometheus/client_golang/api"
prometheusclient "github.com/prometheus/client_golang/api/prometheus/v1"
"github.com/sirupsen/logrus"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/util/retry"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
)
// NewBuilder returns a new Builder.
func NewBuilder() *Builder {
return &Builder{
configFunc: func() (*config.GardenletConfiguration, error) {
return nil, fmt.Errorf("config is required but not set")
},
gardenFunc: func(map[string]*corev1.Secret) (*garden.Garden, error) {
return nil, fmt.Errorf("garden object is required but not set")
},
gardenerInfoFunc: func() (*gardencorev1beta1.Gardener, error) {
return nil, fmt.Errorf("gardener info is required but not set")
},
imageVectorFunc: func() (imagevector.ImageVector, error) {
return nil, fmt.Errorf("image vector is required but not set")
},
loggerFunc: func() (*logrus.Entry, error) {
return nil, fmt.Errorf("logger is required but not set")
},
secretsFunc: func() (map[string]*corev1.Secret, error) {
return nil, fmt.Errorf("secrets map is required but not set")
},
seedFunc: func(context.Context, client.Client) (*seed.Seed, error) {
return nil, fmt.Errorf("seed object is required but not set")
},
shootFunc: func(context.Context, client.Client, *garden.Garden, *seed.Seed) (*shoot.Shoot, error) {
return nil, fmt.Errorf("shoot object is required but not set")
},
chartsRootPathFunc: func() string {
return common.ChartPath
},
}
}
// WithConfig sets the configFunc attribute at the Builder.
func (b *Builder) WithConfig(cfg *config.GardenletConfiguration) *Builder {
b.configFunc = func() (*config.GardenletConfiguration, error) { return cfg, nil }
return b
}
// WithGarden sets the gardenFunc attribute at the Builder.
func (b *Builder) WithGarden(g *garden.Garden) *Builder {
b.gardenFunc = func(_ map[string]*corev1.Secret) (*garden.Garden, error) { return g, nil }
return b
}
// WithGardenFrom sets the gardenFunc attribute at the Builder which will build a new Garden object.
func (b *Builder) WithGardenFrom(k8sGardenCoreInformers gardencoreinformers.Interface, namespace string) *Builder {
b.gardenFunc = func(secrets map[string]*corev1.Secret) (*garden.Garden, error) {
return garden.
NewBuilder().
WithProjectFromLister(k8sGardenCoreInformers.Projects().Lister(), namespace).
WithInternalDomainFromSecrets(secrets).
WithDefaultDomainsFromSecrets(secrets).
Build()
}
return b
}
// WithGardenerInfo sets the gardenerInfoFunc attribute at the Builder.
func (b *Builder) WithGardenerInfo(gardenerInfo *gardencorev1beta1.Gardener) *Builder {
b.gardenerInfoFunc = func() (*gardencorev1beta1.Gardener, error) { return gardenerInfo, nil }
return b
}
// WithImageVector sets the imageVectorFunc attribute at the Builder.
func (b *Builder) WithImageVector(imageVector imagevector.ImageVector) *Builder {
b.imageVectorFunc = func() (imagevector.ImageVector, error) { return imageVector, nil }
return b
}
// WithLogger sets the loggerFunc attribute at the Builder.
func (b *Builder) WithLogger(logger *logrus.Entry) *Builder {
b.loggerFunc = func() (*logrus.Entry, error) { return logger, nil }
return b
}
// WithSecrets sets the secretsFunc attribute at the Builder.
func (b *Builder) WithSecrets(secrets map[string]*corev1.Secret) *Builder {
b.secretsFunc = func() (map[string]*corev1.Secret, error) { return secrets, nil }
return b
}
// WithSeed sets the seedFunc attribute at the Builder.
func (b *Builder) WithSeed(s *seed.Seed) *Builder {
b.seedFunc = func(_ context.Context, _ client.Client) (*seed.Seed, error) { return s, nil }
return b
}
// WithSeedFrom sets the seedFunc attribute at the Builder which will build a new Seed object.
func (b *Builder) WithSeedFrom(k8sGardenCoreInformers gardencoreinformers.Interface, seedName string) *Builder {
b.seedFunc = func(ctx context.Context, c client.Client) (*seed.Seed, error) {
return seed.
NewBuilder().
WithSeedObjectFromLister(k8sGardenCoreInformers.Seeds().Lister(), seedName).
WithSeedSecretFromClient(context.TODO(), c).
Build()
}
return b
}
// WithShoot sets the shootFunc attribute at the Builder.
func (b *Builder) WithShoot(s *shoot.Shoot) *Builder {
b.shootFunc = func(_ context.Context, _ client.Client, _ *garden.Garden, _ *seed.Seed) (*shoot.Shoot, error) {
return s, nil
}
return b
}
// WithChartsRootPath sets the ChartsRootPath attribute at the Builder.
// Mainly used for testing. Optional.
func (b *Builder) WithChartsRootPath(chartsRootPath string) *Builder {
b.chartsRootPathFunc = func() string { return chartsRootPath }
return b
}
// WithShootFrom sets the shootFunc attribute at the Builder which will build a new Shoot object.
func (b *Builder) WithShootFrom(k8sGardenCoreInformers gardencoreinformers.Interface, s *gardencorev1beta1.Shoot) *Builder {
b.shootFunc = func(ctx context.Context, c client.Client, gardenObj *garden.Garden, seedObj *seed.Seed) (*shoot.Shoot, error) {
return shootpkg.
NewBuilder().
WithShootObject(s).
WithCloudProfileObjectFromLister(k8sGardenCoreInformers.CloudProfiles().Lister()).
WithShootSecretFromSecretBindingLister(k8sGardenCoreInformers.SecretBindings().Lister()).
WithProjectName(gardenObj.Project.Name).
WithDisableDNS(!seedObj.Info.Spec.Settings.ShootDNS.Enabled).
WithInternalDomain(gardenObj.InternalDomain).
WithDefaultDomains(gardenObj.DefaultDomains).
Build(ctx, c)
}
return b
}
// Build initializes a new Operation object.
func (b *Builder) Build(ctx context.Context, k8sGardenClient kubernetes.Interface) (*Operation, error) {
operation := &Operation{
K8sGardenClient: k8sGardenClient,
CheckSums: make(map[string]string),
}
config, err := b.configFunc()
if err != nil {
return nil, err
}
operation.Config = config
secretsMap, err := b.secretsFunc()
if err != nil {
return nil, err
}
secrets := make(map[string]*corev1.Secret)
for k, v := range secretsMap {
secrets[k] = v
}
operation.Secrets = secrets
garden, err := b.gardenFunc(secrets)
if err != nil {
return nil, err
}
operation.Garden = garden
gardenerInfo, err := b.gardenerInfoFunc()
if err != nil {
return nil, err
}
operation.GardenerInfo = gardenerInfo
imageVector, err := b.imageVectorFunc()
if err != nil {
return nil, err
}
operation.ImageVector = imageVector
logger, err := b.loggerFunc()
if err != nil {
return nil, err
}
operation.Logger = logger
seed, err := b.seedFunc(ctx, k8sGardenClient.Client())
if err != nil {
return nil, err
}
operation.Seed = seed
shoot, err := b.shootFunc(ctx, k8sGardenClient.Client(), garden, seed)
if err != nil {
return nil, err
}
operation.Shoot = shoot
shootedSeed, err := gardencorev1beta1helper.ReadShootedSeed(shoot.Info)
if err != nil {
logger.Warnf("Cannot use shoot %s/%s as shooted seed: %+v", shoot.Info.Namespace, shoot.Info.Name, err)
} else {
operation.ShootedSeed = shootedSeed
}
operation.ChartsRootPath = b.chartsRootPathFunc()
return operation, nil
}
// InitializeSeedClients will use the Garden Kubernetes client to read the Seed Secret in the Garden
// cluster which contains a Kubeconfig that can be used to authenticate against the Seed cluster. With it,
// a Kubernetes client as well as a Chart renderer for the Seed cluster will be initialized and attached to
// the already existing Operation object.
func (o *Operation) InitializeSeedClients() error {
if o.K8sSeedClient != nil && o.ChartApplierSeed != nil {
return nil
}
k8sSeedClient, err := seed.GetSeedClient(context.TODO(), o.K8sGardenClient.Client(), o.Config.SeedClientConnection.ClientConnectionConfiguration, o.Config.SeedSelector == nil, o.Seed.Info.Name)
if err != nil {
return err
}
o.K8sSeedClient = k8sSeedClient
renderer, err := chartrenderer.NewForConfig(k8sSeedClient.RESTConfig())
if err != nil {
return err
}
applier, err := kubernetes.NewApplierForConfig(k8sSeedClient.RESTConfig())
if err != nil {
return err
}
o.ChartApplierSeed = kubernetes.NewChartApplier(renderer, applier)
return nil
}
// InitializeShootClients will use the Seed Kubernetes client to read the gardener Secret in the Seed
// cluster which contains a Kubeconfig that can be used to authenticate against the Shoot cluster. With it,
// a Kubernetes client as well as a Chart renderer for the Shoot cluster will be initialized and attached to
// the already existing Operation object.
func (o *Operation) InitializeShootClients() error {
if o.K8sShootClient != nil && o.ChartApplierShoot != nil {
return nil
}
if o.Shoot.HibernationEnabled {
controlPlaneHibernated, err := o.controlPlaneHibernated()
if err != nil {
return err
}
// Do not initialize Shoot clients for already hibernated shoots.
if controlPlaneHibernated {
return nil
}
}
secretName := v1beta1constants.SecretNameGardener
// If the gardenlet runs in the same cluster like the API server of the shoot then use the internal kubeconfig
// and communicate internally. Otherwise, fall back to the "external" kubeconfig and communicate via the
// load balancer of the shoot API server.
addr, err := net.LookupHost(o.Shoot.ComputeInClusterAPIServerAddress(false))
if err != nil {
o.Logger.Warnf("service DNS name lookup of kube-apiserver failed (%+v), falling back to external kubeconfig", err)
} else if len(addr) > 0 {
secretName = v1beta1constants.SecretNameGardenerInternal
}
k8sShootClient, err := kubernetes.NewClientFromSecret(o.K8sSeedClient, o.Shoot.SeedNamespace, secretName,
kubernetes.WithClientConnectionOptions(o.Config.ShootClientConnection.ClientConnectionConfiguration),
kubernetes.WithClientOptions(client.Options{
Scheme: kubernetes.ShootScheme,
}),
)
// TODO: This if-condition can be removed in a future version when all shoots were reconciled with Gardener v1.1 version.
if secretName == v1beta1constants.SecretNameGardenerInternal && err != nil && apierrors.IsNotFound(err) {
k8sShootClient, err = kubernetes.NewClientFromSecret(o.K8sSeedClient, o.Shoot.SeedNamespace, v1beta1constants.SecretNameGardener,
kubernetes.WithClientConnectionOptions(o.Config.ShootClientConnection.ClientConnectionConfiguration),
kubernetes.WithClientOptions(client.Options{
Scheme: kubernetes.ShootScheme,
}),
)
}
if err != nil {
return err
}
o.K8sShootClient = k8sShootClient
renderer, err := chartrenderer.NewForConfig(k8sShootClient.RESTConfig())
if err != nil {
return err
}
applier, err := kubernetes.NewApplierForConfig(k8sShootClient.RESTConfig())
if err != nil {
return err
}
o.ChartApplierShoot = kubernetes.NewChartApplier(renderer, applier)
return nil
}
func (o *Operation) controlPlaneHibernated() (bool, error) {
replicaCount, err := common.CurrentReplicaCount(o.K8sSeedClient.Client(), o.Shoot.SeedNamespace, v1beta1constants.DeploymentNameKubeAPIServer)
if err != nil {
return false, err
}
if replicaCount > 0 {
return false, nil
}
return true, nil
}
// InitializeMonitoringClient will read the Prometheus ingress auth and tls
// secrets from the Seed cluster, which are containing the cert to secure
// the connection and the credentials authenticate against the Shoot Prometheus.
// With those certs and credentials, a Prometheus client API will be created
// and attached to the existing Operation object.
func (o *Operation) InitializeMonitoringClient() error {
if o.MonitoringClient != nil {
return nil
}
// Read the CA.
tlsSecret := &corev1.Secret{}
if err := o.K8sSeedClient.Client().Get(context.TODO(), kutil.Key(o.Shoot.SeedNamespace, common.PrometheusTLS), tlsSecret); err != nil {
return err
}
ca := x509.NewCertPool()
ca.AppendCertsFromPEM(tlsSecret.Data[secrets.DataKeyCertificateCA])
// Read the basic auth credentials.
credentials := &corev1.Secret{}
if err := o.K8sSeedClient.Client().Get(context.TODO(), kutil.Key(o.Shoot.SeedNamespace, "monitoring-ingress-credentials"), credentials); err != nil {
return err
}
config := prometheusapi.Config{
Address: fmt.Sprintf("https://%s", o.ComputeIngressHost("p")),
RoundTripper: &prometheusRoundTripper{
authHeader: fmt.Sprintf("Basic %s", utils.EncodeBase64([]byte(fmt.Sprintf("%s:%s", credentials.Data[secrets.DataKeyUserName], credentials.Data[secrets.DataKeyPassword])))),
ca: ca,
},
}
client, err := prometheusapi.NewClient(config)
if err != nil {
return err
}
o.MonitoringClient = prometheusclient.NewAPI(client)
return nil
}
// GetSecretKeysOfRole returns a list of keys which are present in the Garden Secrets map and which
// are prefixed with <kind>.
func (o *Operation) GetSecretKeysOfRole(kind string) []string {
return common.GetSecretKeysWithPrefix(kind, o.Secrets)
}
func makeDescription(stats *flow.Stats) string {
if stats.ProgressPercent() == 100 {
return "Execution finished"
}
return strings.Join(stats.Running.StringList(), ", ")
}
// ReportShootProgress will update the last operation object in the Shoot manifest `status` section
// by the current progress of the Flow execution.
func (o *Operation) ReportShootProgress(ctx context.Context, stats *flow.Stats) {
var (
description = makeDescription(stats)
progress = stats.ProgressPercent()
lastUpdateTime = metav1.Now()
)
newShoot, err := kutil.TryUpdateShootStatus(o.K8sGardenClient.GardenCore(), retry.DefaultRetry, o.Shoot.Info.ObjectMeta,
func(shoot *gardencorev1beta1.Shoot) (*gardencorev1beta1.Shoot, error) {
if shoot.Status.LastOperation == nil {
return nil, fmt.Errorf("last operation of Shoot %s/%s is unset", shoot.Namespace, shoot.Name)
}
if shoot.Status.LastOperation.LastUpdateTime.After(lastUpdateTime.Time) {
return nil, fmt.Errorf("last operation of Shoot %s/%s was updated mid-air", shoot.Namespace, shoot.Name)
}
shoot.Status.LastOperation.Description = description
shoot.Status.LastOperation.Progress = progress
shoot.Status.LastOperation.LastUpdateTime = lastUpdateTime
return shoot, nil
})
if err != nil {
o.Logger.Errorf("Could not report shoot progress: %v", err)
return
}
o.Shoot.Info = newShoot
}
// CleanShootTaskError removes the error with taskID from the Shoot's status.LastErrors array.
// If the status.LastErrors array is empty then status.LastError is also removed.
func (o *Operation) CleanShootTaskError(_ context.Context, taskID string) {
newShoot, err := kutil.TryUpdateShootStatus(o.K8sGardenClient.GardenCore(), retry.DefaultRetry, o.Shoot.Info.ObjectMeta,
func(shoot *gardencorev1beta1.Shoot) (*gardencorev1beta1.Shoot, error) {
shoot.Status.LastErrors = gardencorev1beta1helper.DeleteLastErrorByTaskID(o.Shoot.Info.Status.LastErrors, taskID)
return shoot, nil
},
)
if err != nil {
o.Logger.Errorf("Could not report shoot progress: %v", err)
return
}
o.Shoot.Info = newShoot
}
// SeedVersion is a shorthand for the kubernetes version of the K8sSeedClient.
func (o *Operation) SeedVersion() string {
return o.K8sSeedClient.Version()
}
// ShootVersion is a shorthand for the desired kubernetes version of the operation's shoot.
func (o *Operation) ShootVersion() string {
return o.Shoot.Info.Spec.Kubernetes.Version
}
// InjectSeedSeedImages injects images that shall run on the Seed and target the Seed's Kubernetes version.
func (o *Operation) InjectSeedSeedImages(values map[string]interface{}, names ...string) (map[string]interface{}, error) {
return chart.InjectImages(values, o.ImageVector, names, imagevector.RuntimeVersion(o.SeedVersion()), imagevector.TargetVersion(o.SeedVersion()))
}
// InjectSeedShootImages injects images that shall run on the Seed but target the Shoot's Kubernetes version.
func (o *Operation) InjectSeedShootImages(values map[string]interface{}, names ...string) (map[string]interface{}, error) {
return chart.InjectImages(values, o.ImageVector, names, imagevector.RuntimeVersion(o.SeedVersion()), imagevector.TargetVersion(o.ShootVersion()))
}
// InjectShootShootImages injects images that shall run on the Shoot and target the Shoot's Kubernetes version.
func (o *Operation) InjectShootShootImages(values map[string]interface{}, names ...string) (map[string]interface{}, error) {
return chart.InjectImages(values, o.ImageVector, names, imagevector.RuntimeVersion(o.ShootVersion()), imagevector.TargetVersion(o.ShootVersion()))
}
// EnsureShootStateExists creates the ShootState resource for the corresponding shoot and sets its ownerReferences to the Shoot.
func (o *Operation) EnsureShootStateExists(ctx context.Context) error {
shootState := &gardencorev1alpha1.ShootState{
ObjectMeta: metav1.ObjectMeta{
Name: o.Shoot.Info.Name,
Namespace: o.Shoot.Info.Namespace,
},
}
ownerReference := metav1.NewControllerRef(o.Shoot.Info, gardencorev1beta1.SchemeGroupVersion.WithKind("Shoot"))
blockOwnerDeletion := false
ownerReference.BlockOwnerDeletion = &blockOwnerDeletion
_, err := controllerutil.CreateOrUpdate(ctx, o.K8sGardenClient.Client(), shootState, func() error {
shootState.OwnerReferences = []metav1.OwnerReference{*ownerReference}
return nil
})
if err != nil {
return err
}
o.ShootState = shootState
gardenerResourceList := gardencorev1alpha1helper.GardenerResourceDataList(shootState.Spec.Gardener)
o.Shoot.ETCDEncryption, err = etcdencryption.GetEncryptionConfig(gardenerResourceList)
return err
}
// DeleteClusterResourceFromSeed deletes the `Cluster` extension resource for the shoot in the seed cluster.
func (o *Operation) DeleteClusterResourceFromSeed(ctx context.Context) error {
if err := o.InitializeSeedClients(); err != nil {
o.Logger.Errorf("Could not initialize a new Kubernetes client for the seed cluster: %s", err.Error())
return err
}
return client.IgnoreNotFound(o.K8sSeedClient.Client().Delete(ctx, &extensionsv1alpha1.Cluster{ObjectMeta: metav1.ObjectMeta{Name: o.Shoot.SeedNamespace}}))
}
// SwitchBackupEntryToTargetSeed changes the BackupEntry in the Garden cluster to the Target Seed and removes it from the Source Seed
func (o *Operation) SwitchBackupEntryToTargetSeed(ctx context.Context) error {
var (
name = common.GenerateBackupEntryName(o.Shoot.Info.Status.TechnicalID, o.Shoot.Info.Status.UID)
gardenBackupEntry = &gardencorev1beta1.BackupEntry{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: o.Shoot.Info.Namespace,
},
}
)
return kutil.TryUpdate(ctx, retry.DefaultBackoff, o.K8sGardenClient.Client(), gardenBackupEntry, func() error {
gardenBackupEntry.Spec.SeedName = o.Shoot.Info.Spec.SeedName
return nil
})
}
// ComputeGrafanaHosts computes the host for both grafanas.
func (o *Operation) ComputeGrafanaHosts() []string {
return []string{
o.ComputeGrafanaOperatorsHostDeprecated(),
o.ComputeGrafanaUsersHostDeprecated(),
o.ComputeGrafanaOperatorsHost(),
o.ComputeGrafanaUsersHost(),
}
}
// ComputeKibanaHosts computes the hosts for kibana.
func (o *Operation) ComputeKibanaHosts() []string {
return []string{
o.ComputeKibanaHostDeprecated(),
o.ComputeKibanaHost(),
}
}
// ComputePrometheusHosts computes the hosts for prometheus.
func (o *Operation) ComputePrometheusHosts() []string {
return []string{
o.ComputePrometheusHostDeprecated(),
o.ComputePrometheusHost(),
}
}
// ComputeAlertManagerHosts computes the host for alert manager.
func (o *Operation) ComputeAlertManagerHosts() []string {
return []string{
o.ComputeAlertManagerHostDeprecated(),
o.ComputeAlertManagerHost(),
}
}
// ComputeGrafanaOperatorsHostDeprecated computes the host for users Grafana.
// TODO: timuthy - remove in the future. Old Grafana host is retained for migration reasons.
func (o *Operation) ComputeGrafanaOperatorsHostDeprecated() string {
return o.ComputeIngressHostDeprecated(common.GrafanaOperatorsPrefix)
}
// ComputeGrafanaUsersHostDeprecated computes the host for operators Grafana.
// TODO: timuthy - remove in the future. Old Grafana host is retained for migration reasons.
func (o *Operation) ComputeGrafanaUsersHostDeprecated() string {
return o.ComputeIngressHostDeprecated(common.GrafanaUsersPrefix)
}
// ComputeGrafanaOperatorsHost computes the host for users Grafana.
func (o *Operation) ComputeGrafanaOperatorsHost() string {
return o.ComputeIngressHost(common.GrafanaOperatorsPrefix)
}
// ComputeGrafanaUsersHost computes the host for operators Grafana.
func (o *Operation) ComputeGrafanaUsersHost() string {
return o.ComputeIngressHost(common.GrafanaUsersPrefix)
}
// ComputeAlertManagerHostDeprecated computes the host for alert manager.
// TODO: timuthy - remove in the future. Old AlertManager host is retained for migration reasons.
func (o *Operation) ComputeAlertManagerHostDeprecated() string {
return o.ComputeIngressHostDeprecated(common.AlertManagerPrefix)
}
// ComputeAlertManagerHost computes the host for alert manager.
func (o *Operation) ComputeAlertManagerHost() string {
return o.ComputeIngressHost(common.AlertManagerPrefix)
}
// ComputePrometheusHostDeprecated computes the host for prometheus.
// TODO: timuthy - remove in the future. Old Prometheus host is retained for migration reasons.
func (o *Operation) ComputePrometheusHostDeprecated() string {
return o.ComputeIngressHostDeprecated(common.PrometheusPrefix)
}
// ComputePrometheusHost computes the host for prometheus.
func (o *Operation) ComputePrometheusHost() string {
return o.ComputeIngressHost(common.PrometheusPrefix)
}
// ComputeKibanaHostDeprecated computes the host for kibana.
// TODO: timuthy - remove in the future. Old Kibana host is retained for migration reasons.
func (o *Operation) ComputeKibanaHostDeprecated() string {
return o.ComputeIngressHostDeprecated(common.KibanaPrefix)
}
// ComputeKibanaHost computes the host for kibana.
func (o *Operation) ComputeKibanaHost() string {
return o.ComputeIngressHost(common.KibanaPrefix)
}
// ComputeIngressHostDeprecated computes the host for a given prefix.
// TODO: timuthy - remove in the future. Only retained for migration reasons.
func (o *Operation) ComputeIngressHostDeprecated(prefix string) string {
return o.Seed.GetIngressFQDNDeprecated(prefix, o.Shoot.Info.Name, o.Garden.Project.Name)
}
// ComputeIngressHost computes the host for a given prefix.
func (o *Operation) ComputeIngressHost(prefix string) string {
shortID := strings.Replace(o.Shoot.Info.Status.TechnicalID, shoot.TechnicalIDPrefix, "", 1)
return fmt.Sprintf("%s-%s.%s", prefix, shortID, o.Seed.Info.Spec.DNS.IngressDomain)
}