-
Notifications
You must be signed in to change notification settings - Fork 1
/
apprelease_types.go
142 lines (114 loc) · 3.83 KB
/
apprelease_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
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
/*
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package v1alpha1
import (
"fmt"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/k11n/konstellation/pkg/utils/files"
)
// AppReleaseSpec defines a release of AppTarget
type AppReleaseSpec struct {
App string `json:"app"`
Target string `json:"target"`
Build string `json:"build"`
Config string `json:"config"`
// num desired default state, autoscaling could change desired in status
NumDesired int32 `json:"numDesired"`
Role ReleaseRole `json:"role"`
TrafficPercentage int32 `json:"trafficPercentage"`
AppCommonSpec `json:",inline"`
}
// AppReleaseStatus defines the observed state of AppRelease
type AppReleaseStatus struct {
State ReleaseState `json:"state"`
StateChangedAt metav1.Time `json:"stateChangedAt"`
NumDesired int32 `json:"numDesired"`
NumReady int32 `json:"numReady"`
NumAvailable int32 `json:"numAvailable"`
// contains pods that are failing to become ready
// +kubebuilder:validation:Optional
// +nullable
PodErrors []PodStatus `json:"podErrors,omitempty"`
}
type PodStatus struct {
Pod string `json:"pod"`
Reason string `json:"reason"`
Message string `json:"message"`
}
type ReleaseState string
func (rs ReleaseState) String() string {
return string(rs)
}
const (
ReleaseStateNew ReleaseState = "new"
ReleaseStateCanarying ReleaseState = "canarying"
ReleaseStateReleasing ReleaseState = "releasing"
ReleaseStateReleased ReleaseState = "released"
ReleaseStateRetiring ReleaseState = "retiring"
ReleaseStateRetired ReleaseState = "retired"
ReleaseStateFailed ReleaseState = "failed"
ReleaseStateBad ReleaseState = "bad"
ReleaseStateHalted ReleaseState = "halted"
)
type ReleaseRole string
func (rr ReleaseRole) String() string {
return string(rr)
}
const (
// no special role
ReleaseRoleNone = ""
// indicates the release that should be serving all of current traffic
ReleaseRoleActive = "active"
// indicates the release we are moving towards
ReleaseRoleTarget = "target"
ReleaseRoleBad = "bad"
)
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// AppRelease is the Schema for the appreleases API
type AppRelease struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec AppReleaseSpec `json:"spec,omitempty"`
Status AppReleaseStatus `json:"status,omitempty"`
}
// +kubebuilder:object:root=true
// AppReleaseList contains a list of AppRelease
type AppReleaseList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []AppRelease `json:"items"`
}
func (s *AppReleaseSpec) ContainerPorts() []corev1.ContainerPort {
ports := []corev1.ContainerPort{}
for _, p := range s.Ports {
ports = append(ports, corev1.ContainerPort{
Name: p.Name,
ContainerPort: p.Port,
Protocol: p.Protocol,
})
}
return ports
}
func init() {
SchemeBuilder.Register(&AppRelease{}, &AppReleaseList{})
}
func GenerateAppReleaseName(at *AppTarget, build *Build, cm *corev1.ConfigMap) string {
hashStr := at.GetHash()
if cm != nil {
hashStr = files.Sha1ChecksumString(fmt.Sprintf("%s-%s", at.GetHash(), cm.Labels[ConfigHashLabel]))
}
return fmt.Sprintf("%s-%s-%s", at.Spec.App,
build.CreationTimestamp.Format("20060102-1504"),
hashStr[:5])
}