Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix remote object sync by multiple Storage and Database objects #195

Merged
merged 12 commits into from
May 1, 2024
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ IMG ?= cr.yandex/yc/ydb-operator:latest
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
CRD_OPTIONS ?= "crd:trivialVersions=true,preserveUnknownFields=false"
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.21
ENVTEST_K8S_VERSION = 1.26

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha1/remotestoragenodeset_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type RemoteStorageNodeSet struct {
Status RemoteStorageNodeSetStatus `json:"status,omitempty"`
}

// DatabaseNodeSetStatus defines the observed state
// StorageNodeSetStatus defines the observed state
type RemoteStorageNodeSetStatus struct {
State constants.ClusterState `json:"state"`
Conditions []metav1.Condition `json:"conditions,omitempty"`
Expand Down
4 changes: 2 additions & 2 deletions deploy/ydb-operator/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.5.5
version: 0.5.6

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "0.5.5"
appVersion: "0.5.6"
2 changes: 1 addition & 1 deletion deploy/ydb-operator/crds/remotestoragenodeset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4498,7 +4498,7 @@ spec:
status:
default:
state: Pending
description: DatabaseNodeSetStatus defines the observed state
description: StorageNodeSetStatus defines the observed state
properties:
conditions:
items:
Expand Down
6 changes: 3 additions & 3 deletions internal/controllers/databasenodeset/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ type Reconciler struct {
// Reconcile is part of the main kubernetes reconciliation loop which aims to
// move the current state of the cluster closer to the desired state.
func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
logger := log.FromContext(ctx)
r.Log = log.FromContext(ctx)

crDatabaseNodeSet := &v1alpha1.DatabaseNodeSet{}
err := r.Get(ctx, req.NamespacedName, crDatabaseNodeSet)
if err != nil {
if apierrors.IsNotFound(err) {
logger.Info("DatabaseNodeSet resource not found")
r.Log.Info("DatabaseNodeSet resource not found")
return ctrl.Result{Requeue: false}, nil
}
logger.Error(err, "unable to get DatabaseNodeSet")
r.Log.Error(err, "unable to get DatabaseNodeSet")
return ctrl.Result{RequeueAfter: DefaultRequeueDelay}, err
}

Expand Down
16 changes: 7 additions & 9 deletions internal/controllers/remotedatabasenodeset/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ type Reconciler struct {
//+kubebuilder:rbac:groups=core,resources=secrets/status,verbs=get;update;patch

func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
logger := log.FromContext(ctx)
r.Log = log.FromContext(ctx)

remoteDatabaseNodeSet := &v1alpha1.RemoteDatabaseNodeSet{}
if err := r.RemoteClient.Get(ctx, req.NamespacedName, remoteDatabaseNodeSet); err != nil {
if apierrors.IsNotFound(err) {
logger.Info("RemoteDatabaseNodeSet resource not found on remote cluster")
r.Log.Info("RemoteDatabaseNodeSet resource not found on remote cluster")
return ctrl.Result{Requeue: false}, nil
}
logger.Error(err, "unable to get RemoteDatabaseNodeSet on remote cluster")
r.Log.Error(err, "unable to get RemoteDatabaseNodeSet on remote cluster")
return ctrl.Result{RequeueAfter: DefaultRequeueDelay}, nil
}

Expand Down Expand Up @@ -225,29 +225,27 @@ func (r *Reconciler) deleteExternalResources(
ctx context.Context,
crRemoteDatabaseNodeSet *v1alpha1.RemoteDatabaseNodeSet,
) error {
logger := log.FromContext(ctx)

databaseNodeSet := &v1alpha1.DatabaseNodeSet{}
if err := r.Client.Get(ctx, types.NamespacedName{
Name: crRemoteDatabaseNodeSet.Name,
Namespace: crRemoteDatabaseNodeSet.Namespace,
}, databaseNodeSet); err != nil {
if apierrors.IsNotFound(err) {
logger.Info("DatabaseNodeSet not found")
r.Log.Info("DatabaseNodeSet not found")
} else {
logger.Error(err, "unable to get DatabaseNodeSet")
r.Log.Error(err, "unable to get DatabaseNodeSet")
return err
}
} else {
if err := r.Client.Delete(ctx, databaseNodeSet); err != nil {
logger.Error(err, "unable to delete DatabaseNodeSet")
r.Log.Error(err, "unable to delete DatabaseNodeSet")
return err
}
}

remoteDatabaseNodeSet := resources.NewRemoteDatabaseNodeSet(crRemoteDatabaseNodeSet)
if _, _, err := r.removeUnusedRemoteObjects(ctx, &remoteDatabaseNodeSet, []client.Object{}); err != nil {
logger.Error(err, "unable to delete unused remote resources")
r.Log.Error(err, "unable to delete unused remote resources")
return err
}

Expand Down
Loading
Loading