/
vmi.go
572 lines (524 loc) · 20.6 KB
/
vmi.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
// Copyright (c) 2022, 2023, Oracle and/or its affiliates.
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
package common
import (
"context"
"fmt"
"reflect"
vmov1 "github.com/verrazzano/verrazzano-monitoring-operator/pkg/apis/vmcontroller/v1"
vmoconst "github.com/verrazzano/verrazzano-monitoring-operator/pkg/constants"
globalconst "github.com/verrazzano/verrazzano/pkg/constants"
ctrlerrors "github.com/verrazzano/verrazzano/pkg/controller/errors"
"github.com/verrazzano/verrazzano/pkg/k8s/ready"
"github.com/verrazzano/verrazzano/pkg/security/password"
"github.com/verrazzano/verrazzano/pkg/vzcr"
vzapi "github.com/verrazzano/verrazzano/platform-operator/apis/verrazzano/v1alpha1"
"github.com/verrazzano/verrazzano/platform-operator/apis/verrazzano/v1beta1"
"github.com/verrazzano/verrazzano/platform-operator/constants"
"github.com/verrazzano/verrazzano/platform-operator/controllers/verrazzano/component/spi"
vzsecret "github.com/verrazzano/verrazzano/platform-operator/controllers/verrazzano/secret"
"github.com/verrazzano/verrazzano/platform-operator/internal/k8s/namespace"
"github.com/verrazzano/verrazzano/platform-operator/internal/vzconfig"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
netv1 "k8s.io/api/networking/v1"
rbacv1 "k8s.io/api/rbac/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/types"
controllerruntime "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
)
const (
VMIName = "system"
VMOComponentName = "verrazzano-monitoring-operator"
VMOComponentNamespace = constants.VerrazzanoSystemNamespace
defaultStorageSize = "50Gi"
)
var vmoManagedLabels = labels.Set{vmoconst.VMOLabel: VMIName}
var vmoLabelSelector = labels.SelectorFromSet(vmoManagedLabels)
// ResourceRequestValues defines the storage information that will be passed to VMI instance
type ResourceRequestValues struct {
Memory string `json:"memory,omitempty"`
Storage string `json:"storage"` // Empty string allowed
}
// VMIMutateFunc is the function used to populate the components in VMI
type VMIMutateFunc func(ctx spi.ComponentContext, storage *ResourceRequestValues, vmi *vmov1.VerrazzanoMonitoringInstance, existingVMI *vmov1.VerrazzanoMonitoringInstance) error
// NewVMI creates a new VerrazzanoMonitoringInstance object with default values
func NewVMI() *vmov1.VerrazzanoMonitoringInstance {
return &vmov1.VerrazzanoMonitoringInstance{
ObjectMeta: metav1.ObjectMeta{
Name: VMIName,
Namespace: globalconst.VerrazzanoSystemNamespace,
},
}
}
// DeleteVMI deletes the VMI resource
func DeleteVMI(ctx spi.ComponentContext) error {
vmi := NewVMI()
err := ctx.Client().Delete(context.TODO(), vmi)
if errors.IsNotFound(err) {
return nil
}
if _, ok := err.(*meta.NoKindMatchError); ok {
return nil
}
if err != nil {
return ctx.Log().ErrorfNewErr("failed to delete VMI: %v", err)
}
return nil
}
// IsLegacyOS returns true if the OS that is running is managed by VMO
func IsLegacyOS(ctx spi.ComponentContext) (bool, error) {
if vzcr.IsOpenSearchEnabled(ctx.EffectiveCR()) {
systemVMI := vmov1.VerrazzanoMonitoringInstance{}
if err := ctx.Client().Get(context.TODO(), types.NamespacedName{Name: VMIName, Namespace: globalconst.VerrazzanoSystemNamespace}, &systemVMI); err != nil {
if meta.IsNoMatchError(err) || errors.IsNotFound(err) {
return false, nil
}
return false, err
}
if systemVMI.Spec.Opensearch.Enabled {
return true, nil
}
}
return false, nil
}
// IsLegacyOSD returns true if the OSD that is running is managed by VMO
func IsLegacyOSD(ctx spi.ComponentContext) (bool, error) {
if vzcr.IsOpenSearchDashboardsEnabled(ctx.EffectiveCR()) {
systemVMI := vmov1.VerrazzanoMonitoringInstance{}
if err := ctx.Client().Get(context.TODO(), types.NamespacedName{Name: VMIName, Namespace: globalconst.VerrazzanoSystemNamespace}, &systemVMI); err != nil {
if meta.IsNoMatchError(err) || errors.IsNotFound(err) {
return false, nil
}
return false, err
}
if systemVMI.Spec.OpensearchDashboards.Enabled {
return true, nil
}
}
return false, nil
}
// CreateOrUpdateVMI instantiates the VMI resource
func CreateOrUpdateVMI(ctx spi.ComponentContext, updateFunc VMIMutateFunc) error {
if !vzcr.IsVMOEnabled(ctx.EffectiveCR()) {
return nil
}
effectiveCR := ctx.EffectiveCR()
var dnsSuffix string
var envName string
var err error
if vzcr.IsNGINXEnabled(effectiveCR) {
dnsSuffix, err = vzconfig.GetDNSSuffix(ctx.Client(), effectiveCR)
if err != nil {
return ctx.Log().ErrorfThrottledNewErr("Failed getting DNS suffix: %v", err)
}
envName = vzconfig.GetEnvName(effectiveCR)
}
storage, err := FindStorageOverride(ctx.EffectiveCR())
if err != nil {
return ctx.Log().ErrorfNewErr("failed to get storage overrides: %v", err)
}
vmi := NewVMI()
_, err = controllerutil.CreateOrUpdate(context.TODO(), ctx.Client(), vmi, func() error {
var existingVMI *vmov1.VerrazzanoMonitoringInstance
if len(vmi.Spec.SecretsName) > 0 {
existingVMI = vmi.DeepCopy()
}
vmi.Labels = map[string]string{
"k8s-app": "verrazzano.io",
"verrazzano.binding": VMIName,
}
if vzcr.IsNGINXEnabled(effectiveCR) {
vmi.Spec.URI = fmt.Sprintf("vmi.system.%s.%s", envName, dnsSuffix)
vmi.Spec.IngressTargetDNSName = fmt.Sprintf("verrazzano-ingress.%s.%s", envName, dnsSuffix)
}
ingressClassName := vzconfig.GetIngressClassName(effectiveCR)
vmi.Spec.IngressClassName = &ingressClassName
vmi.Spec.ServiceType = "ClusterIP"
vmi.Spec.AutoSecret = true
vmi.Spec.SecretsName = constants.VMISecret
vmi.Spec.CascadingDelete = true
return updateFunc(ctx, storage, vmi, existingVMI)
})
if err != nil {
return ctx.Log().ErrorfNewErr("failed to update VMI: %v", err)
}
return nil
}
// EnsureVMISecret creates or updates the VMI secret
func EnsureVMISecret(cli client.Client) error {
secret := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: constants.VMISecret,
Namespace: globalconst.VerrazzanoSystemNamespace,
},
Data: map[string][]byte{},
}
if _, err := controllerruntime.CreateOrUpdate(context.TODO(), cli, secret, func() error {
if secret.Data["username"] == nil || secret.Data["password"] == nil {
secret.Data["username"] = []byte(constants.VMISecret)
pw, err := password.GeneratePassword(16)
if err != nil {
return err
}
secret.Data["password"] = []byte(pw)
}
return nil
}); err != nil {
return err
}
return nil
}
// EnsureGrafanaAdminSecret creates or updates the Grafana admin secret
func EnsureGrafanaAdminSecret(cli client.Client) error {
secret := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: constants.GrafanaSecret,
Namespace: globalconst.VerrazzanoSystemNamespace,
},
Data: map[string][]byte{},
}
if _, err := controllerruntime.CreateOrUpdate(context.TODO(), cli, secret, func() error {
if secret.Data["username"] == nil || secret.Data["password"] == nil {
secret.Data["username"] = []byte(constants.VMISecret)
pw, err := password.GeneratePassword(32)
if err != nil {
return err
}
secret.Data["password"] = []byte(pw)
}
return nil
}); err != nil {
return err
}
return nil
}
// EnsureGrafanaDatabaseSecret ensures that the DB login secret provided in the verrazzano-install namespace is copied
// to the verrazzano-system namespace
func EnsureGrafanaDatabaseSecret(ctx spi.ComponentContext) error {
if ctx.EffectiveCR().Spec.Components.Grafana.Database != nil {
// an external database is configured
return CopySecret(ctx, constants.GrafanaDBSecret, constants.VerrazzanoSystemNamespace, "Grafana Database")
}
return nil
}
// EnsureBackupSecret creates or updates the VMI backup secret
func EnsureBackupSecret(cli client.Client) error {
secret := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: constants.VMIBackupSecretName,
Namespace: globalconst.VerrazzanoSystemNamespace,
},
Data: map[string][]byte{},
}
if _, err := controllerruntime.CreateOrUpdate(context.TODO(), cli, secret, func() error {
// Populating dummy keys for access and secret key so that they are never empty
if secret.Data[constants.ObjectStoreAccessKey] == nil || secret.Data[constants.ObjectStoreAccessSecretKey] == nil {
key, err := password.GeneratePassword(32)
if err != nil {
return err
}
secret.Data[constants.ObjectStoreAccessKey] = []byte(key)
secret.Data[constants.ObjectStoreAccessSecretKey] = []byte(key)
}
return nil
}); err != nil {
return err
}
return nil
}
// FindStorageOverride finds and returns the correct storage override from the effective CR
func FindStorageOverride(effectiveCR *vzapi.Verrazzano) (*ResourceRequestValues, error) {
if effectiveCR == nil || effectiveCR.Spec.DefaultVolumeSource == nil {
return nil, nil
}
defaultVolumeSource := effectiveCR.Spec.DefaultVolumeSource
if defaultVolumeSource.EmptyDir != nil {
return &ResourceRequestValues{
Storage: "",
}, nil
}
if defaultVolumeSource.PersistentVolumeClaim != nil {
pvcClaim := defaultVolumeSource.PersistentVolumeClaim
storageSpec, found := vzconfig.FindVolumeTemplate(pvcClaim.ClaimName, effectiveCR)
if !found {
return nil, fmt.Errorf("Failed, did not find matching storage volume template for claim %s", pvcClaim.ClaimName)
}
storageString := storageSpec.Resources.Requests.Storage().String()
return &ResourceRequestValues{
Storage: storageString,
}, nil
}
return nil, fmt.Errorf("Failed, unsupported volume source: %v", defaultVolumeSource)
}
// FindStorageOverrideV1Beta1 finds and returns the correct storage override from the effective CR
func FindStorageOverrideV1Beta1(effectiveCR *v1beta1.Verrazzano) (*ResourceRequestValues, error) {
if effectiveCR == nil || effectiveCR.Spec.DefaultVolumeSource == nil {
return nil, nil
}
defaultVolumeSource := effectiveCR.Spec.DefaultVolumeSource
if defaultVolumeSource.EmptyDir != nil {
return &ResourceRequestValues{
Storage: "",
}, nil
}
if defaultVolumeSource.PersistentVolumeClaim != nil {
pvcClaim := defaultVolumeSource.PersistentVolumeClaim
storageSpec, found := vzconfig.FindVolumeTemplate(pvcClaim.ClaimName, effectiveCR)
if !found {
return nil, fmt.Errorf("Failed, did not find matching storage volume template for claim %s", pvcClaim.ClaimName)
}
storageString := storageSpec.Resources.Requests.Storage().String()
return &ResourceRequestValues{
Storage: storageString,
}, nil
}
return nil, fmt.Errorf("Failed, unsupported volume source: %v", defaultVolumeSource)
}
// IsVMISecretReady returns true if the VMI secret is present in the system namespace
func IsVMISecretReady(ctx spi.ComponentContext) bool {
if err := ctx.Client().Get(context.TODO(),
types.NamespacedName{Name: "verrazzano", Namespace: globalconst.VerrazzanoSystemNamespace},
&corev1.Secret{}); err != nil {
if !errors.IsNotFound(err) {
ctx.Log().Errorf("Failed, unexpected error getting verrazzano secret: %v", err)
return false
}
ctx.Log().Debugf("Verrazzano secret not found")
return false
}
return true
}
// CreateAndLabelVMINamespaces creates and labels the namespaces needed for the VMI resources
func CreateAndLabelVMINamespaces(ctx spi.ComponentContext) error {
istio := ctx.EffectiveCR().Spec.Components.Istio
if err := namespace.CreateVerrazzanoSystemNamespace(ctx.Client(), istio != nil && istio.IsInjectionEnabled()); err != nil {
return err
}
if _, err := vzsecret.CheckImagePullSecret(ctx.Client(), globalconst.VerrazzanoSystemNamespace); err != nil {
return ctx.Log().ErrorfNewErr("Failed checking for image pull secret: %v", err)
}
return nil
}
// CompareStorageOverrides compares storage override settings for the VMI components
func CompareStorageOverrides(old *vzapi.Verrazzano, new *vzapi.Verrazzano, jsonName string) error {
// compare the storage overrides and reject if the type or size is different
oldSetting, err := FindStorageOverride(old)
if err != nil {
return err
}
// Allow the case where existing (old) storage settings were not specified.
if oldSetting != nil && reflect.DeepEqual(*oldSetting, ResourceRequestValues{}) {
return nil
}
newSetting, err := FindStorageOverride(new)
if err != nil {
return err
}
if !reflect.DeepEqual(oldSetting, newSetting) {
return fmt.Errorf("Can not change volume settings for %s", jsonName)
}
return nil
}
// CompareStorageOverridesV1Beta1 compares storage override settings for the VMI components
func CompareStorageOverridesV1Beta1(old *v1beta1.Verrazzano, new *v1beta1.Verrazzano, jsonName string) error {
// compare the storage overrides and reject if the type or size is different
oldSetting, err := FindStorageOverrideV1Beta1(old)
if err != nil {
return err
}
// Allow the case where existing (old) storage settings were not specified.
if oldSetting != nil && reflect.DeepEqual(*oldSetting, ResourceRequestValues{}) {
return nil
}
newSetting, err := FindStorageOverrideV1Beta1(new)
if err != nil {
return err
}
if !reflect.DeepEqual(oldSetting, newSetting) {
return fmt.Errorf("Can not change volume settings for %s", jsonName)
}
return nil
}
// CheckIngressesAndCerts checks the Ingress and Certs for the VMI components in the Post- function
func CheckIngressesAndCerts(ctx spi.ComponentContext, comp spi.Component) error {
prefix := fmt.Sprintf("Component %s", comp.Name())
if !ready.IngressesPresent(ctx.Log(), ctx.Client(), comp.GetIngressNames(ctx), prefix) {
return ctrlerrors.RetryableError{
Source: comp.Name(),
Operation: "Check if Ingresses are present",
}
}
if readyStatus, certsNotReady := ready.CertificatesAreReady(ctx.Client(), ctx.Log(), ctx.EffectiveCR(), comp.GetCertificateNames(ctx)); !readyStatus {
ctx.Log().Progressf("Certificates not ready for component %s: %v", comp.Name(), certsNotReady)
return ctrlerrors.RetryableError{
Source: comp.Name(),
Operation: "Check if certificates are ready",
}
}
return nil
}
// IsMultiNodeOpenSearch returns true if the VZ OpenSearch has more than 1 node.
func IsMultiNodeOpenSearch(vz *vzapi.Verrazzano) (bool, error) {
opensearch := vz.Spec.Components.Elasticsearch
var replicas int32
if opensearch != nil && opensearch.Enabled != nil && *opensearch.Enabled {
// add any replicas from the Node Groups API
addNodeGroupReplicas(opensearch, &replicas)
// add any replicas from install args. There may an error when parsing install arg values
// from strings to int.
if err := addInstallArgReplicas(opensearch, &replicas); err != nil {
return false, err
}
}
return replicas > 1, nil
}
// addNodeGroupReplicas iterates through each OpenSearch node and sums the replicas
func addNodeGroupReplicas(os *vzapi.ElasticsearchComponent, replicas *int32) {
for _, node := range os.Nodes {
if node.Replicas != nil {
*replicas += *node.Replicas
}
}
}
// addInstallArgReplicas sums the replicas from master, data, and ingest node install args.
func addInstallArgReplicas(os *vzapi.ElasticsearchComponent, replicas *int32) error {
addStr := func(v string) error {
var val int32
if _, err := fmt.Sscan(v, &val); err != nil {
return err
}
*replicas += val
return nil
}
for _, arg := range os.ESInstallArgs {
switch arg.Name {
case "nodes.master.replicas":
case "nodes.ingest.replicas":
case "nodes.data.replicas":
if err := addStr(arg.Value); err != nil {
return err
}
default:
continue
}
}
return nil
}
// IsGrafanaAdminSecretReady returns true if the Grafana admin secret is present in the system namespace
func IsGrafanaAdminSecretReady(ctx spi.ComponentContext) bool {
if err := ctx.Client().Get(context.TODO(),
types.NamespacedName{Name: constants.GrafanaSecret, Namespace: globalconst.VerrazzanoSystemNamespace},
&corev1.Secret{}); err != nil {
if !errors.IsNotFound(err) {
ctx.Log().Errorf("Failed, unexpected error getting grafana admin secret: %v", err)
return false
}
ctx.Log().Debugf("Grafana admin secret not found")
return false
}
return true
}
// SetStorageSize copies or defaults the storage size
func SetStorageSize(storage *ResourceRequestValues, storageObject *vmov1.Storage) {
if storage == nil {
storageObject.Size = defaultStorageSize
} else {
storageObject.Size = storage.Storage
}
}
// ExportVMOHelmChart adds necessary annotations to verrazzano-monitoring-operator objects which allows them to be
// managed by the verrazzano-monitoring-operator helm chart. This is needed for the case when VMO was
// previously installed by the verrazzano helm chart.
func ExportVMOHelmChart(ctx spi.ComponentContext) error {
releaseName := types.NamespacedName{Name: VMOComponentName, Namespace: VMOComponentNamespace}
managedResources := GetVMOHelmManagedResources()
for _, managedResource := range managedResources {
if _, err := AssociateHelmObject(ctx.Client(), managedResource.Obj, releaseName, managedResource.NamespacedName, true); err != nil {
return err
}
}
return nil
}
// ReassociateVMOResources updates the resources to ensure they are managed by the VMO release/component. The resource policy
// annotation is removed to ensure that helm manages the lifecycle of the resources (the resource policy annotation is
// added to ensure the resources are disassociated from the VZ chart which used to manage these resources)
func ReassociateVMOResources(ctx spi.ComponentContext) error {
managedResources := GetVMOHelmManagedResources()
for _, managedResource := range managedResources {
if _, err := RemoveResourcePolicyAnnotation(ctx.Client(), managedResource.Obj, managedResource.NamespacedName); err != nil {
return err
}
}
return nil
}
// GetVMOHelmManagedResources returns a list of resource types and their namespaced names that are managed by the
// VMO helm chart
func GetVMOHelmManagedResources() []HelmManagedResource {
return []HelmManagedResource{
{Obj: &corev1.ConfigMap{}, NamespacedName: types.NamespacedName{Name: "verrazzano-monitoring-operator-config", Namespace: VMOComponentNamespace}},
{Obj: &appsv1.Deployment{}, NamespacedName: types.NamespacedName{Name: VMOComponentName, Namespace: VMOComponentNamespace}},
{Obj: &corev1.Service{}, NamespacedName: types.NamespacedName{Name: VMOComponentName, Namespace: VMOComponentNamespace}},
{Obj: &corev1.ServiceAccount{}, NamespacedName: types.NamespacedName{Name: VMOComponentName, Namespace: VMOComponentNamespace}},
{Obj: &rbacv1.ClusterRole{}, NamespacedName: types.NamespacedName{Name: "verrazzano-monitoring-operator-cluster-role"}},
{Obj: &rbacv1.ClusterRole{}, NamespacedName: types.NamespacedName{Name: "vmi-cluster-role-default"}},
{Obj: &rbacv1.ClusterRole{}, NamespacedName: types.NamespacedName{Name: "verrazzano-monitoring-operator-get-nodes"}},
{Obj: &rbacv1.ClusterRoleBinding{}, NamespacedName: types.NamespacedName{Name: "verrazzano-monitoring-operator-cluster-role-binding"}},
{Obj: &rbacv1.ClusterRoleBinding{}, NamespacedName: types.NamespacedName{Name: "verrazzano-monitoring-operator-cluster-role-default-binding"}},
{Obj: &rbacv1.ClusterRoleBinding{}, NamespacedName: types.NamespacedName{Name: "verrazzano-monitoring-operator-get-nodes"}},
{Obj: &netv1.NetworkPolicy{}, NamespacedName: types.NamespacedName{Name: VMOComponentName, Namespace: VMOComponentNamespace}},
}
}
// GetVMOManagedDeployments returns the list of deployments managed by VMO
func GetVMOManagedDeployments(ctx spi.ComponentContext) (*appsv1.DeploymentList, error) {
opts := client.ListOptions{
LabelSelector: vmoLabelSelector,
}
objList := appsv1.DeploymentList{}
err := ctx.Client().List(context.TODO(), &objList, &opts)
if err != nil {
return nil, err
}
return &objList, nil
}
// GetVMOManagedStatefulsets returns the list of statefulsets managed by VMO
func GetVMOManagedStatefulsets(ctx spi.ComponentContext) (*appsv1.StatefulSetList, error) {
opts := client.ListOptions{
LabelSelector: vmoLabelSelector,
}
objList := appsv1.StatefulSetList{}
err := ctx.Client().List(context.TODO(), &objList, &opts)
if err != nil {
return nil, err
}
return &objList, nil
}
// GetVMOManagedIngresses returns the list of ingresses managed by VMO
func GetVMOManagedIngresses(ctx spi.ComponentContext) (*netv1.IngressList, error) {
opts := client.ListOptions{
LabelSelector: vmoLabelSelector,
}
objList := netv1.IngressList{}
err := ctx.Client().List(context.TODO(), &objList, &opts)
if err != nil {
return nil, err
}
return &objList, nil
}
// GetVMOManagedServices returns the list of services managed by VMO
func GetVMOManagedServices(ctx spi.ComponentContext) (*corev1.ServiceList, error) {
opts := client.ListOptions{
LabelSelector: vmoLabelSelector,
}
objList := corev1.ServiceList{}
err := ctx.Client().List(context.TODO(), &objList, &opts)
if err != nil {
return nil, err
}
return &objList, nil
}