Skip to content

[Feature] Compare Generic #1480

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

Merged
merged 3 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- (Documentation) Do not use field type name for field URL hash
- (Maintenance) Bump Go to 1.20.11
- (Feature) License ArangoDeployment Fetcher
- (Feature) K8S Resources Compare Generic

## [1.2.35](https://github.com/arangodb/kube-arangodb/tree/1.2.35) (2023-11-06)
- (Maintenance) Update go-driver to v1.6.0, update IsNotFound() checks
Expand Down
49 changes: 42 additions & 7 deletions pkg/apis/deployment/v1/arango_member_pod_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,6 @@ type ArangoMemberPodTemplate struct {
Endpoint *string `json:"endpoint,omitempty"`
}

func (a *ArangoMemberPodTemplate) GetChecksum() string {
if a == nil {
return ""
}
return a.Checksum
}

func (a *ArangoMemberPodTemplate) Equals(b *ArangoMemberPodTemplate) bool {
if a == nil && b == nil {
return true
Expand Down Expand Up @@ -100,3 +93,45 @@ func (a *ArangoMemberPodTemplate) EqualPodSpecChecksum(checksum string) bool {
}
return checksum == a.PodSpecChecksum
}

func (a *ArangoMemberPodTemplate) GetTemplate() *core.PodTemplateSpec {
if a == nil {
return nil
}
return a.PodSpec.DeepCopy()
}

func (a *ArangoMemberPodTemplate) SetTemplate(t *core.PodTemplateSpec) {
if a == nil {
return
}
a.PodSpec = t.DeepCopy()
}

func (a *ArangoMemberPodTemplate) GetTemplateChecksum() string {
if a == nil {
return ""
}
return a.PodSpecChecksum
}

func (a *ArangoMemberPodTemplate) SetTemplateChecksum(s string) {
if a == nil {
return
}
a.PodSpecChecksum = s
}

func (a *ArangoMemberPodTemplate) SetChecksum(s string) {
if a == nil {
return
}
a.Checksum = s
}

func (a *ArangoMemberPodTemplate) GetChecksum() string {
if a == nil {
return ""
}
return a.Checksum
}
9 changes: 5 additions & 4 deletions pkg/deployment/reconcile/plan_builder_high.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/arangodb/kube-arangodb/pkg/deployment/actions"
"github.com/arangodb/kube-arangodb/pkg/deployment/reconcile/shared"
"github.com/arangodb/kube-arangodb/pkg/deployment/rotation"
"github.com/arangodb/kube-arangodb/pkg/util/compare"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
)

Expand Down Expand Up @@ -231,15 +232,15 @@ func (r *Reconciler) updateMemberRotationConditions(apiObject k8sutil.APIObject,
return nil, err
} else {
switch m {
case rotation.EnforcedRotation:
case compare.EnforcedRotation:
if reason != "" {
r.log.Bool("enforced", true).Info(reason)
} else {
r.log.Bool("enforced", true).Info("Unknown reason")
}
// We need to do enforced rotation
return restartMemberConditionAction(group, member.ID, reason), nil
case rotation.InPlaceRotation:
case compare.InPlaceRotation:
if member.Conditions.IsTrue(api.ConditionTypeUpdateFailed) {
if !(member.Conditions.IsTrue(api.ConditionTypePendingRestart) || member.Conditions.IsTrue(api.ConditionTypeRestart)) {
return api.Plan{pendingRestartMemberConditionAction(group, member.ID, reason)}, nil
Expand All @@ -249,11 +250,11 @@ func (r *Reconciler) updateMemberRotationConditions(apiObject k8sutil.APIObject,
return nil, nil
}
return api.Plan{shared.UpdateMemberConditionActionV2(reason, api.ConditionTypePendingUpdate, group, member.ID, true, reason, "", "")}, nil
case rotation.SilentRotation:
case compare.SilentRotation:
// Propagate changes without restart, but apply plan if required
plan = append(plan, actions.NewAction(api.ActionTypeArangoMemberUpdatePodStatus, group, member, "Propagating status of pod").AddParam(ActionTypeArangoMemberUpdatePodStatusChecksum, checksum))
return plan, nil
case rotation.GracefulRotation:
case compare.GracefulRotation:
if reason != "" {
r.log.Bool("enforced", false).Info(reason)
} else {
Expand Down
3 changes: 2 additions & 1 deletion pkg/deployment/reconcile/plan_builder_rotate_upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"github.com/arangodb/kube-arangodb/pkg/deployment/resources"
"github.com/arangodb/kube-arangodb/pkg/deployment/rotation"
"github.com/arangodb/kube-arangodb/pkg/util"
"github.com/arangodb/kube-arangodb/pkg/util/compare"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
)

Expand Down Expand Up @@ -213,7 +214,7 @@ func (r *Reconciler) createUpdatePlanInternal(apiObject k8sutil.APIObject, spec
if mode, p, checksum, reason, err := rotation.IsRotationRequired(context.ACS(), spec, m.Member, m.Group, p, arangoMember.Spec.Template, arangoMember.Status.Template); err != nil {
r.planLogger.Err(err).Str("member", m.Member.ID).Error("Error while generating update plan")
continue
} else if mode != rotation.InPlaceRotation {
} else if mode != compare.InPlaceRotation {
return api.Plan{
shared.RemoveMemberConditionActionV2(reason, api.ConditionTypePendingUpdate, m.Group, m.Member.ID),
shared.UpdateMemberConditionActionV2(reason, api.ConditionTypeUpdating, m.Group, m.Member.ID, true, reason, "", ""),
Expand Down
31 changes: 16 additions & 15 deletions pkg/deployment/rotation/arangod.go
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -25,36 +25,37 @@ import (

api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
"github.com/arangodb/kube-arangodb/pkg/util"
"github.com/arangodb/kube-arangodb/pkg/util/compare"
)

func podCompare(_ api.DeploymentSpec, _ api.ServerGroup, spec, status *core.PodSpec) comparePodFunc {
return func(builder api.ActionBuilder) (mode Mode, plan api.Plan, err error) {
if spec.SchedulerName != status.SchedulerName {
status.SchedulerName = spec.SchedulerName
mode = mode.And(SilentRotation)
func podCompare(_ api.DeploymentSpec, _ api.ServerGroup, spec, status *core.PodTemplateSpec) compare.Func {
return func(builder api.ActionBuilder) (mode compare.Mode, plan api.Plan, err error) {
if spec.Spec.SchedulerName != status.Spec.SchedulerName {
status.Spec.SchedulerName = spec.Spec.SchedulerName
mode = mode.And(compare.SilentRotation)
}

if !util.CompareInt64p(spec.TerminationGracePeriodSeconds, status.TerminationGracePeriodSeconds) {
status.TerminationGracePeriodSeconds = spec.TerminationGracePeriodSeconds
mode = mode.And(SilentRotation)
if !util.CompareInt64p(spec.Spec.TerminationGracePeriodSeconds, status.Spec.TerminationGracePeriodSeconds) {
status.Spec.TerminationGracePeriodSeconds = spec.Spec.TerminationGracePeriodSeconds
mode = mode.And(compare.SilentRotation)
}

return
}
}

func affinityCompare(_ api.DeploymentSpec, _ api.ServerGroup, spec, status *core.PodSpec) comparePodFunc {
return func(builder api.ActionBuilder) (mode Mode, plan api.Plan, e error) {
if specC, err := util.SHA256FromJSON(spec.Affinity); err != nil {
func affinityCompare(_ api.DeploymentSpec, _ api.ServerGroup, spec, status *core.PodTemplateSpec) compare.Func {
return func(builder api.ActionBuilder) (mode compare.Mode, plan api.Plan, e error) {
if specC, err := util.SHA256FromJSON(spec.Spec.Affinity); err != nil {
e = err
return
} else {
if statusC, err := util.SHA256FromJSON(status.Affinity); err != nil {
if statusC, err := util.SHA256FromJSON(status.Spec.Affinity); err != nil {
e = err
return
} else if specC != statusC {
mode = mode.And(SilentRotation)
status.Affinity = spec.Affinity.DeepCopy()
mode = mode.And(compare.SilentRotation)
status.Spec.Affinity = spec.Spec.Affinity.DeepCopy()
return
} else {
return
Expand Down
Loading