This repository has been archived by the owner on Jan 6, 2021. It is now read-only.
/
che.go
166 lines (149 loc) · 5.24 KB
/
che.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
package cheinstallation
import (
toolchainv1alpha1 "github.com/codeready-toolchain/api/pkg/apis/toolchain/v1alpha1"
"github.com/codeready-toolchain/toolchain-operator/pkg/apis/toolchain/v1alpha1"
"github.com/codeready-toolchain/toolchain-operator/pkg/toolchain"
olmv1 "github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1"
olmv1alpha1 "github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
orgv1 "github.com/eclipse/che-operator/pkg/apis/org/v1"
)
const (
// InstallationName the name of the CheInstallation resource (cluster-scoped)
InstallationName = "toolchain-workspaces-installation"
// Namespace the namespace in which the OLM OperatorGroup and Subscription resources will be created
Namespace = "toolchain-workspaces"
// OperatorGroupName the name of the OLM OperatorGroup for Che
OperatorGroupName = InstallationName
// SubscriptionName the name of the OLM subscription for Che
SubscriptionName = "codeready-workspaces"
// StartingCSV keeps the CSV version the installation should start with
StartingCSV = "crwoperator.v2.0.0"
// CheClusterName the name of the CheCluster
CheClusterName = "codeready-workspaces"
// CheFlavorName the name of the CheCluster flavor
CheFlavorName = "codeready"
// AvailableStatus constant for Available status
AvailableStatus = "Available"
// CheClusterCRDName the fully qualified name of the CheCluster CRD
CheClusterCRDName = "checlusters.org.eclipse.che"
)
// NewInstallation returns a new CheInstallation resource
func NewInstallation() *v1alpha1.CheInstallation {
return &v1alpha1.CheInstallation{
ObjectMeta: metav1.ObjectMeta{
Name: InstallationName, // Che installation resource is cluster-scoped, so no namespace is defined
Finalizers: []string{toolchainv1alpha1.FinalizerName},
},
Spec: v1alpha1.CheInstallationSpec{
CheOperatorSpec: v1alpha1.CheOperator{
Namespace: Namespace, // the namespace in which the Che operatorgroup and subscription resources will be created
},
},
}
}
// NewSubscription for CodeReady Workspaces operator
func NewSubscription(ns string) *olmv1alpha1.Subscription {
return &olmv1alpha1.Subscription{
ObjectMeta: metav1.ObjectMeta{
Name: SubscriptionName,
Namespace: ns,
Labels: toolchain.Labels(),
},
Spec: &olmv1alpha1.SubscriptionSpec{
Channel: "latest",
InstallPlanApproval: olmv1alpha1.ApprovalAutomatic,
Package: "codeready-workspaces",
StartingCSV: StartingCSV,
CatalogSource: "redhat-operators",
CatalogSourceNamespace: "openshift-marketplace",
},
}
}
// NewNamespace return a new namespace with the toolchain labels
func NewNamespace(name string) *v1.Namespace {
return &v1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Labels: toolchain.Labels(),
},
}
}
// NewOperatorGroup returns a new OLM Operator Group for the given ns, with the toolchain labels
func NewOperatorGroup(ns string) *olmv1.OperatorGroup {
return &olmv1.OperatorGroup{
ObjectMeta: metav1.ObjectMeta{
Namespace: ns,
Name: OperatorGroupName,
Labels: toolchain.Labels(),
},
Spec: olmv1.OperatorGroupSpec{
TargetNamespaces: []string{ns},
},
}
}
// NewCheCluster returns a new CheCluster with the given namespace
func NewCheCluster(ns string) *orgv1.CheCluster {
return &orgv1.CheCluster{
ObjectMeta: metav1.ObjectMeta{
Name: CheClusterName,
Namespace: ns,
Labels: toolchain.Labels(),
},
Spec: orgv1.CheClusterSpec{
Server: orgv1.CheClusterSpecServer{
CheFlavor: CheFlavorName,
TlsSupport: false,
SelfSignedCert: false,
},
Database: orgv1.CheClusterSpecDB{
ExternalDb: false,
},
Auth: orgv1.CheClusterSpecAuth{
OpenShiftoAuth: true,
ExternalIdentityProvider: false,
},
Storage: orgv1.CheClusterSpecStorage{
PvcStrategy: "per-workspace",
PvcClaimSize: "1Gi",
PreCreateSubPaths: true,
},
},
}
}
// Installing returns the status condition to set when Che is (still) being installed
func Installing(message string) toolchainv1alpha1.Condition {
return toolchainv1alpha1.Condition{
Type: v1alpha1.CheReady,
Status: v1.ConditionFalse,
Reason: v1alpha1.InstallingReason,
Message: message,
}
}
// Terminating returns the status condition to set when Che is (still) being uninstalled
func Terminating(message string) toolchainv1alpha1.Condition {
return toolchainv1alpha1.Condition{
Type: v1alpha1.CheReady,
Status: v1.ConditionFalse,
Reason: v1alpha1.TerminatingReason,
Message: message,
}
}
// InstallationSucceeded returns a status condition for the case where the Che installation succeeded
func InstallationSucceeded() toolchainv1alpha1.Condition {
return toolchainv1alpha1.Condition{
Type: v1alpha1.CheReady,
Status: v1.ConditionTrue,
Reason: v1alpha1.InstalledReason,
}
}
// InstallationFailed returns a status condition for the case where the Che installation failed
func InstallationFailed(message string) toolchainv1alpha1.Condition {
return toolchainv1alpha1.Condition{
Type: v1alpha1.CheReady,
Status: v1.ConditionFalse,
Reason: v1alpha1.FailedToInstallReason,
Message: message,
}
}