From a1eeaace59f1cb2fdd7e91be6d7e1637b9313620 Mon Sep 17 00:00:00 2001 From: Adam Janikowski <12255597+ajanikow@users.noreply.github.com> Date: Wed, 25 Oct 2023 15:33:12 +0200 Subject: [PATCH] [Feature] Add ArangoMember Message and extend ArangoMember CRD (#1464) --- CHANGELOG.md | 1 + .../deployment/v1/arango_member_status.go | 8 +++ .../deployment/v1/zz_generated.deepcopy.go | 1 + .../v2alpha1/arango_member_status.go | 8 +++ .../v2alpha1/zz_generated.deepcopy.go | 1 + .../action_arango_member_update_pod_spec.go | 2 +- .../action_arango_member_update_pod_status.go | 5 +- .../reconcile/action_member_status_sync.go | 20 ++----- .../action_runtime_container_args_udpate.go | 5 +- .../action_runtime_container_image_update.go | 3 +- pkg/deployment/reconcile/helper_member.go | 56 +++++++++++++++++++ 11 files changed, 85 insertions(+), 25 deletions(-) create mode 100644 pkg/deployment/reconcile/helper_member.go diff --git a/CHANGELOG.md b/CHANGELOG.md index f288b4636..9b401de80 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ - (Documentation) Update ArangoDeploymentReplication and ArangoLocalStorage CR auto-generated docs - (Feature) Member Memory Reservation - (Documentation) Update ArangoDeploymentReplication and ArangoLocalStorage CR auto-generated docs +- (Feature) Add ArangoMember Message and extend ArangoMember CRD ## [1.2.34](https://github.com/arangodb/kube-arangodb/tree/1.2.34) (2023-10-16) - (Bugfix) Fix make manifests-crd-file command diff --git a/pkg/apis/deployment/v1/arango_member_status.go b/pkg/apis/deployment/v1/arango_member_status.go index 107f84a10..d4c6a4511 100644 --- a/pkg/apis/deployment/v1/arango_member_status.go +++ b/pkg/apis/deployment/v1/arango_member_status.go @@ -20,10 +20,18 @@ package v1 +import meta "k8s.io/apimachinery/pkg/apis/meta/v1" + type ArangoMemberStatus struct { Conditions ConditionList `json:"conditions,omitempty"` Template *ArangoMemberPodTemplate `json:"template,omitempty"` + + // Message keeps the information about time when ArangoMember Status was modified last time + LastUpdateTime meta.Time `json:"lastUpdateTime,omitempty"` + + // Message keeps the information about ArangoMember Message in the String format + Message string `json:"message,omitempty"` } func (a ArangoMemberStatus) InSync(status MemberStatus) bool { diff --git a/pkg/apis/deployment/v1/zz_generated.deepcopy.go b/pkg/apis/deployment/v1/zz_generated.deepcopy.go index 8ae8fc1e4..9f64c4c42 100644 --- a/pkg/apis/deployment/v1/zz_generated.deepcopy.go +++ b/pkg/apis/deployment/v1/zz_generated.deepcopy.go @@ -599,6 +599,7 @@ func (in *ArangoMemberStatus) DeepCopyInto(out *ArangoMemberStatus) { *out = new(ArangoMemberPodTemplate) (*in).DeepCopyInto(*out) } + in.LastUpdateTime.DeepCopyInto(&out.LastUpdateTime) return } diff --git a/pkg/apis/deployment/v2alpha1/arango_member_status.go b/pkg/apis/deployment/v2alpha1/arango_member_status.go index 4a332c5df..e9a3799f9 100644 --- a/pkg/apis/deployment/v2alpha1/arango_member_status.go +++ b/pkg/apis/deployment/v2alpha1/arango_member_status.go @@ -20,10 +20,18 @@ package v2alpha1 +import meta "k8s.io/apimachinery/pkg/apis/meta/v1" + type ArangoMemberStatus struct { Conditions ConditionList `json:"conditions,omitempty"` Template *ArangoMemberPodTemplate `json:"template,omitempty"` + + // Message keeps the information about time when ArangoMember Status was modified last time + LastUpdateTime meta.Time `json:"lastUpdateTime,omitempty"` + + // Message keeps the information about ArangoMember Message in the String format + Message string `json:"message,omitempty"` } func (a ArangoMemberStatus) InSync(status MemberStatus) bool { diff --git a/pkg/apis/deployment/v2alpha1/zz_generated.deepcopy.go b/pkg/apis/deployment/v2alpha1/zz_generated.deepcopy.go index 523225cd0..6c3a0d1c4 100644 --- a/pkg/apis/deployment/v2alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/deployment/v2alpha1/zz_generated.deepcopy.go @@ -599,6 +599,7 @@ func (in *ArangoMemberStatus) DeepCopyInto(out *ArangoMemberStatus) { *out = new(ArangoMemberPodTemplate) (*in).DeepCopyInto(*out) } + in.LastUpdateTime.DeepCopyInto(&out.LastUpdateTime) return } diff --git a/pkg/deployment/reconcile/action_arango_member_update_pod_spec.go b/pkg/deployment/reconcile/action_arango_member_update_pod_spec.go index 10db963f6..71b3f4f2b 100644 --- a/pkg/deployment/reconcile/action_arango_member_update_pod_spec.go +++ b/pkg/deployment/reconcile/action_arango_member_update_pod_spec.go @@ -130,7 +130,7 @@ func (a *actionArangoMemberUpdatePodSpec) Start(ctx context.Context) (bool, erro return false, err } - if err := inspector.WithArangoMemberStatusUpdate(ctx, cache, name, func(member *api.ArangoMember) (bool, error) { + if err := WithArangoMemberStatusUpdate(ctx, cache, name, func(member *api.ArangoMember) (bool, error) { if (member.Status.Template == nil || member.Status.Template.PodSpec == nil) && (m.Pod == nil || m.Pod.SpecVersion == "" || m.Pod.SpecVersion == template.PodSpecChecksum) { member.Status.Template = template.DeepCopy() } diff --git a/pkg/deployment/reconcile/action_arango_member_update_pod_status.go b/pkg/deployment/reconcile/action_arango_member_update_pod_status.go index e2bff5515..cb3d5cb9b 100644 --- a/pkg/deployment/reconcile/action_arango_member_update_pod_status.go +++ b/pkg/deployment/reconcile/action_arango_member_update_pod_status.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -25,7 +25,6 @@ import ( api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" "github.com/arangodb/kube-arangodb/pkg/util/errors" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector" ) const ( @@ -83,7 +82,7 @@ func (a *actionArangoMemberUpdatePodStatus) Start(ctx context.Context) (bool, er } if member.Status.Template == nil || !member.Status.Template.Equals(member.Spec.Template) { - if err := inspector.WithArangoMemberStatusUpdate(ctx, cache, name, func(in *api.ArangoMember) (bool, error) { + if err := WithArangoMemberStatusUpdate(ctx, cache, name, func(in *api.ArangoMember) (bool, error) { if in.Status.Template == nil || !in.Status.Template.Equals(member.Spec.Template) { in.Status.Template = member.Spec.Template.DeepCopy() return true, nil diff --git a/pkg/deployment/reconcile/action_member_status_sync.go b/pkg/deployment/reconcile/action_member_status_sync.go index c3db75720..f8b84467e 100644 --- a/pkg/deployment/reconcile/action_member_status_sync.go +++ b/pkg/deployment/reconcile/action_member_status_sync.go @@ -23,11 +23,8 @@ package reconcile import ( "context" - meta "k8s.io/apimachinery/pkg/apis/meta/v1" - api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" "github.com/arangodb/kube-arangodb/pkg/util/errors" - "github.com/arangodb/kube-arangodb/pkg/util/globals" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/definitions" ) @@ -77,19 +74,10 @@ func (a *actionMemberStatusSync) Start(ctx context.Context) (bool, error) { return true, nil } - amemberc := amember.DeepCopy() - if amemberc.Status.Propagate(m) { - // Change applied - nctx, c := globals.GetGlobalTimeouts().Kubernetes().WithTimeout(ctx) - defer c() - - if _, err := cache.ArangoMemberModInterface().V1().UpdateStatus(nctx, amemberc, meta.UpdateOptions{}); err != nil { - return false, errors.WithStack(err) - } - - if err := cache.Refresh(nctx); err != nil { - return false, errors.WithStack(err) - } + if err := WithArangoMemberStatusUpdate(ctx, cache, amember.GetName(), func(in *api.ArangoMember) (bool, error) { + return in.Status.Propagate(m), nil + }); err != nil { + return false, errors.WithStack(err) } return true, nil diff --git a/pkg/deployment/reconcile/action_runtime_container_args_udpate.go b/pkg/deployment/reconcile/action_runtime_container_args_udpate.go index 0b3cf469c..e62584ab5 100644 --- a/pkg/deployment/reconcile/action_runtime_container_args_udpate.go +++ b/pkg/deployment/reconcile/action_runtime_container_args_udpate.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -32,7 +32,6 @@ import ( "github.com/arangodb/kube-arangodb/pkg/deployment/rotation" "github.com/arangodb/kube-arangodb/pkg/util/globals" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/definitions" ) @@ -107,7 +106,7 @@ func (a actionRuntimeContainerArgsLogLevelUpdate) Post(ctx context.Context) erro return false, nil } - err := inspector.WithArangoMemberStatusUpdate(ctx, cache, memberName, updateMemberStatusArgs) + err := WithArangoMemberStatusUpdate(ctx, cache, memberName, updateMemberStatusArgs) if err != nil { return errors.WithMessage(err, "Error while updating member status") } diff --git a/pkg/deployment/reconcile/action_runtime_container_image_update.go b/pkg/deployment/reconcile/action_runtime_container_image_update.go index 7381dd602..1508771fc 100644 --- a/pkg/deployment/reconcile/action_runtime_container_image_update.go +++ b/pkg/deployment/reconcile/action_runtime_container_image_update.go @@ -31,7 +31,6 @@ import ( "github.com/arangodb/kube-arangodb/pkg/deployment/rotation" "github.com/arangodb/kube-arangodb/pkg/util/errors" "github.com/arangodb/kube-arangodb/pkg/util/k8sutil" - "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector" ) func newRuntimeContainerImageUpdateAction(action api.Action, actionCtx ActionContext) Action { @@ -121,7 +120,7 @@ func (a actionRuntimeContainerImageUpdate) Post(ctx context.Context) error { return err } - return inspector.WithArangoMemberStatusUpdate(ctx, cache, name, func(in *api.ArangoMember) (bool, error) { + return WithArangoMemberStatusUpdate(ctx, cache, name, func(in *api.ArangoMember) (bool, error) { if in.Spec.Template == nil || in.Status.Template == nil || in.Spec.Template.PodSpec == nil || in.Status.Template.PodSpec == nil { a.log.Info("Nil Member definition") diff --git a/pkg/deployment/reconcile/helper_member.go b/pkg/deployment/reconcile/helper_member.go new file mode 100644 index 000000000..6ef6886c0 --- /dev/null +++ b/pkg/deployment/reconcile/helper_member.go @@ -0,0 +1,56 @@ +// +// DISCLAIMER +// +// Copyright 2023 ArangoDB GmbH, Cologne, Germany +// +// 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. +// +// Copyright holder is ArangoDB GmbH, Cologne, Germany +// + +package reconcile + +import ( + "context" + + meta "k8s.io/apimachinery/pkg/apis/meta/v1" + + api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1" + "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector" +) + +func WithArangoMemberStatusUpdate(ctx context.Context, client inspector.ArangoMemberUpdateInterface, name string, f inspector.ArangoMemberUpdateFunc) error { + return inspector.WithArangoMemberStatusUpdate(ctx, client, name, func(in *api.ArangoMember) (bool, error) { + if changed, err := f(in); err != nil { + return false, err + } else if !changed { + return false, nil + } + + // Update Status + + postArangoMemberStatusUpdate(in) + + return true, nil + }) +} + +func postArangoMemberStatusUpdate(in *api.ArangoMember) { + in.Status.LastUpdateTime = meta.Now() + + if in.Status.Conditions.IsTrue(api.ConditionTypeReady) { + in.Status.Message = "Member is Ready" + } else { + in.Status.Message = "Member is Not Ready" + } +}