Skip to content

Commit 0c5b66b

Browse files
committed
[DNM] Merge placement-operator into nova-operator
This is initial PR for getting feedback from reviewers. Closes: OSPRH-14957
1 parent a318f74 commit 0c5b66b

19 files changed

+1085
-6
lines changed

PROJECT

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Code generated by tool. DO NOT EDIT.
2+
# This file is used to track the info used to scaffold your project
3+
# and allow the plugins properly work.
4+
# More info: https://book.kubebuilder.io/reference/project-config.html
15
domain: openstack.org
26
layout:
37
- go.kubebuilder.io/v3
@@ -111,4 +115,17 @@ resources:
111115
defaulting: true
112116
validation: true
113117
webhookVersion: v1
118+
- api:
119+
crdVersion: v1
120+
namespaced: true
121+
controller: true
122+
domain: openstack.org
123+
group: nova
124+
kind: NovaPlacementAPI
125+
path: github.com/openstack-k8s-operators/nova-operator/api/v1beta1
126+
version: v1beta1
127+
webhooks:
128+
defaulting: true
129+
validation: true
130+
webhookVersion: v1
114131
version: "3"
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
apiVersion: apiextensions.k8s.io/v1
3+
kind: CustomResourceDefinition
4+
metadata:
5+
annotations:
6+
controller-gen.kubebuilder.io/version: v0.14.0
7+
name: novaplacementapis.nova.openstack.org
8+
spec:
9+
group: nova.openstack.org
10+
names:
11+
kind: NovaPlacementAPI
12+
listKind: NovaPlacementAPIList
13+
plural: novaplacementapis
14+
singular: novaplacementapi
15+
scope: Namespaced
16+
versions:
17+
- name: v1beta1
18+
schema:
19+
openAPIV3Schema:
20+
description: NovaPlacementAPI is the Schema for the novaplacementapis API
21+
properties:
22+
apiVersion:
23+
description: |-
24+
APIVersion defines the versioned schema of this representation of an object.
25+
Servers should convert recognized schemas to the latest internal value, and
26+
may reject unrecognized values.
27+
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
28+
type: string
29+
kind:
30+
description: |-
31+
Kind is a string value representing the REST resource this object represents.
32+
Servers may infer this from the endpoint the client submits requests to.
33+
Cannot be updated.
34+
In CamelCase.
35+
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
36+
type: string
37+
metadata:
38+
type: object
39+
spec:
40+
description: NovaPlacementAPISpec defines the desired state of NovaPlacementAPI
41+
properties:
42+
foo:
43+
description: Foo is an example field of NovaPlacementAPI. Edit novaplacementapi_types.go
44+
to remove/update
45+
type: string
46+
type: object
47+
status:
48+
description: NovaPlacementAPIStatus defines the observed state of NovaPlacementAPI
49+
type: object
50+
type: object
51+
served: true
52+
storage: true
53+
subresources:
54+
status: {}

api/v1beta1/common_types.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@ import (
2525

2626
// Container image fall-back defaults
2727
const (
28-
NovaAPIContainerImage = "quay.io/podified-antelope-centos9/openstack-nova-api:current-podified"
29-
NovaConductorContainerImage = "quay.io/podified-antelope-centos9/openstack-nova-conductor:current-podified"
30-
NovaMetadataContainerImage = "quay.io/podified-antelope-centos9/openstack-nova-api:current-podified"
31-
NovaNoVNCContainerImage = "quay.io/podified-antelope-centos9/openstack-nova-novncproxy:current-podified"
32-
NovaSchedulerContainerImage = "quay.io/podified-antelope-centos9/openstack-nova-scheduler:current-podified"
33-
NovaComputeContainerImage = "quay.io/podified-antelope-centos9/openstack-nova-compute:current-podified"
28+
NovaAPIContainerImage = "quay.io/podified-antelope-centos9/openstack-nova-api:current-podified"
29+
NovaConductorContainerImage = "quay.io/podified-antelope-centos9/openstack-nova-conductor:current-podified"
30+
NovaMetadataContainerImage = "quay.io/podified-antelope-centos9/openstack-nova-api:current-podified"
31+
NovaNoVNCContainerImage = "quay.io/podified-antelope-centos9/openstack-nova-novncproxy:current-podified"
32+
NovaSchedulerContainerImage = "quay.io/podified-antelope-centos9/openstack-nova-scheduler:current-podified"
33+
NovaComputeContainerImage = "quay.io/podified-antelope-centos9/openstack-nova-compute:current-podified"
34+
NovaPlacementAPIContainerImage = "quay.io/podified-antelope-centos9/openstack-placement-api:current-podified"
3435
)
3536

3637
// Compute drivers names
Lines changed: 238 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
1+
/*
2+
Copyright 2022.
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 v1beta1
18+
19+
import (
20+
condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition"
21+
"github.com/openstack-k8s-operators/lib-common/modules/common/tls"
22+
corev1 "k8s.io/api/core/v1"
23+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
24+
topologyv1 "github.com/openstack-k8s-operators/infra-operator/apis/topology/v1beta1"
25+
)
26+
27+
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
28+
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
29+
30+
// NovaPlacementAPITemplate defines the input parameters specified by the user to
31+
// create a NovaPlacement via higher level CRDs.
32+
33+
// NovaPlacementAPISpec defines the desired state of NovaPlacementAPI
34+
type NovaPlacementAPISpec struct {
35+
NovaPlacementAPISpecCore `json:",inline"`
36+
37+
// +kubebuilder:validation:Required
38+
//PlacementAPI Container Image URL (will be set to environmental default if empty)
39+
ContainerImage string `json:"containerImage"`
40+
}
41+
42+
// PlacementAPISpecCore -
43+
type PlacementAPISpecCore struct {
44+
// +kubebuilder:validation:Optional
45+
// +kubebuilder:default=60
46+
// +kubebuilder:validation:Minimum=10
47+
// APITimeout for HAProxy, Apache
48+
APITimeout int `json:"apiTimeout"`
49+
50+
// +kubebuilder:validation:Optional
51+
// +kubebuilder:default=placement
52+
// ServiceUser - optional username used for this service to register in keystone
53+
ServiceUser string `json:"serviceUser"`
54+
55+
// +kubebuilder:validation:Required
56+
// MariaDB instance name
57+
// Right now required by the maridb-operator to get the credentials from the instance to create the DB
58+
// Might not be required in future
59+
DatabaseInstance string `json:"databaseInstance"`
60+
61+
// +kubebuilder:validation:Optional
62+
// +kubebuilder:default=placement
63+
// DatabaseAccount - name of MariaDBAccount which will be used to connect.
64+
DatabaseAccount string `json:"databaseAccount"`
65+
66+
// +kubebuilder:validation:Optional
67+
// +kubebuilder:default=1
68+
// +kubebuilder:validation:Maximum=32
69+
// +kubebuilder:validation:Minimum=0
70+
// Replicas of placement API to run
71+
Replicas *int32 `json:"replicas"`
72+
73+
// +kubebuilder:validation:Required
74+
// Secret containing OpenStack password information for placement PlacementPassword
75+
Secret string `json:"secret"`
76+
77+
// +kubebuilder:validation:Optional
78+
// +kubebuilder:default={service: PlacementPassword}
79+
// PasswordSelectors - Selectors to identify the DB and ServiceUser password from the Secret
80+
PasswordSelectors PasswordSelector `json:"passwordSelectors"`
81+
82+
// +kubebuilder:validation:Optional
83+
// NodeSelector to target subset of worker nodes running this service
84+
NodeSelector *map[string]string `json:"nodeSelector,omitempty"`
85+
86+
// +kubebuilder:validation:Optional
87+
// +kubebuilder:default=false
88+
// PreserveJobs - do not delete jobs after they finished e.g. to check logs
89+
PreserveJobs bool `json:"preserveJobs"`
90+
91+
// +kubebuilder:validation:Optional
92+
// CustomServiceConfig - customize the service config using this parameter to change service defaults,
93+
// or overwrite rendered information using raw OpenStack config format. The content gets added to
94+
// to /etc/<service>/<service>.conf.d directory as custom.conf file.
95+
CustomServiceConfig string `json:"customServiceConfig"`
96+
97+
// +kubebuilder:validation:Optional
98+
// DefaultConfigOverwrite - interface to overwrite default config files like policy.yaml.
99+
DefaultConfigOverwrite map[string]string `json:"defaultConfigOverwrite,omitempty"`
100+
101+
// +kubebuilder:validation:Optional
102+
// Resources - Compute Resources required by this service (Limits/Requests).
103+
// https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
104+
Resources corev1.ResourceRequirements `json:"resources,omitempty"`
105+
106+
// +kubebuilder:validation:Optional
107+
// NetworkAttachments is a list of NetworkAttachment resource names to expose the services to the given network
108+
NetworkAttachments []string `json:"networkAttachments,omitempty"`
109+
110+
// +kubebuilder:validation:Optional
111+
// Override, provides the ability to override the generated manifest of several child resources.
112+
Override APIOverrideSpec `json:"override,omitempty"`
113+
114+
// +kubebuilder:validation:Optional
115+
// +operator-sdk:csv:customresourcedefinitions:type=spec
116+
// TLS - Parameters related to the TLS
117+
TLS tls.API `json:"tls,omitempty"`
118+
119+
// +kubebuilder:validation:Optional
120+
// TopologyRef to apply the Topology defined by the associated CR referenced
121+
// by name
122+
TopologyRef *topologyv1.TopoRef `json:"topologyRef,omitempty"`
123+
}
124+
125+
// APIOverrideSpec to override the generated manifest of several child resources.
126+
type APIOverrideSpec struct {
127+
// Override configuration for the Service created to serve traffic to the cluster.
128+
// The key must be the endpoint type (public, internal)
129+
Service map[service.Endpoint]service.RoutedOverrideSpec `json:"service,omitempty"`
130+
}
131+
132+
// PasswordSelector to identify the DB and AdminUser password from the Secret
133+
type PasswordSelector struct {
134+
// +kubebuilder:validation:Optional
135+
// +kubebuilder:default="PlacementPassword"
136+
// Service - Selector to get the service user password from the Secret
137+
Service string `json:"service"`
138+
}
139+
140+
// NovaPlacementAPIStatus defines the observed state of NovaPlacementAPI
141+
type NovaPlacementAPIStatus struct {
142+
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
143+
// Important: Run "make" to regenerate code after modifying this file
144+
// ReadyCount of placement API instances
145+
ReadyCount int32 `json:"readyCount,omitempty"`
146+
147+
// Map of hashes to track e.g. job status
148+
Hash map[string]string `json:"hash,omitempty"`
149+
150+
// Conditions
151+
Conditions condition.Conditions `json:"conditions,omitempty" optional:"true"`
152+
153+
// Placement Database Hostname
154+
DatabaseHostname string `json:"databaseHostname,omitempty"`
155+
156+
// NetworkAttachments status of the deployment pods
157+
NetworkAttachments map[string][]string `json:"networkAttachments,omitempty"`
158+
159+
//ObservedGeneration - the most recent generation observed for this service. If the observed generation is less than the spec generation, then the controller has not processed the latest changes.
160+
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
161+
162+
// LastAppliedTopology - the last applied Topology
163+
LastAppliedTopology *topologyv1.TopoRef `json:"lastAppliedTopology,omitempty"`
164+
}
165+
166+
// NovaPlacementAPI is the Schema for the novaplacementapis API
167+
// +kubebuilder:object:root=true
168+
// +kubebuilder:subresource:status
169+
// +kubebuilder:printcolumn:name="NetworkAttachments",type="string",JSONPath=".spec.networkAttachments",description="NetworkAttachments"
170+
// +kubebuilder:printcolumn:name="Status",type="string",JSONPath=".status.conditions[0].status",description="Status"
171+
// +kubebuilder:printcolumn:name="Message",type="string",JSONPath=".status.conditions[0].message",description="Message"
172+
type NovaPlacementAPI struct {
173+
metav1.TypeMeta `json:",inline"`
174+
metav1.ObjectMeta `json:"metadata,omitempty"`
175+
176+
Spec NovaPlacementAPISpec `json:"spec,omitempty"`
177+
Status NovaPlacementAPIStatus `json:"status,omitempty"`
178+
}
179+
180+
// NovaPlacementAPIList contains a list of NovaPlacementAPI
181+
//+kubebuilder:object:root=true
182+
type NovaPlacementAPIList struct {
183+
metav1.TypeMeta `json:",inline"`
184+
metav1.ListMeta `json:"metadata,omitempty"`
185+
Items []NovaPlacementAPI `json:"items"`
186+
}
187+
188+
func init() {
189+
SchemeBuilder.Register(&NovaPlacementAPI{}, &NovaPlacementAPIList{})
190+
}
191+
192+
// IsReady - returns true if PlacementAPI is reconciled successfully
193+
func (instance PlacementAPI) IsReady() bool {
194+
return instance.Status.Conditions.IsTrue(condition.ReadyCondition)
195+
}
196+
197+
// RbacConditionsSet - set the conditions for the rbac object
198+
func (instance PlacementAPI) RbacConditionsSet(c *condition.Condition) {
199+
instance.Status.Conditions.Set(c)
200+
}
201+
202+
// RbacNamespace - return the namespace
203+
func (instance PlacementAPI) RbacNamespace() string {
204+
return instance.Namespace
205+
}
206+
207+
// RbacResourceName - return the name to be used for rbac objects (serviceaccount, role, rolebinding)
208+
func (instance PlacementAPI) RbacResourceName() string {
209+
return "placement-" + instance.Name
210+
}
211+
212+
// SetupDefaults - initializes any CRD field defaults based on environment variables (the defaulting mechanism itself is implemented via webhooks)
213+
func SetupDefaults() {
214+
// Acquire environmental defaults and initialize Placement defaults with them
215+
placementDefaults := PlacementAPIDefaults{
216+
ContainerImageURL: util.GetEnvVar("RELATED_IMAGE_PLACEMENT_API_IMAGE_URL_DEFAULT", PlacementAPIContainerImage),
217+
APITimeout: 60,
218+
}
219+
220+
SetupPlacementAPIDefaults(placementDefaults)
221+
}
222+
223+
// GetSecret returns the value of the Nova.Spec.Secret
224+
func (instance PlacementAPI) GetSecret() string {
225+
return instance.Spec.Secret
226+
}
227+
228+
// ValidateTopology -
229+
func (instance *PlacementAPISpecCore) ValidateTopology(
230+
basePath *field.Path,
231+
namespace string,
232+
) field.ErrorList {
233+
var allErrs field.ErrorList
234+
allErrs = append(allErrs, topologyv1.ValidateTopologyRef(
235+
instance.TopologyRef,
236+
*basePath.Child("topologyRef"), namespace)...)
237+
return allErrs
238+
}

0 commit comments

Comments
 (0)