This repository has been archived by the owner on May 10, 2023. It is now read-only.
/
object.go
102 lines (91 loc) · 2.63 KB
/
object.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
/*
* Copyright contributors to the Galasa Project
*/
package api
import (
"context"
"reflect"
"github.com/galasa-dev/kubernetes-operator/pkg/apis/galasaecosystem/v2alpha1"
galasaecosystem "github.com/galasa-dev/kubernetes-operator/pkg/client/clientset/versioned"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
)
type Api struct {
Ecosystemclient galasaecosystem.Interface
Name string
Namespace string
BusyboxImage string
Image string
Replicas *int32
ImagePullPolicy string
Storage string
StorageClassName string
NodeSelector map[string]string
Owner []v1.OwnerReference
Status v2alpha1.ComponentStatus
CPSUri string
}
func New(apiCrd *v2alpha1.GalasaApiComponent, k galasaecosystem.Interface) *Api {
t := true
return &Api{
Ecosystemclient: k,
Namespace: apiCrd.Namespace,
Name: apiCrd.Name,
BusyboxImage: apiCrd.Spec.ComponentParms["busyboxImage"],
CPSUri: apiCrd.Spec.ComponentParms["cpsuri"],
Image: apiCrd.Spec.Image,
Replicas: apiCrd.Spec.Replicas,
ImagePullPolicy: apiCrd.Spec.ImagePullPolicy,
Storage: apiCrd.Spec.Storage,
StorageClassName: apiCrd.Spec.StorageClassName,
NodeSelector: apiCrd.Spec.NodeSelector,
Owner: []v1.OwnerReference{
{
APIVersion: "galasa.dev/v2alpha1",
Kind: "GalasaApiComponent",
Name: apiCrd.Name,
UID: apiCrd.GetUID(),
Controller: &t,
BlockOwnerDeletion: &t,
},
},
Status: v2alpha1.ComponentStatus{
Ready: apiCrd.Status.Ready,
},
}
}
func (c *Api) HasChanged(spec v2alpha1.ComponentSpec) bool {
if c.Image != spec.Image {
return true
}
if c.ImagePullPolicy != spec.ImagePullPolicy {
return true
}
if c.Storage != spec.Storage {
return true
}
if c.StorageClassName != spec.StorageClassName {
return true
}
if reflect.DeepEqual(c.NodeSelector, spec.NodeSelector) {
return true
}
return false
}
func (c *Api) IsReady(ctx context.Context) bool {
api, err := c.Ecosystemclient.GalasaV2alpha1().GalasaApiComponents(c.Namespace).Get(ctx, c.Name, v1.GetOptions{})
if err != nil {
return false
}
return api.Status.Ready
}
func (c *Api) GetObjects() []runtime.Object {
var objects []runtime.Object
objects = append(objects, c.getPersistentVolumeClaim())
objects = append(objects, c.getInternalService())
objects = append(objects, c.getExposedService())
objects = append(objects, c.getTestCatalog())
objects = append(objects, c.getBootstrap())
objects = append(objects, c.getDeployment())
return objects
}