/
installation_types.go
141 lines (122 loc) · 5.69 KB
/
installation_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
/*
Copyright 2023.
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 v1beta1
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// What follows is a list of all valid states for an Installation object.
const (
InstallationStateWaiting string = "Waiting"
InstallationStateCopyingArtifacts string = "CopyingArtifacts"
InstallationStateEnqueued string = "Enqueued"
InstallationStateInstalling string = "Installing"
InstallationStateInstalled string = "Installed"
InstallationStateKubernetesInstalled string = "KubernetesInstalled"
InstallationStateAddonsInstalling string = "AddonsInstalling"
InstallationStateHelmChartUpdateFailure string = "HelmChartUpdateFailure"
InstallationStateObsolete string = "Obsolete"
InstallationStateFailed string = "Failed"
InstallationStateUnknown string = "Unknown"
InstallationStatePendingChartCreation string = "PendingChartCreation"
)
// NodeStatus is used to keep track of the status of a cluster node, we
// only hold its name and a hash of the node's status. Whenever the node
// status change we will be able to capture it and update the hash.
type NodeStatus struct {
Name string `json:"name"`
Hash string `json:"hash"`
}
// ArtifactsLocation defines a location from where we can download an
// airgap bundle. It contains individual URLs for each component of the
// bundle. These URLs are expected to point to a registry running inside
// the cluster, authentication for the registry is read from the cluster
// at execution time so they do not need to be provided here.
type ArtifactsLocation struct {
Images string `json:"images"`
HelmCharts string `json:"helmCharts"`
EmbeddedClusterBinary string `json:"embeddedClusterBinary"`
EmbeddedClusterMetadata string `json:"embeddedClusterMetadata"`
}
// LicenseInfo holds information about the license used to install the cluster.
type LicenseInfo struct {
IsSnapshotSupported bool `json:"isSnapshotSupported"`
}
// InstallationSpec defines the desired state of Installation.
type InstallationSpec struct {
// ClusterID holds the cluster, generated during the installation.
ClusterID string `json:"clusterID,omitempty"`
// MetricsBaseURL holds the base URL for the metrics server.
MetricsBaseURL string `json:"metricsBaseURL,omitempty"`
// AirGap indicates if the installation is airgapped.
AirGap bool `json:"airGap"`
// Artifacts holds the location of the airgap bundle.
Artifacts *ArtifactsLocation `json:"artifacts,omitempty"`
// Config holds the configuration used at installation time.
Config *ConfigSpec `json:"config,omitempty"`
// EndUserK0sConfigOverrides holds the end user k0s config overrides
// used at installation time.
EndUserK0sConfigOverrides string `json:"endUserK0sConfigOverrides,omitempty"`
// BinaryName holds the name of the binary used to install the cluster.
// this will follow the pattern 'appslug-channelslug'
BinaryName string `json:"binaryName,omitempty"`
// LicenseInfo holds information about the license used to install the cluster.
LicenseInfo *LicenseInfo `json:"licenseInfo,omitempty"`
}
// InstallationStatus defines the observed state of Installation
type InstallationStatus struct {
// NodesStatus is a list of nodes and their status.
NodesStatus []NodeStatus `json:"nodesStatus,omitempty"`
// State holds the current state of the installation.
State string `json:"state,omitempty"`
// Reason holds the reason for the current state.
Reason string `json:"reason,omitempty"`
}
// SetState sets the installation state and reason.
func (s *InstallationStatus) SetState(state string, reason string) {
s.State = state
s.Reason = reason
}
func (s *InstallationStatus) GetKubernetesInstalled() bool {
if s.State == InstallationStateInstalled ||
s.State == InstallationStateKubernetesInstalled ||
s.State == InstallationStateAddonsInstalling ||
s.State == InstallationStatePendingChartCreation ||
s.State == InstallationStateHelmChartUpdateFailure {
return true
}
return false
}
//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:resource:scope=Cluster
//+kubebuilder:printcolumn:name="State",type="string",JSONPath=".status.state",description="State of the installation"
//+kubebuilder:printcolumn:name="InstallerVersion",type="string",JSONPath=".spec.config.version",description="Installer version"
//+kubebuilder:printcolumn:name="CreatedAt",type="string",JSONPath=".metadata.creationTimestamp",description="Creation time of the installation"
//+kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description="Age of the resource"
// Installation is the Schema for the installations API
type Installation struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec InstallationSpec `json:"spec,omitempty"`
Status InstallationStatus `json:"status,omitempty"`
}
//+kubebuilder:object:root=true
// InstallationList contains a list of Installation
type InstallationList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Installation `json:"items"`
}
func init() {
SchemeBuilder.Register(&Installation{}, &InstallationList{})
}