forked from openstack-k8s-operators/osp-director-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[OSPK8-314] Openstack deploy (openstack-k8s-operators#478)
* [OSPK8-314] OpenStackDeploy Implements a new API/Controller to drive the openstack deployment via an operator native workflow.
- Loading branch information
Showing
30 changed files
with
1,357 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
ARG GOLANG_BUILDER=golang:1.16 | ||
ARG OPERATOR_BASE_IMAGE=gcr.io/distroless/base | ||
|
||
# Build the manager binary | ||
FROM $GOLANG_BUILDER AS builder | ||
|
||
#Arguments required by OSBS build system | ||
ARG CACHITO_ENV_FILE=/remote-source/cachito.env | ||
|
||
ARG REMOTE_SOURCE=. | ||
ARG REMOTE_SOURCE_DIR=/remote-source | ||
ARG REMOTE_SOURCE_SUBDIR= | ||
ARG DEST_ROOT=/dest-root | ||
ARG WHAT=osp-director-operator-agent | ||
|
||
ARG GO_BUILD_EXTRA_ARGS= | ||
|
||
COPY $REMOTE_SOURCE $REMOTE_SOURCE_DIR | ||
WORKDIR $REMOTE_SOURCE_DIR/$REMOTE_SOURCE_SUBDIR | ||
|
||
RUN if [ -f $CACHITO_ENV_FILE ] ; then source $CACHITO_ENV_FILE ; fi ; CGO_ENABLED=1 go build ${GO_BUILD_EXTRA_ARGS} -o ${DEST_ROOT}/${WHAT} ./containers/agent | ||
|
||
# Use distroless as minimal base image to package the manager binary | ||
# Refer to https://github.com/GoogleContainerTools/distroless for more details | ||
FROM $OPERATOR_BASE_IMAGE | ||
|
||
# Those arguments must match ones from builder | ||
ARG DEST_ROOT=/dest-root | ||
ARG WHAT=osp-director-operator-agent | ||
|
||
ARG IMAGE_COMPONENT="osp-director-operator-agent-container" | ||
ARG IMAGE_NAME="osp-director-agent-container-container" | ||
ARG IMAGE_VERSION="1.0.0" | ||
ARG IMAGE_SUMMARY="OSP-Director-Operator-agent" | ||
ARG IMAGE_DESC="This is agent that works with the OSP Director Operator" | ||
ARG IMAGE_TAGS="openstack director" | ||
|
||
### DO NOT EDIT LINES BELOW | ||
# Auto generated using CI tools from | ||
# https://github.com/openstack-k8s-operators/openstack-k8s-operators-ci | ||
|
||
# Labels required by upstream and osbs build system | ||
LABEL com.redhat.component="${IMAGE_COMPONENT}" \ | ||
name="${IMAGE_NAME}" \ | ||
version="${IMAGE_VERSION}" \ | ||
summary="${IMAGE_SUMMARY}" \ | ||
io.k8s.name="${IMAGE_NAME}" \ | ||
io.k8s.description="${IMAGE_DESC}" \ | ||
io.openshift.tags="${IMAGE_TAGS}" | ||
### DO NOT EDIT LINES ABOVE | ||
|
||
WORKDIR / | ||
|
||
# Install binary to WORKDIR | ||
COPY --from=builder ${DEST_ROOT}/${WHAT} . | ||
|
||
ENV PATH="/:${PATH}" | ||
|
||
ENTRYPOINT ["/osp-director-operator-agent"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/* | ||
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" | ||
) | ||
|
||
const ( | ||
// | ||
// condition types | ||
// | ||
|
||
// DeployCondTypeWaiting - the deployment is waiting | ||
DeployCondTypeWaiting ProvisioningState = "Waiting" | ||
// DeployCondTypeInitializing - the deployment is waiting | ||
DeployCondTypeInitializing ProvisioningState = "Initializing" | ||
// DeployCondTypeRunning - the deployment is running | ||
DeployCondTypeRunning ProvisioningState = "Running" | ||
// DeployCondTypeFinished - the deploy has finished executing | ||
DeployCondTypeFinished ProvisioningState = "Finished" | ||
// DeployCondTypeError - the deployment hit a generic error | ||
DeployCondTypeError ProvisioningState = "Error" | ||
|
||
// DeployCondReasonJobCreated - job created | ||
DeployCondReasonJobCreated ConditionReason = "JobCreated" | ||
// DeployCondReasonJobCreateFailed - job create failed | ||
DeployCondReasonJobCreateFailed ConditionReason = "JobCreated" | ||
// DeployCondReasonJobDelete - job deleted | ||
DeployCondReasonJobDelete ConditionReason = "JobDeleted" | ||
// DeployCondReasonJobFinished - job deleted | ||
DeployCondReasonJobFinished ConditionReason = "JobFinished" | ||
// DeployCondReasonCVUpdated - error creating/update ConfigVersion | ||
DeployCondReasonCVUpdated ConditionReason = "ConfigVersionUpdated" | ||
// DeployCondReasonConfigVersionNotFound - error finding ConfigVersion | ||
DeployCondReasonConfigVersionNotFound ConditionReason = "ConfigVersionNotFound" | ||
// DeployCondReasonJobFailed - error creating/update CM | ||
DeployCondReasonJobFailed ConditionReason = "JobFailed" | ||
// DeployCondReasonConfigCreate - error creating/update CM | ||
DeployCondReasonConfigCreate ConditionReason = "ConfigCreate" | ||
) | ||
|
||
// OpenStackDeploySpec defines the desired state of OpenStackDeploy | ||
type OpenStackDeploySpec struct { | ||
// Name of the image | ||
ImageURL string `json:"imageURL"` | ||
|
||
// ConfigVersion the config version/git hash of the playbooks to deploy. | ||
ConfigVersion string `json:"configVersion,omitempty"` | ||
|
||
// ConfigGenerator name of the configGenerator | ||
ConfigGenerator string `json:"configGenerator"` | ||
} | ||
|
||
// OpenStackDeployStatus defines the observed state of OpenStackDeploy | ||
type OpenStackDeployStatus struct { | ||
// ConfigVersion hash that has been deployed | ||
ConfigVersion string `json:"configVersion"` | ||
|
||
// CurrentState | ||
CurrentState ProvisioningState `json:"currentState"` | ||
|
||
// CurrentReason | ||
CurrentReason ConditionReason `json:"currentReason"` | ||
|
||
Conditions ConditionList `json:"conditions,omitempty" optional:"true"` | ||
} | ||
|
||
//+kubebuilder:object:root=true | ||
//+kubebuilder:subresource:status | ||
//+kubebuilder:resource:shortName=osdeploy;osdeploys;osdepl | ||
//+operator-sdk:csv:customresourcedefinitions:displayName="OpenStack Deploy" | ||
//+kubebuilder:printcolumn:name="Status",type=string,JSONPath=`.status.currentState`,description="Status" | ||
|
||
// OpenStackDeploy is the Schema for the openstackdeploys API | ||
type OpenStackDeploy struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ObjectMeta `json:"metadata,omitempty"` | ||
|
||
Spec OpenStackDeploySpec `json:"spec,omitempty"` | ||
Status OpenStackDeployStatus `json:"status,omitempty"` | ||
} | ||
|
||
//+kubebuilder:object:root=true | ||
|
||
// OpenStackDeployList contains a list of OpenStackDeploy | ||
type OpenStackDeployList struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ListMeta `json:"metadata,omitempty"` | ||
Items []OpenStackDeploy `json:"items"` | ||
} | ||
|
||
func init() { | ||
SchemeBuilder.Register(&OpenStackDeploy{}, &OpenStackDeployList{}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
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 ( | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
logf "sigs.k8s.io/controller-runtime/pkg/log" | ||
"sigs.k8s.io/controller-runtime/pkg/webhook" | ||
) | ||
|
||
// log is for logging in this package. | ||
var openstackdeploylog = logf.Log.WithName("openstackdeploy-resource") | ||
|
||
// OpenStackDeployDefaults - | ||
type OpenStackDeployDefaults struct { | ||
AgentImageURL string | ||
} | ||
|
||
var openstackDeployDefaults OpenStackDeployDefaults | ||
|
||
// SetupWebhookWithManager - | ||
func (r *OpenStackDeploy) SetupWebhookWithManager(mgr ctrl.Manager, defaults OpenStackDeployDefaults) error { | ||
openstackDeployDefaults = defaults | ||
|
||
return ctrl.NewWebhookManagedBy(mgr). | ||
For(r). | ||
Complete() | ||
} | ||
|
||
//+kubebuilder:webhook:path=/mutate-osp-director-openstack-org-v1beta1-openstackdeploy,mutating=true,failurePolicy=fail,sideEffects=None,groups=osp-director.openstack.org,resources=openstackdeploys,verbs=create;update,versions=v1beta1,name=mopenstackdeploy.kb.io,admissionReviewVersions={v1,v1beta1} | ||
|
||
var _ webhook.Defaulter = &OpenStackDeploy{} | ||
|
||
// Default implements webhook.Defaulter so a webhook will be registered for the type | ||
func (r *OpenStackDeploy) Default() { | ||
openstackdeploylog.Info("default", "name", r.Name) | ||
if r.Spec.ImageURL == "" { | ||
r.Spec.ImageURL = openstackDeployDefaults.AgentImageURL | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.