forked from RHEcosystemAppEng/dbaas-operator
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
014dad7
commit bdb1212
Showing
9 changed files
with
57 additions
and
58 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -123,7 +123,7 @@ metadata: | |
operators.operatorframework.io/project_layout: go.kubebuilder.io/v3 | ||
repository: https://github.com/RHEcosystemAppEng/dbaas-operator | ||
support: [email protected] | ||
name: dbaas-operator.v0.5.3 | ||
name: dbaas-operator.v0.1.3 | ||
namespace: placeholder | ||
spec: | ||
apiservicedefinitions: {} | ||
|
@@ -461,7 +461,7 @@ spec: | |
valueFrom: | ||
fieldRef: | ||
fieldPath: metadata.namespace | ||
image: quay.io/jianrzha/dbaas-operator:0.5.3 | ||
image: quay.io/ecosystem-appeng/dbaas-operator:v0.1.3 | ||
imagePullPolicy: Always | ||
livenessProbe: | ||
httpGet: | ||
|
@@ -552,7 +552,7 @@ spec: | |
name: Red Hat | ||
url: https://www.redhat.com | ||
replaces: dbaas-operator.v0.1.2 | ||
version: 0.5.3 | ||
version: 0.1.3 | ||
webhookdefinitions: | ||
- admissionReviewVersions: | ||
- v1 | ||
|
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
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 |
---|---|---|
|
@@ -19,16 +19,12 @@ package controllers | |
import ( | ||
"context" | ||
|
||
appv1 "k8s.io/api/apps/v1" | ||
v1 "k8s.io/api/core/v1" | ||
"k8s.io/apimachinery/pkg/api/errors" | ||
apimeta "k8s.io/apimachinery/pkg/api/meta" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/types" | ||
"k8s.io/utils/pointer" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
"sigs.k8s.io/controller-runtime/pkg/controller" | ||
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" | ||
|
||
"github.com/RHEcosystemAppEng/dbaas-operator/api/v1alpha1" | ||
) | ||
|
@@ -49,7 +45,7 @@ type DBaaSInstanceReconciler struct { | |
// For more details, check Reconcile and its Result here: | ||
// - https://pkg.go.dev/sigs.k8s.io/[email protected]/pkg/reconcile | ||
func (r *DBaaSInstanceReconciler) Reconcile(ctx context.Context, req ctrl.Request) (result ctrl.Result, recErr error) { | ||
logger := ctrl.LoggerFrom(ctx, "DBaaS Connection", req.NamespacedName) | ||
logger := ctrl.LoggerFrom(ctx, "DBaaS Instance", req.NamespacedName) | ||
|
||
var instance v1alpha1.DBaaSInstance | ||
if err := r.Get(ctx, req.NamespacedName, &instance); err != nil { | ||
|
@@ -67,15 +63,19 @@ func (r *DBaaSInstanceReconciler) Reconcile(ctx context.Context, req ctrl.Reques | |
var dbaasCond metav1.Condition | ||
// This update will make sure the status is always updated in case of any errors or successful result | ||
defer func(inst *v1alpha1.DBaaSInstance, cond *metav1.Condition) { | ||
if len(dbaasCond.Type) == 0 { | ||
// dbaasCond is not populated or updated. No status update is needed. | ||
return | ||
} | ||
apimeta.SetStatusCondition(&inst.Status.Conditions, *cond) | ||
if err := r.Client.Status().Update(ctx, inst); err != nil { | ||
if errors.IsConflict(err) { | ||
logger.V(1).Info("Connection modified, retry syncing spec") | ||
logger.V(1).Info("Instance modified, retry syncing spec") | ||
// Re-queue and preserve existing recErr | ||
result = ctrl.Result{Requeue: true} | ||
return | ||
} | ||
logger.Error(err, "Could not update connection status") | ||
logger.Error(err, "Could not update instance status") | ||
if recErr == nil { | ||
// There is no existing recErr. Set it to the status update error | ||
recErr = err | ||
|
@@ -85,6 +85,12 @@ func (r *DBaaSInstanceReconciler) Reconcile(ctx context.Context, req ctrl.Reques | |
|
||
var inventory v1alpha1.DBaaSInventory | ||
if err := r.Get(ctx, types.NamespacedName{Namespace: instance.Spec.InventoryRef.Namespace, Name: instance.Spec.InventoryRef.Name}, &inventory); err != nil { | ||
if errors.IsNotFound(err) { | ||
logger.Error(err, "DBaaS Inventory resource not found", "DBaaS Inventory", instance.Spec.InventoryRef) | ||
dbaasCond = metav1.Condition{Type: v1alpha1.DBaaSInstanceReadyType, Status: metav1.ConditionFalse, Reason: v1alpha1.DBaaSInventoryNotFound, Message: err.Error()} | ||
result, recErr = ctrl.Result{}, err | ||
return | ||
} | ||
logger.Error(err, "Error fetching DBaaS Inventory resource reference for DBaaS Connection", "DBaaS Inventory", instance.Spec.InventoryRef) | ||
result, recErr = ctrl.Result{}, err | ||
return | ||
|
@@ -94,6 +100,7 @@ func (r *DBaaSInstanceReconciler) Reconcile(ctx context.Context, req ctrl.Reques | |
if err != nil { | ||
if errors.IsNotFound(err) { | ||
logger.Error(err, "Requested DBaaS Provider is not configured in this environment", "DBaaS Provider", inventory.Spec.ProviderRef) | ||
dbaasCond = metav1.Condition{Type: v1alpha1.DBaaSInstanceReadyType, Status: metav1.ConditionFalse, Reason: v1alpha1.DBaaSProviderNotFound, Message: err.Error()} | ||
result, recErr = ctrl.Result{}, err | ||
return | ||
} | ||
|
@@ -135,55 +142,15 @@ func (r *DBaaSInstanceReconciler) SetupWithManager(mgr ctrl.Manager) (controller | |
Build(r) | ||
} | ||
|
||
func (r *DBaaSInstanceReconciler) deploymentMutateFn(connection *v1alpha1.DBaaSInstance, deployment *appv1.Deployment) controllerutil.MutateFn { | ||
return func() error { | ||
deployment.ObjectMeta.Labels = map[string]string{ | ||
"managed-by": "dbaas-operator", | ||
"owner": connection.Name, | ||
"owner.kind": connection.Kind, | ||
"owner.namespace": connection.Namespace, | ||
} | ||
deployment.Spec = appv1.DeploymentSpec{ | ||
Replicas: pointer.Int32Ptr(0), | ||
Selector: &metav1.LabelSelector{ | ||
MatchLabels: map[string]string{ | ||
"name": "bind-deploy", | ||
}, | ||
}, | ||
Template: v1.PodTemplateSpec{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Labels: map[string]string{ | ||
"name": "bind-deploy", | ||
}, | ||
}, | ||
Spec: v1.PodSpec{ | ||
Containers: []v1.Container{ | ||
{ | ||
Name: "bind-deploy", | ||
Image: "quay.io/ecosystem-appeng/busybox", | ||
ImagePullPolicy: v1.PullIfNotPresent, | ||
Command: []string{"sh", "-c", "echo The app is running! && sleep 3600"}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
deployment.OwnerReferences = nil | ||
if err := ctrl.SetControllerReference(connection, deployment, r.Scheme); err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
} | ||
|
||
// mergeInstanceStatus: merge the status from DBaaSProviderConnection into the current DBaaSInstance status | ||
// mergeInstanceStatus: merge the status from DBaaSProviderInstance into the current DBaaSInstance status | ||
func mergeInstanceStatus(inst *v1alpha1.DBaaSInstance, providerInst *v1alpha1.DBaaSProviderInstance) *metav1.Condition { | ||
cond := apimeta.FindStatusCondition(inst.Status.Conditions, v1alpha1.DBaaSInstanceReadyType) | ||
inst.Status.Phase = providerInst.Status.Phase | ||
providerInst.Status.DeepCopyInto(&inst.Status) | ||
if cond != nil { | ||
inst.Status.Conditions = append(inst.Status.Conditions, *cond) | ||
} | ||
// Update connection status condition (type: DBaaSInstanceReadyType) based on the provider status | ||
// Update instance status condition (type: DBaaSInstanceReadyType) based on the provider status | ||
specSync := apimeta.FindStatusCondition(providerInst.Status.Conditions, v1alpha1.DBaaSInstanceProviderSyncType) | ||
if cond != nil && specSync != nil && specSync.Status == metav1.ConditionTrue { | ||
return &metav1.Condition{Type: v1alpha1.DBaaSInstanceReadyType, Status: metav1.ConditionTrue, Reason: v1alpha1.Ready, Message: v1alpha1.MsgProviderCRStatusSyncDone} | ||
|
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