Skip to content

Commit e4045c7

Browse files
authored
[Feature] Optional Action (#1245)
1 parent 78c33e6 commit e4045c7

File tree

8 files changed

+545
-81
lines changed

8 files changed

+545
-81
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- (Maintenance) Fix generated license dates
1111
- (Improvement) Reduce CI on Commit Travis runs
1212
- (Maintenance) Add license range rewrite command
13+
- (Feature) Optional Action
1314

1415
## [1.2.24](https://github.com/arangodb/kube-arangodb/tree/1.2.24) (2023-01-25)
1516
- (Bugfix) Fix deployment creation on ARM64

docs/generated/actions.md

Lines changed: 78 additions & 78 deletions
Large diffs are not rendered by default.

internal/actions.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -70,6 +70,16 @@ func (i ActionsInput) Keys() []string {
7070
return z
7171
}
7272

73+
func (i ActionsInput) Optionals() map[string]bool {
74+
r := map[string]bool{}
75+
76+
for k, v := range i.Actions {
77+
r[k] = v.Optional
78+
}
79+
80+
return r
81+
}
82+
7383
type Scopes struct {
7484
Normal, High, Resource bool
7585
}
@@ -179,6 +189,8 @@ type Action struct {
179189
Enterprise bool `json:"enterprise"`
180190

181191
IsInternal bool `json:"isInternal"`
192+
193+
Optional bool `json:"optional"`
182194
}
183195

184196
func (a Action) InScope(scope string) bool {
@@ -222,6 +234,7 @@ func RenderActions(root string) error {
222234
"internal": in.Internal(),
223235
"timeouts": in.Timeouts(),
224236
"descriptions": in.Descriptions(),
237+
"optionals": in.Optionals(),
225238
"defaultTimeout": fmt.Sprintf("%d * time.Second // %s", in.DefaultTimeout.Duration/time.Second, in.DefaultTimeout.Duration.String()),
226239
}); err != nil {
227240
return err
@@ -274,6 +287,7 @@ func RenderActions(root string) error {
274287
"actions": in.Keys(),
275288
"startupFailureGracePeriods": in.StartFailureGracePeriods(),
276289
"internal": in.Internal(),
290+
"optional": in.Optionals(),
277291
}); err != nil {
278292
return err
279293
}
@@ -300,11 +314,13 @@ func RenderActions(root string) error {
300314
timeout := md.NewColumn("Timeout", md.ColumnCenterAlign)
301315
description := md.NewColumn("Description", md.ColumnCenterAlign)
302316
internal := md.NewColumn("Internal", md.ColumnCenterAlign)
317+
optional := md.NewColumn("Optional", md.ColumnCenterAlign)
303318
edition := md.NewColumn("Edition", md.ColumnCenterAlign)
304319
t := md.NewTable(
305320
action,
306321
internal,
307322
timeout,
323+
optional,
308324
edition,
309325
description,
310326
)
@@ -324,12 +340,17 @@ func RenderActions(root string) error {
324340
if !a.IsInternal {
325341
int = "no"
326342
}
343+
opt := "yes"
344+
if !a.Optional {
345+
opt = "no"
346+
}
327347

328348
if err := t.AddRow(map[md.Column]string{
329349
action: k,
330350
timeout: v,
331351
description: a.Description,
332352
edition: vr,
353+
optional: opt,
333354
internal: int,
334355
}); err != nil {
335356
return err

internal/actions.go.tmpl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,22 @@ func (a ActionType) Internal() bool {
6767
{{- range $key, $value := .internal }}
6868
case ActionType{{ $key }}:
6969
return true
70+
{{- end }}
71+
default:
72+
return false
73+
}
74+
}
75+
76+
// Optional returns true if action execution wont abort Plan
77+
func (a ActionType) Optional() bool {
78+
switch a {
79+
{{- range $key, $value := .optionals }}
80+
case ActionType{{ $key }}:
81+
{{- if $value }}
82+
return true
83+
{{- else }}
84+
return false
85+
{{- end }}
7086
{{- end }}
7187
default:
7288
return false

internal/actions.register.test.go.tmpl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ func Test_Actions(t *testing.T) {
4444
require.True(t, api.ActionType{{ . }}.Internal())
4545
{{- else }}
4646
require.False(t, api.ActionType{{ . }}.Internal())
47+
{{- end }}
48+
})
49+
{{- $isOptional := index $root.optional . }}
50+
t.Run("Optional", func(t *testing.T) {
51+
{{- if $isOptional }}
52+
require.True(t, api.ActionType{{ . }}.Optional())
53+
{{- else }}
54+
require.False(t, api.ActionType{{ . }}.Optional())
4755
{{- end }}
4856
})
4957
})

pkg/apis/deployment/v1/actions.generated.go

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,3 +662,163 @@ func (a ActionType) Internal() bool {
662662
return false
663663
}
664664
}
665+
666+
// Optional returns true if action execution wont abort Plan
667+
func (a ActionType) Optional() bool {
668+
switch a {
669+
case ActionTypeAddMember:
670+
return false
671+
case ActionTypeAppendTLSCACertificate:
672+
return false
673+
case ActionTypeArangoMemberUpdatePodSpec:
674+
return false
675+
case ActionTypeArangoMemberUpdatePodStatus:
676+
return false
677+
case ActionTypeBackupRestore:
678+
return false
679+
case ActionTypeBackupRestoreClean:
680+
return false
681+
case ActionTypeBootstrapSetPassword:
682+
return false
683+
case ActionTypeBootstrapUpdate:
684+
return false
685+
case ActionTypeCleanOutMember:
686+
return false
687+
case ActionTypeCleanTLSCACertificate:
688+
return false
689+
case ActionTypeCleanTLSKeyfileCertificate:
690+
return false
691+
case ActionTypeClusterMemberCleanup:
692+
return false
693+
case ActionTypeDisableClusterScaling:
694+
return false
695+
case ActionTypeDisableMaintenance:
696+
return false
697+
case ActionTypeDisableMemberMaintenance:
698+
return false
699+
case ActionTypeEnableClusterScaling:
700+
return false
701+
case ActionTypeEnableMaintenance:
702+
return false
703+
case ActionTypeEnableMemberMaintenance:
704+
return false
705+
case ActionTypeEncryptionKeyAdd:
706+
return false
707+
case ActionTypeEncryptionKeyPropagated:
708+
return false
709+
case ActionTypeEncryptionKeyRefresh:
710+
return false
711+
case ActionTypeEncryptionKeyRemove:
712+
return false
713+
case ActionTypeEncryptionKeyStatusUpdate:
714+
return false
715+
case ActionTypeIdle:
716+
return false
717+
case ActionTypeJWTAdd:
718+
return false
719+
case ActionTypeJWTClean:
720+
return false
721+
case ActionTypeJWTPropagated:
722+
return false
723+
case ActionTypeJWTRefresh:
724+
return false
725+
case ActionTypeJWTSetActive:
726+
return false
727+
case ActionTypeJWTStatusUpdate:
728+
return false
729+
case ActionTypeKillMemberPod:
730+
return false
731+
case ActionTypeLicenseSet:
732+
return false
733+
case ActionTypeMarkToRemoveMember:
734+
return false
735+
case ActionTypeMemberPhaseUpdate:
736+
return false
737+
case ActionTypeMemberRIDUpdate:
738+
return false
739+
case ActionTypePVCResize:
740+
return false
741+
case ActionTypePVCResized:
742+
return false
743+
case ActionTypePlaceHolder:
744+
return false
745+
case ActionTypeRebalancerCheck:
746+
return false
747+
case ActionTypeRebalancerClean:
748+
return false
749+
case ActionTypeRebalancerGenerate:
750+
return false
751+
case ActionTypeRecreateMember:
752+
return false
753+
case ActionTypeRefreshTLSKeyfileCertificate:
754+
return false
755+
case ActionTypeRemoveMember:
756+
return false
757+
case ActionTypeRenewTLSCACertificate:
758+
return false
759+
case ActionTypeRenewTLSCertificate:
760+
return false
761+
case ActionTypeResignLeadership:
762+
return false
763+
case ActionTypeResourceSync:
764+
return false
765+
case ActionTypeRotateMember:
766+
return false
767+
case ActionTypeRotateStartMember:
768+
return false
769+
case ActionTypeRotateStopMember:
770+
return false
771+
case ActionTypeRuntimeContainerArgsLogLevelUpdate:
772+
return false
773+
case ActionTypeRuntimeContainerImageUpdate:
774+
return false
775+
case ActionTypeRuntimeContainerSyncTolerations:
776+
return false
777+
case ActionTypeSetCondition:
778+
return false
779+
case ActionTypeSetConditionV2:
780+
return false
781+
case ActionTypeSetCurrentImage:
782+
return false
783+
case ActionTypeSetCurrentMemberArch:
784+
return false
785+
case ActionTypeSetMaintenanceCondition:
786+
return false
787+
case ActionTypeSetMemberCondition:
788+
return false
789+
case ActionTypeSetMemberConditionV2:
790+
return false
791+
case ActionTypeSetMemberCurrentImage:
792+
return false
793+
case ActionTypeShutdownMember:
794+
return false
795+
case ActionTypeTLSKeyStatusUpdate:
796+
return false
797+
case ActionTypeTLSPropagated:
798+
return false
799+
case ActionTypeTimezoneSecretSet:
800+
return false
801+
case ActionTypeTopologyDisable:
802+
return false
803+
case ActionTypeTopologyEnable:
804+
return false
805+
case ActionTypeTopologyMemberAssignment:
806+
return false
807+
case ActionTypeTopologyZonesUpdate:
808+
return false
809+
case ActionTypeUpToDateUpdate:
810+
return false
811+
case ActionTypeUpdateTLSSNI:
812+
return false
813+
case ActionTypeUpgradeMember:
814+
return false
815+
case ActionTypeWaitForMemberInSync:
816+
return false
817+
case ActionTypeWaitForMemberReady:
818+
return false
819+
case ActionTypeWaitForMemberUp:
820+
return false
821+
default:
822+
return false
823+
}
824+
}

0 commit comments

Comments
 (0)