/
service_types.go
68 lines (55 loc) · 1.86 KB
/
service_types.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
package v1
import (
ct "github.com/kloudlite/operator/apis/common-types"
"github.com/kloudlite/operator/pkg/constants"
rApi "github.com/kloudlite/operator/pkg/operator"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
type ServiceSpec struct {
Region string `json:"region"`
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`
// +kubebuilder:validation:Optional
// +kubebuilder:default=1
ReplicaCount int `json:"replicaCount,omitempty"`
Resources ct.Resources `json:"resources"`
}
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:JSONPath=".status.isReady",name=Ready,type=boolean
// +kubebuilder:printcolumn:JSONPath=".metadata.creationTimestamp",name=Age,type=date
// Service is the Schema for the services API
type Service struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec ServiceSpec `json:"spec"`
Status rApi.Status `json:"status,omitempty"`
}
func (s *Service) EnsureGVK() {
if s != nil {
// TODO: Check with anshuman
s.SetGroupVersionKind(GroupVersion.WithKind("Service"))
}
}
func (s *Service) GetStatus() *rApi.Status {
return &s.Status
}
func (s *Service) GetEnsuredLabels() map[string]string {
return map[string]string{constants.MsvcNameKey: s.Name}
}
func (s *Service) GetEnsuredAnnotations() map[string]string {
return map[string]string{
constants.AnnotationKeys.GroupVersionKind: GroupVersion.WithKind("Service").String(),
}
}
// +kubebuilder:object:root=true
// ServiceList contains a list of Service
type ServiceList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Service `json:"items"`
}
func init() {
SchemeBuilder.Register(&Service{}, &ServiceList{})
}