/
chart_types.go
138 lines (122 loc) · 4.43 KB
/
chart_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
package v1alpha1
import (
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/giantswarm/apiextensions/pkg/crd"
)
const (
kindChart = "Chart"
chartDocumentationLink = "https://docs.giantswarm.io/reference/cp-k8s-api/charts.application.giantswarm.io/"
)
func NewChartCRD() *v1beta1.CustomResourceDefinition {
return crd.LoadV1Beta1(group, kindChart)
}
func NewChartTypeMeta() metav1.TypeMeta {
return metav1.TypeMeta{
APIVersion: SchemeGroupVersion.String(),
Kind: kindChart,
}
}
// NewChartCR returns an Chart Custom Resource.
func NewChartCR() *Chart {
return &Chart{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
crDocsAnnotation: chartDocumentationLink,
},
},
TypeMeta: NewChartTypeMeta(),
}
}
// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:storageversion
// +kubebuilder:subresource:status
// +kubebuilder:resource:categories=common;giantswarm
type Chart struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata"`
Spec ChartSpec `json:"spec"`
// +kubebuilder:validation:Optional
Status ChartStatus `json:"status"`
}
type ChartSpec struct {
// Config is the config to be applied when the chart is deployed.
Config ChartSpecConfig `json:"config"`
// Name is the name of the Helm chart to be deployed.
// e.g. kubernetes-prometheus
Name string `json:"name"`
// Namespace is the namespace where the chart should be deployed.
// e.g. monitoring
Namespace string `json:"namespace"`
// TarballURL is the URL for the Helm chart tarball to be deployed.
// e.g. https://example.com/path/to/prom-1-0-0.tgz
TarballURL string `json:"tarballURL"`
// Version is the version of the chart that should be deployed.
// e.g. 1.0.0
Version string `json:"version"`
}
type ChartSpecConfig struct {
// ConfigMap references a config map containing values that should be
// applied to the chart.
ConfigMap ChartSpecConfigConfigMap `json:"configMap"`
// Secret references a secret containing secret values that should be
// applied to the chart.
Secret ChartSpecConfigSecret `json:"secret"`
}
type ChartSpecConfigConfigMap struct {
// Name is the name of the config map containing chart values to apply,
// e.g. prometheus-chart-values.
Name string `json:"name"`
// Namespace is the namespace of the values config map,
// e.g. monitoring.
Namespace string `json:"namespace"`
// ResourceVersion is the Kubernetes resource version of the configmap.
// Used to detect if the configmap has changed, e.g. 12345.
ResourceVersion string `json:"resourceVersion"`
}
type ChartSpecConfigSecret struct {
// Name is the name of the secret containing chart values to apply,
// e.g. prometheus-chart-secret.
Name string `json:"name"`
// Namespace is the namespace of the secret,
// e.g. kube-system.
Namespace string `json:"namespace"`
// ResourceVersion is the Kubernetes resource version of the secret.
// Used to detect if the secret has changed, e.g. 12345.
ResourceVersion string `json:"resourceVersion"`
}
type ChartStatus struct {
// AppVersion is the value of the AppVersion field in the Chart.yaml of the
// deployed chart. This is an optional field with the version of the
// component being deployed.
// e.g. 0.21.0.
// https://helm.sh/docs/topics/charts/#the-chartyaml-file
AppVersion string `json:"appVersion"`
// Reason is the description of the last status of helm release when the chart is
// not installed successfully, e.g. deploy resource already exists.
Reason string `json:"reason,omitempty"`
// Release is the status of the Helm release for the deployed chart.
Release ChartStatusRelease `json:"release"`
// Version is the value of the Version field in the Chart.yaml of the
// deployed chart.
// e.g. 1.0.0.
Version string `json:"version"`
}
type ChartStatusRelease struct {
// +kubebuilder:validation:Optional
// +nullable
// LastDeployed is the time when the deployed chart was last deployed.
LastDeployed metav1.Time `json:"lastDeployed,omitempty"`
// Revision is the revision number for this deployed chart.
Revision int `json:"revision"`
// Status is the status of the deployed chart,
// e.g. DEPLOYED.
Status string `json:"status"`
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type ChartList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`
Items []Chart `json:"items"`
}