| 1 |
// Copyright 2019 The Kubernetes Authors. |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
package types |
| 5 |
|
| 6 |
// GenerationBehavior specifies generation behavior of configmaps, secrets and maybe other resources. |
| 7 |
type GenerationBehavior int |
| 8 |
|
| 9 |
const ( |
| 10 |
// BehaviorUnspecified is an Unspecified behavior; typically treated as a Create. |
| 11 |
BehaviorUnspecified GenerationBehavior = iota |
| 12 |
// BehaviorCreate makes a new resource. |
| 13 |
BehaviorCreate |
| 14 |
// BehaviorReplace replaces a resource. |
| 15 |
BehaviorReplace |
| 16 |
// BehaviorMerge attempts to merge a new resource with an existing resource. |
| 17 |
BehaviorMerge |
| 18 |
) |
| 19 |
|
| 20 |
// String converts a GenerationBehavior to a string. |
| 21 |
func (b GenerationBehavior) String() string { |
| 22 |
switch b { |
| 23 |
case BehaviorReplace: |
| 24 |
return "replace" |
| 25 |
case BehaviorMerge: |
| 26 |
return "merge" |
| 27 |
case BehaviorCreate: |
| 28 |
return "create" |
| 29 |
default: |
| 30 |
return "unspecified" |
| 31 |
} |
| 32 |
} |
| 33 |
|
| 34 |
// NewGenerationBehavior converts a string to a GenerationBehavior. |
| 35 |
func NewGenerationBehavior(s string) GenerationBehavior { |
| 36 |
switch s { |
| 37 |
case "replace": |
| 38 |
return BehaviorReplace |
| 39 |
case "merge": |
| 40 |
return BehaviorMerge |
| 41 |
case "create": |
| 42 |
return BehaviorCreate |
| 43 |
default: |
| 44 |
return BehaviorUnspecified |
| 45 |
} |
| 46 |
} |