github.com/oam-dev/kubevela@v1.9.11/pkg/resourcekeeper/options.go (about) 1 /* 2 Copyright 2021 The KubeVela Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package resourcekeeper 18 19 import ( 20 "github.com/oam-dev/kubevela/apis/core.oam.dev/v1alpha1" 21 ) 22 23 type rtConfig struct { 24 useRoot bool 25 skipGC bool 26 } 27 28 // MetaOnlyOption record only meta part in resourcetracker, which disables the configuration-drift-prevention 29 type MetaOnlyOption struct{} 30 31 // ApplyToDispatchConfig apply change to dispatch config 32 func (option MetaOnlyOption) ApplyToDispatchConfig(cfg *dispatchConfig) { cfg.metaOnly = true } 33 34 // CreatorOption set the creator of the resource 35 type CreatorOption struct { 36 Creator string 37 } 38 39 // ApplyToDispatchConfig apply change to dispatch config 40 func (option CreatorOption) ApplyToDispatchConfig(cfg *dispatchConfig) { cfg.creator = option.Creator } 41 42 // SkipGCOption marks the recorded resource to skip gc 43 type SkipGCOption struct{} 44 45 // ApplyToDispatchConfig apply change to dispatch config 46 func (option SkipGCOption) ApplyToDispatchConfig(cfg *dispatchConfig) { cfg.skipGC = true } 47 48 // ApplyToDeleteConfig apply change to delete config 49 func (option SkipGCOption) ApplyToDeleteConfig(cfg *deleteConfig) { cfg.skipGC = true } 50 51 // UseRootOption let the recording and management of target resource belongs to the RootRT instead of VersionedRT. This 52 // will let the resource be alive as long as the application is still alive. 53 type UseRootOption struct{} 54 55 // ApplyToDispatchConfig apply change to dispatch config 56 func (option UseRootOption) ApplyToDispatchConfig(cfg *dispatchConfig) { cfg.useRoot = true } 57 58 // ApplyToDeleteConfig apply change to delete config 59 func (option UseRootOption) ApplyToDeleteConfig(cfg *deleteConfig) { cfg.useRoot = true } 60 61 // PassiveGCOption disable the active gc for outdated versions. Old versioned resourcetracker will not be recycled 62 // except all of their managed resources have already been deleted or controlled by later resourcetrackers. 63 type PassiveGCOption struct{} 64 65 // ApplyToGCConfig apply change to gc config 66 func (option PassiveGCOption) ApplyToGCConfig(cfg *gcConfig) { cfg.passive = true } 67 68 // DependencyGCOption recycle the resource in the order of reverse dependency 69 type DependencyGCOption struct{} 70 71 // ApplyToGCConfig apply change to gc config 72 func (option DependencyGCOption) ApplyToGCConfig(cfg *gcConfig) { 73 cfg.order = v1alpha1.OrderDependency 74 } 75 76 // DisableMarkStageGCOption disable the mark stage in gc process (no rt will be marked to be deleted) 77 // this option should be switched on when application workflow is suspending/terminating since workflow is not 78 // finished so outdated versions should be kept 79 type DisableMarkStageGCOption struct{} 80 81 // ApplyToGCConfig apply change to gc config 82 func (option DisableMarkStageGCOption) ApplyToGCConfig(cfg *gcConfig) { cfg.disableMark = true } 83 84 // DisableGCComponentRevisionOption disable the component revision gc process 85 // this option should be switched on when application workflow is suspending/terminating 86 type DisableGCComponentRevisionOption struct{} 87 88 // ApplyToGCConfig apply change to gc config 89 func (option DisableGCComponentRevisionOption) ApplyToGCConfig(cfg *gcConfig) { 90 cfg.disableComponentRevisionGC = true 91 } 92 93 // DisableLegacyGCOption disable garbage collect legacy resourcetrackers 94 type DisableLegacyGCOption struct{} 95 96 // ApplyToGCConfig apply change to gc config 97 func (option DisableLegacyGCOption) ApplyToGCConfig(cfg *gcConfig) { 98 cfg.disableLegacyGC = true 99 } 100 101 // DisableApplicationRevisionGCOption disable garbage collect application revision resourcetrackers 102 type DisableApplicationRevisionGCOption struct{} 103 104 // ApplyToGCConfig apply change to gc config 105 func (option DisableApplicationRevisionGCOption) ApplyToGCConfig(cfg *gcConfig) { 106 cfg.disableApplicationRevisionGC = true 107 } 108 109 // AppRevisionLimitGCOption is the maximum number of application revisions that will be maintained 110 type AppRevisionLimitGCOption int 111 112 // ApplyToGCConfig apply change to gc config 113 func (option AppRevisionLimitGCOption) ApplyToGCConfig(cfg *gcConfig) { 114 cfg.appRevisionLimit = int(option) 115 } 116 117 // GarbageCollectStrategyOption apply garbage collect strategy to resourcetracker recording 118 type GarbageCollectStrategyOption v1alpha1.GarbageCollectStrategy 119 120 func (option GarbageCollectStrategyOption) applyToRTConfig(cfg *rtConfig) { 121 switch v1alpha1.GarbageCollectStrategy(option) { 122 case v1alpha1.GarbageCollectStrategyOnAppUpdate: 123 cfg.skipGC = false 124 cfg.useRoot = false 125 case v1alpha1.GarbageCollectStrategyOnAppDelete: 126 cfg.skipGC = false 127 cfg.useRoot = true 128 case v1alpha1.GarbageCollectStrategyNever: 129 cfg.skipGC = true 130 } 131 } 132 133 // ApplyToDispatchConfig apply change to dispatch config 134 func (option GarbageCollectStrategyOption) ApplyToDispatchConfig(cfg *dispatchConfig) { 135 option.applyToRTConfig(&cfg.rtConfig) 136 } 137 138 // ApplyToDeleteConfig apply change to delete config 139 func (option GarbageCollectStrategyOption) ApplyToDeleteConfig(cfg *deleteConfig) { 140 option.applyToRTConfig(&cfg.rtConfig) 141 }