-
Notifications
You must be signed in to change notification settings - Fork 462
/
gardener_core.go
160 lines (141 loc) · 6.76 KB
/
gardener_core.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
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Gardener contributors
//
// SPDX-License-Identifier: Apache-2.0
package indexer
import (
"context"
"fmt"
"k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/client"
"github.com/gardener/gardener/pkg/apis/core"
gardencorev1beta1 "github.com/gardener/gardener/pkg/apis/core/v1beta1"
)
// ProjectNamespaceIndexerFunc extracts the .spec.namespace field of a Project.
func ProjectNamespaceIndexerFunc(obj client.Object) []string {
project, ok := obj.(*gardencorev1beta1.Project)
if !ok {
return []string{""}
}
return []string{ptr.Deref(project.Spec.Namespace, "")}
}
// BackupBucketSeedNameIndexerFunc extracts the .spec.seedName field of a BackupBucket.
func BackupBucketSeedNameIndexerFunc(obj client.Object) []string {
backupBucket, ok := obj.(*gardencorev1beta1.BackupBucket)
if !ok {
return []string{""}
}
return []string{ptr.Deref(backupBucket.Spec.SeedName, "")}
}
// BackupEntryBucketNameIndexerFunc extracts the .spec.bucketName field of a BackupEntry.
func BackupEntryBucketNameIndexerFunc(obj client.Object) []string {
backupEntry, ok := obj.(*gardencorev1beta1.BackupEntry)
if !ok {
return []string{""}
}
return []string{backupEntry.Spec.BucketName}
}
// ControllerInstallationSeedRefNameIndexerFunc extracts the .spec.seedRef.name field of a ControllerInstallation.
func ControllerInstallationSeedRefNameIndexerFunc(obj client.Object) []string {
controllerInstallation, ok := obj.(*gardencorev1beta1.ControllerInstallation)
if !ok {
return []string{""}
}
return []string{controllerInstallation.Spec.SeedRef.Name}
}
// ControllerInstallationRegistrationRefNameIndexerFunc extracts the .spec.registrationRef.name field of a ControllerInstallation.
func ControllerInstallationRegistrationRefNameIndexerFunc(obj client.Object) []string {
controllerInstallation, ok := obj.(*gardencorev1beta1.ControllerInstallation)
if !ok {
return []string{""}
}
return []string{controllerInstallation.Spec.RegistrationRef.Name}
}
// InternalSecretTypeIndexerFunc extracts the .type field of an InternalSecret.
func InternalSecretTypeIndexerFunc(obj client.Object) []string {
internalSecret, ok := obj.(*gardencorev1beta1.InternalSecret)
if !ok {
return []string{""}
}
return []string{string(internalSecret.Type)}
}
// AddProjectNamespace adds an index for core.ProjectNamespace to the given indexer.
func AddProjectNamespace(ctx context.Context, indexer client.FieldIndexer) error {
if err := indexer.IndexField(ctx, &gardencorev1beta1.Project{}, core.ProjectNamespace, ProjectNamespaceIndexerFunc); err != nil {
return fmt.Errorf("failed to add indexer for %s to Project Informer: %w", core.ProjectNamespace, err)
}
return nil
}
// AddShootSeedName adds an index for core.ShootSeedName to the given indexer.
func AddShootSeedName(ctx context.Context, indexer client.FieldIndexer) error {
if err := indexer.IndexField(ctx, &gardencorev1beta1.Shoot{}, core.ShootSeedName, func(obj client.Object) []string {
shoot, ok := obj.(*gardencorev1beta1.Shoot)
if !ok {
return []string{""}
}
return []string{ptr.Deref(shoot.Spec.SeedName, "")}
}); err != nil {
return fmt.Errorf("failed to add indexer for %s to Shoot Informer: %w", core.ShootSeedName, err)
}
return nil
}
// AddShootStatusSeedName adds an index for core.ShootStatusSeedName to the given indexer.
func AddShootStatusSeedName(ctx context.Context, indexer client.FieldIndexer) error {
if err := indexer.IndexField(ctx, &gardencorev1beta1.Shoot{}, core.ShootStatusSeedName, func(obj client.Object) []string {
shoot, ok := obj.(*gardencorev1beta1.Shoot)
if !ok {
return []string{""}
}
return []string{ptr.Deref(shoot.Status.SeedName, "")}
}); err != nil {
return fmt.Errorf("failed to add indexer for %s to Shoot Informer: %w", core.ShootStatusSeedName, err)
}
return nil
}
// AddBackupBucketSeedName adds an index for core.BackupBucketSeedName to the given indexer.
func AddBackupBucketSeedName(ctx context.Context, indexer client.FieldIndexer) error {
if err := indexer.IndexField(ctx, &gardencorev1beta1.BackupBucket{}, core.BackupBucketSeedName, BackupBucketSeedNameIndexerFunc); err != nil {
return fmt.Errorf("failed to add indexer for %s to BackupBucket Informer: %w", core.BackupBucketSeedName, err)
}
return nil
}
// AddBackupEntrySeedName adds an index for core.BackupEntrySeedName to the given indexer.
func AddBackupEntrySeedName(ctx context.Context, indexer client.FieldIndexer) error {
if err := indexer.IndexField(ctx, &gardencorev1beta1.BackupEntry{}, core.BackupEntrySeedName, func(obj client.Object) []string {
backupEntry, ok := obj.(*gardencorev1beta1.BackupEntry)
if !ok {
return []string{""}
}
return []string{ptr.Deref(backupEntry.Spec.SeedName, "")}
}); err != nil {
return fmt.Errorf("failed to add indexer for %s to BackupEntry Informer: %w", core.BackupEntrySeedName, err)
}
return nil
}
// AddBackupEntryBucketName adds an index for core.BackupEntryBucketName to the given indexer.
func AddBackupEntryBucketName(ctx context.Context, indexer client.FieldIndexer) error {
if err := indexer.IndexField(ctx, &gardencorev1beta1.BackupEntry{}, core.BackupEntryBucketName, BackupEntryBucketNameIndexerFunc); err != nil {
return fmt.Errorf("failed to add indexer for %s to BackupEntry Informer: %w", core.BackupEntryBucketName, err)
}
return nil
}
// AddControllerInstallationSeedRefName adds an index for core.ControllerInstallationSeedRefName to the given indexer.
func AddControllerInstallationSeedRefName(ctx context.Context, indexer client.FieldIndexer) error {
if err := indexer.IndexField(ctx, &gardencorev1beta1.ControllerInstallation{}, core.SeedRefName, ControllerInstallationSeedRefNameIndexerFunc); err != nil {
return fmt.Errorf("failed to add indexer for %s to ControllerInstallation Informer: %w", core.SeedRefName, err)
}
return nil
}
// AddControllerInstallationRegistrationRefName adds an index for core.ControllerInstallationRegistrationRefName to the given indexer.
func AddControllerInstallationRegistrationRefName(ctx context.Context, indexer client.FieldIndexer) error {
if err := indexer.IndexField(ctx, &gardencorev1beta1.ControllerInstallation{}, core.RegistrationRefName, ControllerInstallationRegistrationRefNameIndexerFunc); err != nil {
return fmt.Errorf("failed to add indexer for %s to ControllerInstallation Informer: %w", core.RegistrationRefName, err)
}
return nil
}
// AddInternalSecretType adds an index for core.InternalSecretType to the given indexer.
func AddInternalSecretType(ctx context.Context, indexer client.FieldIndexer) error {
if err := indexer.IndexField(ctx, &gardencorev1beta1.InternalSecret{}, core.InternalSecretType, InternalSecretTypeIndexerFunc); err != nil {
return fmt.Errorf("failed to add indexer for %s to InternalSecret Informer: %w", core.InternalSecretType, err)
}
return nil
}