/
adapter_objectsetphase.go
144 lines (114 loc) · 3.83 KB
/
adapter_objectsetphase.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
package objectsets
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
corev1alpha1 "package-operator.run/apis/core/v1alpha1"
)
type genericObjectSetPhase interface {
ClientObject() client.Object
GetConditions() []metav1.Condition
IsPaused() bool
SetPhase(phase corev1alpha1.ObjectSetTemplatePhase)
SetPaused(paused bool)
SetAvailabilityProbes([]corev1alpha1.ObjectSetProbe)
SetRevision(revision int64)
SetPrevious([]corev1alpha1.PreviousRevisionReference)
GetStatusControllerOf() []corev1alpha1.ControlledObjectReference
}
type genericObjectSetPhaseFactory func(
scheme *runtime.Scheme) genericObjectSetPhase
var (
objectSetPhaseGVK = corev1alpha1.GroupVersion.WithKind("ObjectSetPhase")
clusterObjectSetPhaseGVK = corev1alpha1.GroupVersion.WithKind("ClusterObjectSetPhase")
)
func newGenericObjectSetPhase(scheme *runtime.Scheme) genericObjectSetPhase {
obj, err := scheme.New(objectSetPhaseGVK)
if err != nil {
panic(err)
}
return &GenericObjectSetPhase{
ObjectSetPhase: *obj.(*corev1alpha1.ObjectSetPhase),
}
}
func newGenericClusterObjectSetPhase(scheme *runtime.Scheme) genericObjectSetPhase {
obj, err := scheme.New(clusterObjectSetPhaseGVK)
if err != nil {
panic(err)
}
return &GenericClusterObjectSetPhase{
ClusterObjectSetPhase: *obj.(*corev1alpha1.ClusterObjectSetPhase),
}
}
var (
_ genericObjectSetPhase = (*GenericObjectSetPhase)(nil)
_ genericObjectSetPhase = (*GenericClusterObjectSetPhase)(nil)
)
type GenericObjectSetPhase struct {
corev1alpha1.ObjectSetPhase
}
func (a *GenericObjectSetPhase) ClientObject() client.Object {
return &a.ObjectSetPhase
}
func (a *GenericObjectSetPhase) GetConditions() []metav1.Condition {
return a.Status.Conditions
}
func (a *GenericObjectSetPhase) SetPaused(paused bool) {
a.Spec.Paused = paused
}
func (a *GenericObjectSetPhase) SetAvailabilityProbes(probes []corev1alpha1.ObjectSetProbe) {
a.Spec.AvailabilityProbes = probes
}
func (a *GenericObjectSetPhase) IsPaused() bool {
return a.Spec.Paused
}
func (a *GenericObjectSetPhase) SetPhase(phase corev1alpha1.ObjectSetTemplatePhase) {
if a.Labels == nil {
a.Labels = map[string]string{}
}
a.Labels[corev1alpha1.ObjectSetPhaseClassLabel] = phase.Class
a.Spec.Objects = phase.Objects
}
func (a *GenericObjectSetPhase) SetRevision(revision int64) {
a.Spec.Revision = revision
}
func (a *GenericObjectSetPhase) SetPrevious(previous []corev1alpha1.PreviousRevisionReference) {
a.Spec.Previous = previous
}
func (a *GenericObjectSetPhase) GetStatusControllerOf() []corev1alpha1.ControlledObjectReference {
return a.Status.ControllerOf
}
type GenericClusterObjectSetPhase struct {
corev1alpha1.ClusterObjectSetPhase
}
func (a *GenericClusterObjectSetPhase) ClientObject() client.Object {
return &a.ClusterObjectSetPhase
}
func (a *GenericClusterObjectSetPhase) GetConditions() []metav1.Condition {
return a.Status.Conditions
}
func (a *GenericClusterObjectSetPhase) SetPaused(paused bool) {
a.Spec.Paused = paused
}
func (a *GenericClusterObjectSetPhase) IsPaused() bool {
return a.Spec.Paused
}
func (a *GenericClusterObjectSetPhase) SetAvailabilityProbes(probes []corev1alpha1.ObjectSetProbe) {
a.Spec.AvailabilityProbes = probes
}
func (a *GenericClusterObjectSetPhase) SetPhase(phase corev1alpha1.ObjectSetTemplatePhase) {
if a.Labels == nil {
a.Labels = map[string]string{}
}
a.Labels[corev1alpha1.ObjectSetPhaseClassLabel] = phase.Class
a.Spec.Objects = phase.Objects
}
func (a *GenericClusterObjectSetPhase) SetRevision(revision int64) {
a.Spec.Revision = revision
}
func (a *GenericClusterObjectSetPhase) SetPrevious(previous []corev1alpha1.PreviousRevisionReference) {
a.Spec.Previous = previous
}
func (a *GenericClusterObjectSetPhase) GetStatusControllerOf() []corev1alpha1.ControlledObjectReference {
return a.Status.ControllerOf
}