Skip to content
This repository was archived by the owner on Aug 19, 2024. It is now read-only.

Commit 72f81ae

Browse files
Deployment configuration and v1alpha2 version (#388)
* kyaml and tests Signed-off-by: gazarenkov <gazarenkov@gmail.com> * added v1alpha2 Signed-off-by: gazarenkov <gazarenkov@gmail.com> * deprecation message Signed-off-by: gazarenkov <gazarenkov@gmail.com> * fix spec.deployment test Signed-off-by: gazarenkov <gazarenkov@gmail.com> * .rhdh/csv modified Signed-off-by: gazarenkov <gazarenkov@gmail.com> * Regenerate bundle manifests Co-authored-by: gazarenkov <gazarenkov@users.noreply.github.com> * fixes after comments Signed-off-by: gazarenkov <gazarenkov@gmail.com> * Regenerate bundle manifests Co-authored-by: gazarenkov <gazarenkov@users.noreply.github.com> * fixes after comments Signed-off-by: gazarenkov <gazarenkov@gmail.com> * go.sum for 1.21 Signed-off-by: gazarenkov <gazarenkov@gmail.com> --------- Signed-off-by: gazarenkov <gazarenkov@gmail.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: gazarenkov <gazarenkov@users.noreply.github.com>
1 parent d624583 commit 72f81ae

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+1970
-257
lines changed

.rhdh/bundle/manifests/rhdh-operator.csv.yaml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ metadata:
77
alm-examples: |-
88
[
99
{
10-
"apiVersion": "rhdh.redhat.com/v1alpha1",
10+
"apiVersion": "rhdh.redhat.com/v1alpha2",
1111
"kind": "Backstage",
1212
"metadata": {
1313
"name": "developer-hub"
@@ -57,6 +57,14 @@ spec:
5757
kind: Backstage
5858
name: backstages.rhdh.redhat.com
5959
version: v1alpha1
60+
- description: Backstage is the Schema for the Red Hat Developer Hub backstages API.
61+
It comes with pre-built plug-ins, configuration settings, and deployment mechanisms,
62+
which can help streamline the process of setting up a self-managed internal
63+
developer portal for adopters who are just starting out.
64+
displayName: Red Hat Developer Hub
65+
kind: Backstage
66+
name: backstages.rhdh.redhat.com
67+
version: v1alpha2
6068
description: |
6169
Red Hat Developer Hub is an enterprise-grade platform for building developer portals, containing a supported and opinionated framework. By implementing a unified and open platform designed to maximize developer skills, ease onboarding, and increase development productivity, focus can be centered on what really matters: writing great code. Red Hat Developer Hub also offers Software Templates to simplify the development process, which can reduce friction and frustration for development teams, boosting their productivity and increasing an organization's competitive advantage.
6270

PROJECT

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ resources:
1313
controller: true
1414
domain: rhdh.redhat.com
1515
kind: Backstage
16-
path: redhat-developer/red-hat-developer-hub-operator/api/v1alpha1
17-
version: v1alpha1
16+
path: redhat-developer/red-hat-developer-hub-operator/api/v1alpha2
17+
version: v1alpha2
1818
version: "3"

api/v1alpha1/backstage_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ type BackstageStatus struct {
197197

198198
//+kubebuilder:object:root=true
199199
//+kubebuilder:subresource:status
200+
//+kubebuilder:deprecatedversion:warning="Since 1.3.0 spec.application.image, spec.application.replicas, spec.application.imagePullSecrets are deprecated in favor of corresponding spec.deployment fields"
200201

201202
// Backstage is the Schema for the backstages API
202203
type Backstage struct {

api/v1alpha2/backstage_types.go

Lines changed: 310 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,310 @@
1+
//
2+
// Copyright (c) 2023 Red Hat, Inc.
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package v1alpha2
16+
17+
import (
18+
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
19+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
20+
"k8s.io/utils/ptr"
21+
)
22+
23+
type BackstageConditionReason string
24+
25+
type BackstageConditionType string
26+
27+
const (
28+
BackstageConditionTypeDeployed BackstageConditionType = "Deployed"
29+
30+
BackstageConditionReasonDeployed BackstageConditionReason = "Deployed"
31+
BackstageConditionReasonFailed BackstageConditionReason = "DeployFailed"
32+
BackstageConditionReasonInProgress BackstageConditionReason = "DeployInProgress"
33+
)
34+
35+
// BackstageSpec defines the desired state of Backstage
36+
type BackstageSpec struct {
37+
// Configuration for Backstage. Optional.
38+
Application *Application `json:"application,omitempty"`
39+
40+
// Raw Runtime RuntimeObjects configuration. For Advanced scenarios.
41+
RawRuntimeConfig *RuntimeConfig `json:"rawRuntimeConfig,omitempty"`
42+
43+
// Configuration for database access. Optional.
44+
Database *Database `json:"database,omitempty"`
45+
46+
// Valid fragment of Deployment to be merged with default/raw configuration.
47+
// Set the Deployment's metadata and|or spec fields you want to override or add.
48+
// Optional.
49+
// +kubebuilder:pruning:PreserveUnknownFields
50+
Deployment *BackstageDeployment `json:"deployment,omitempty"`
51+
}
52+
53+
type BackstageDeployment struct {
54+
// Valid fragment of Deployment to be merged with default/raw configuration.
55+
// Set the Deployment's metadata and|or spec fields you want to override or add.
56+
// Optional.
57+
// +kubebuilder:pruning:PreserveUnknownFields
58+
Patch *apiextensionsv1.JSON `json:"patch,omitempty"`
59+
}
60+
61+
type RuntimeConfig struct {
62+
// Name of ConfigMap containing Backstage runtime objects configuration
63+
BackstageConfigName string `json:"backstageConfig,omitempty"`
64+
// Name of ConfigMap containing LocalDb (PostgreSQL) runtime objects configuration
65+
LocalDbConfigName string `json:"localDbConfig,omitempty"`
66+
}
67+
68+
type Database struct {
69+
// Control the creation of a local PostgreSQL DB. Set to false if using for example an external Database for Backstage.
70+
// +optional
71+
//+kubebuilder:default=true
72+
EnableLocalDb *bool `json:"enableLocalDb,omitempty"`
73+
74+
// Name of the secret for database authentication. Optional.
75+
// For a local database deployment (EnableLocalDb=true), a secret will be auto generated if it does not exist.
76+
// The secret shall include information used for the database access.
77+
// An example for PostgreSQL DB access:
78+
// "POSTGRES_PASSWORD": "rl4s3Fh4ng3M4"
79+
// "POSTGRES_PORT": "5432"
80+
// "POSTGRES_USER": "postgres"
81+
// "POSTGRESQL_ADMIN_PASSWORD": "rl4s3Fh4ng3M4"
82+
// "POSTGRES_HOST": "backstage-psql-bs1" # For local database, set to "backstage-psql-<CR name>".
83+
AuthSecretName string `json:"authSecretName,omitempty"`
84+
}
85+
86+
type Application struct {
87+
// References to existing app-configs ConfigMap objects, that will be mounted as files in the specified mount path.
88+
// Each element can be a reference to any ConfigMap or Secret,
89+
// and will be mounted inside the main application container under a specified mount directory.
90+
// Additionally, each file will be passed as a `--config /mount/path/to/configmap/key` to the
91+
// main container args in the order of the entries defined in the AppConfigs list.
92+
// But bear in mind that for a single ConfigMap element containing several filenames,
93+
// the order in which those files will be appended to the main container args cannot be guaranteed.
94+
// So if you want to pass multiple app-config files, it is recommended to pass one ConfigMap per app-config file.
95+
// +optional
96+
AppConfig *AppConfig `json:"appConfig,omitempty"`
97+
98+
// Reference to an existing ConfigMap for Dynamic Plugins.
99+
// A new one will be generated with the default config if not set.
100+
// The ConfigMap object must have an existing key named: 'dynamic-plugins.yaml'.
101+
// +optional
102+
DynamicPluginsConfigMapName string `json:"dynamicPluginsConfigMapName,omitempty"`
103+
104+
// References to existing Config objects to use as extra config files.
105+
// They will be mounted as files in the specified mount path.
106+
// Each element can be a reference to any ConfigMap or Secret.
107+
// +optional
108+
ExtraFiles *ExtraFiles `json:"extraFiles,omitempty"`
109+
110+
// Extra environment variables
111+
// +optional
112+
ExtraEnvs *ExtraEnvs `json:"extraEnvs,omitempty"`
113+
114+
// Number of desired replicas to set in the Backstage Deployment.
115+
// Defaults to 1.
116+
// +optional
117+
//+kubebuilder:default=1
118+
Replicas *int32 `json:"replicas,omitempty"`
119+
120+
// Custom image to use in all containers (including Init Containers).
121+
// It is your responsibility to make sure the image is from trusted sources and has been validated for security compliance
122+
// +optional
123+
Image *string `json:"image,omitempty"`
124+
125+
// Image Pull Secrets to use in all containers (including Init Containers)
126+
// +optional
127+
ImagePullSecrets []string `json:"imagePullSecrets,omitempty"`
128+
129+
// Route configuration. Used for OpenShift only.
130+
Route *Route `json:"route,omitempty"`
131+
}
132+
133+
type AppConfig struct {
134+
// Mount path for all app-config files listed in the ConfigMapRefs field
135+
// +optional
136+
// +kubebuilder:default=/opt/app-root/src
137+
MountPath string `json:"mountPath,omitempty"`
138+
139+
// List of ConfigMaps storing the app-config files. Will be mounted as files under the MountPath specified.
140+
// For each item in this array, if a key is not specified, it means that all keys in the ConfigMap will be mounted as files.
141+
// Otherwise, only the specified key will be mounted as a file.
142+
// Bear in mind not to put sensitive data in those ConfigMaps. Instead, your app-config content can reference
143+
// environment variables (which you can set with the ExtraEnvs field) and/or include extra files (see the ExtraFiles field).
144+
// More details on https://backstage.io/docs/conf/writing/.
145+
// +optional
146+
ConfigMaps []ObjectKeyRef `json:"configMaps,omitempty"`
147+
}
148+
149+
type ExtraFiles struct {
150+
// Mount path for all extra configuration files listed in the Items field
151+
// +optional
152+
// +kubebuilder:default=/opt/app-root/src
153+
MountPath string `json:"mountPath,omitempty"`
154+
155+
// List of references to ConfigMaps objects mounted as extra files under the MountPath specified.
156+
// For each item in this array, if a key is not specified, it means that all keys in the ConfigMap will be mounted as files.
157+
// Otherwise, only the specified key will be mounted as a file.
158+
// +optional
159+
ConfigMaps []ObjectKeyRef `json:"configMaps,omitempty"`
160+
161+
// List of references to Secrets objects mounted as extra files under the MountPath specified.
162+
// For each item in this array, a key must be specified that will be mounted as a file.
163+
// +optional
164+
Secrets []ObjectKeyRef `json:"secrets,omitempty"`
165+
}
166+
167+
type ExtraEnvs struct {
168+
// List of references to ConfigMaps objects to inject as additional environment variables.
169+
// For each item in this array, if a key is not specified, it means that all keys in the ConfigMap will be injected as additional environment variables.
170+
// Otherwise, only the specified key will be injected as an additional environment variable.
171+
// +optional
172+
ConfigMaps []ObjectKeyRef `json:"configMaps,omitempty"`
173+
174+
// List of references to Secrets objects to inject as additional environment variables.
175+
// For each item in this array, if a key is not specified, it means that all keys in the Secret will be injected as additional environment variables.
176+
// Otherwise, only the specified key will be injected as environment variable.
177+
// +optional
178+
Secrets []ObjectKeyRef `json:"secrets,omitempty"`
179+
180+
// List of name and value pairs to add as environment variables.
181+
// +optional
182+
Envs []Env `json:"envs,omitempty"`
183+
}
184+
185+
type ObjectKeyRef struct {
186+
// Name of the object
187+
// We support only ConfigMaps and Secrets.
188+
//+kubebuilder:validation:Required
189+
Name string `json:"name"`
190+
191+
// Key in the object
192+
// +optional
193+
Key string `json:"key,omitempty"`
194+
}
195+
196+
type Env struct {
197+
// Name of the environment variable
198+
//+kubebuilder:validation:Required
199+
Name string `json:"name"`
200+
201+
// Value of the environment variable
202+
//+kubebuilder:validation:Required
203+
Value string `json:"value"`
204+
}
205+
206+
// BackstageStatus defines the observed state of Backstage
207+
type BackstageStatus struct {
208+
// Conditions is the list of conditions describing the state of the runtime
209+
// +optional
210+
Conditions []metav1.Condition `json:"conditions,omitempty"`
211+
}
212+
213+
//+kubebuilder:object:root=true
214+
//+kubebuilder:subresource:status
215+
//+kubebuilder:storageversion
216+
217+
// Backstage is the Schema for the backstages API
218+
type Backstage struct {
219+
metav1.TypeMeta `json:",inline"`
220+
metav1.ObjectMeta `json:"metadata,omitempty"`
221+
222+
Spec BackstageSpec `json:"spec,omitempty"`
223+
Status BackstageStatus `json:"status,omitempty"`
224+
}
225+
226+
//+kubebuilder:object:root=true
227+
228+
// BackstageList contains a list of Backstage
229+
type BackstageList struct {
230+
metav1.TypeMeta `json:",inline"`
231+
metav1.ListMeta `json:"metadata,omitempty"`
232+
Items []Backstage `json:"items"`
233+
}
234+
235+
// Route specifies configuration parameters for OpenShift Route for Backstage.
236+
// Only a secured edge route is supported for Backstage.
237+
type Route struct {
238+
// Control the creation of a Route on OpenShift.
239+
// +optional
240+
//+kubebuilder:default=true
241+
Enabled *bool `json:"enabled,omitempty"`
242+
243+
// Host is an alias/DNS that points to the service. Optional.
244+
// Ignored if Enabled is false.
245+
// If not specified a route name will typically be automatically
246+
// chosen. Must follow DNS952 subdomain conventions.
247+
// +optional
248+
// +kubebuilder:validation:MaxLength=253
249+
// +kubebuilder:validation:Pattern=`^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])(\.([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9]))*$`
250+
Host string `json:"host,omitempty" protobuf:"bytes,1,opt,name=host"`
251+
252+
// Subdomain is a DNS subdomain that is requested within the ingress controller's
253+
// domain (as a subdomain).
254+
// Ignored if Enabled is false.
255+
// Example: subdomain `frontend` automatically receives the router subdomain
256+
// `apps.mycluster.com` to have a full hostname `frontend.apps.mycluster.com`.
257+
// +optional
258+
// +kubebuilder:validation:MaxLength=253
259+
// +kubebuilder:validation:Pattern=`^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])(\.([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9]))*$`
260+
Subdomain string `json:"subdomain,omitempty"`
261+
262+
// The tls field provides the ability to configure certificates for the route.
263+
// Ignored if Enabled is false.
264+
// +optional
265+
TLS *TLS `json:"tls,omitempty"`
266+
}
267+
268+
type TLS struct {
269+
// certificate provides certificate contents. This should be a single serving certificate, not a certificate
270+
// chain. Do not include a CA certificate.
271+
Certificate string `json:"certificate,omitempty"`
272+
273+
// ExternalCertificateSecretName provides certificate contents as a secret reference.
274+
// This should be a single serving certificate, not a certificate
275+
// chain. Do not include a CA certificate. The secret referenced should
276+
// be present in the same namespace as that of the Route.
277+
// Forbidden when `certificate` is set.
278+
// +optional
279+
ExternalCertificateSecretName string `json:"externalCertificateSecretName,omitempty"`
280+
281+
// key provides key file contents
282+
Key string `json:"key,omitempty"`
283+
284+
// caCertificate provides the cert authority certificate contents
285+
CACertificate string `json:"caCertificate,omitempty"`
286+
}
287+
288+
func init() {
289+
SchemeBuilder.Register(&Backstage{}, &BackstageList{})
290+
}
291+
292+
// IsLocalDbEnabled returns true if Local database is configured and enabled
293+
func (s *BackstageSpec) IsLocalDbEnabled() bool {
294+
if s.Database == nil {
295+
return true
296+
}
297+
return ptr.Deref(s.Database.EnableLocalDb, true)
298+
}
299+
300+
// IsRouteEnabled returns value of Application.Route.Enabled if defined or true by default
301+
func (s *BackstageSpec) IsRouteEnabled() bool {
302+
if s.Application != nil && s.Application.Route != nil {
303+
return ptr.Deref(s.Application.Route.Enabled, true)
304+
}
305+
return true
306+
}
307+
308+
func (s *BackstageSpec) IsAuthSecretSpecified() bool {
309+
return s.Database != nil && s.Database.AuthSecretName != ""
310+
}

api/v1alpha2/groupversion_info.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
Copyright 2023 Red Hat Inc..
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
// Package v1alpha2 contains API Schema definitions for the v1alpha2 API group
18+
// +kubebuilder:object:generate=true
19+
// +groupName=rhdh.redhat.com
20+
package v1alpha2
21+
22+
import (
23+
"k8s.io/apimachinery/pkg/runtime/schema"
24+
"sigs.k8s.io/controller-runtime/pkg/scheme"
25+
)
26+
27+
var (
28+
// GroupVersion is group version used to register these objects
29+
GroupVersion = schema.GroupVersion{Group: "rhdh.redhat.com", Version: "v1alpha2"}
30+
31+
// SchemeBuilder is used to add go types to the GroupVersionKind scheme
32+
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
33+
34+
// AddToScheme adds the types in this group-version to the given scheme.
35+
AddToScheme = SchemeBuilder.AddToScheme
36+
)

0 commit comments

Comments
 (0)