github.com/oam-dev/kubevela@v1.9.11/vela-templates/definitions/internal/trait/k8s-update-strategy.cue (about)

     1  "k8s-update-strategy": {
     2  	alias: ""
     3  	annotations: {}
     4  	attributes: {
     5  		appliesToWorkloads: ["deployments.apps", "statefulsets.apps", "daemonsets.apps"]
     6  		conflictsWith: []
     7  		podDisruptive:   false
     8  		workloadRefPath: ""
     9  	}
    10  	description: "Set k8s update strategy for Deployment/DaemonSet/StatefulSet"
    11  	labels: {}
    12  	type: "trait"
    13  }
    14  
    15  template: {
    16  	patch: {
    17  		spec: {
    18  			if parameter.targetKind == "Deployment" && parameter.strategy.type != "OnDelete" {
    19  				// +patchStrategy=retainKeys
    20  				strategy: {
    21  					type: parameter.strategy.type
    22  					if parameter.strategy.type == "RollingUpdate" {
    23  						rollingUpdate: {
    24  							maxSurge:       parameter.strategy.rollingStrategy.maxSurge
    25  							maxUnavailable: parameter.strategy.rollingStrategy.maxUnavailable
    26  						}
    27  					}
    28  				}
    29  			}
    30  
    31  			if parameter.targetKind == "StatefulSet" && parameter.strategy.type != "Recreate" {
    32  				// +patchStrategy=retainKeys
    33  				updateStrategy: {
    34  					type: parameter.strategy.type
    35  					if parameter.strategy.type == "RollingUpdate" {
    36  						rollingUpdate: {
    37  							partition: parameter.strategy.rollingStrategy.partition
    38  						}
    39  					}
    40  				}
    41  			}
    42  
    43  			if parameter.targetKind == "DaemonSet" && parameter.strategy.type != "Recreate" {
    44  				// +patchStrategy=retainKeys
    45  				updateStrategy: {
    46  					type: parameter.strategy.type
    47  					if parameter.strategy.type == "RollingUpdate" {
    48  						rollingUpdate: {
    49  							maxSurge:       parameter.strategy.rollingStrategy.maxSurge
    50  							maxUnavailable: parameter.strategy.rollingStrategy.maxUnavailable
    51  						}
    52  					}
    53  				}
    54  			}
    55  
    56  		}}
    57  	parameter: {
    58  		// +usage=Specify the apiVersion of target
    59  		targetAPIVersion: *"apps/v1" | string
    60  		// +usage=Specify the kind of target
    61  		targetKind: *"Deployment" | "StatefulSet" | "DaemonSet"
    62  		// +usage=Specify the strategy of update
    63  		strategy: {
    64  			// +usage=Specify the strategy type
    65  			type: *"RollingUpdate" | "Recreate" | "OnDelete"
    66  			// +usage=Specify the parameters of rollong update strategy
    67  			rollingStrategy?: {
    68  				maxSurge:       *"25%" | string
    69  				maxUnavailable: *"25%" | string
    70  				partition:      *0 | int
    71  			}
    72  		}
    73  	}
    74  }