github.com/1aal/kubeblocks@v0.0.0-20231107070852-e1c03e598921/pkg/cli/create/template/cluster_operations_template.cue (about)

     1  //Copyright (C) 2022-2023 ApeCloud Co., Ltd
     2  //
     3  //This file is part of KubeBlocks project
     4  //
     5  //This program is free software: you can redistribute it and/or modify
     6  //it under the terms of the GNU Affero General Public License as published by
     7  //the Free Software Foundation, either version 3 of the License, or
     8  //(at your option) any later version.
     9  //
    10  //This program is distributed in the hope that it will be useful
    11  //but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13  //GNU Affero General Public License for more details.
    14  //
    15  //You should have received a copy of the GNU Affero General Public License
    16  //along with this program.  If not, see <http://www.gnu.org/licenses/>.
    17  
    18  // required, command line input options for parameters and flags
    19  options: {
    20  	name:                   string
    21  	namespace:              string
    22  	opsRequestName:         string
    23  	type:                   string
    24  	typeLower:              string
    25  	ttlSecondsAfterSucceed: int
    26  	clusterVersionRef:      string
    27  	component:              string
    28  	instance:               string
    29  	componentNames: [...string]
    30  	cpu:    string
    31  	memory: string
    32  	class:  string
    33  	classDefRef: {...}
    34  	replicas: int
    35  	storage:  string
    36  	vctNames: [...string]
    37  	keyValues: [string]: {string | null}
    38  	hasPatch:        bool
    39  	fileContent:     string
    40  	cfgTemplateName: string
    41  	cfgFile:         string
    42  	forceRestart:    bool
    43  	services: [
    44  		...{
    45  			name:        string
    46  			serviceType: string
    47  			annotations: {...}
    48  		},
    49  	]
    50  	...
    51  }
    52  
    53  // define operation block,
    54  #upgrade: {
    55  	clusterVersionRef: options.clusterVersionRef
    56  }
    57  
    58  // required, k8s api resource content
    59  content: {
    60  	apiVersion: "apps.kubeblocks.io/v1alpha1"
    61  	kind:       "OpsRequest"
    62  	metadata: {
    63  		if options.opsRequestName == "" {
    64  			generateName: "\(options.name)-\(options.typeLower)-"
    65  		}
    66  		if options.opsRequestName != "" {
    67  			name: options.opsRequestName
    68  		}
    69  		namespace: options.namespace
    70  	}
    71  	spec: {
    72  		clusterRef:             options.name
    73  		type:                   options.type
    74  		ttlSecondsAfterSucceed: options.ttlSecondsAfterSucceed
    75  		if options.type == "Upgrade" {
    76  			upgrade: #upgrade
    77  		}
    78  		if options.type == "VolumeExpansion" {
    79  			volumeExpansion: [ for _, cName in options.componentNames {
    80  				componentName: cName
    81  				volumeClaimTemplates: [ for _, vctName in options.vctNames {
    82  					name:    vctName
    83  					storage: options.storage
    84  				}]
    85  			}]
    86  		}
    87  		if options.type == "HorizontalScaling" {
    88  			horizontalScaling: [ for _, cName in options.componentNames {
    89  				componentName: cName
    90  				replicas:      options.replicas
    91  			}]
    92  		}
    93  		if options.type == "Restart" {
    94  			restart: [ for _, cName in options.componentNames {
    95  				componentName: cName
    96  			}]
    97  		}
    98  		if options.type == "VerticalScaling" {
    99  			verticalScaling: [ for _, cName in options.componentNames {
   100  				componentName: cName
   101  				if options.class != "" {
   102  					classDefRef: options.classDefRef
   103  				}
   104  				requests: {
   105  					if options.memory != "" {
   106  						memory: options.memory
   107  					}
   108  					if options.cpu != "" {
   109  						cpu: options.cpu
   110  					}
   111  				}
   112  				limits: {
   113  					if options.memory != "" {
   114  						memory: options.memory
   115  					}
   116  					if options.cpu != "" {
   117  						cpu: options.cpu
   118  					}
   119  				}
   120  			}]
   121  		}
   122  		if options.type == "Reconfiguring" {
   123  			reconfigure: {
   124  				componentName: options.componentNames[0]
   125  				configurations: [ {
   126  					name: options.cfgTemplateName
   127  					if options.forceRestart {
   128  						policy: "simple"
   129  					}
   130  					keys: [{
   131  						key: options.cfgFile
   132  						if options.fileContent != "" {
   133  							fileContent: options.fileContent
   134  						}
   135  						if options.hasPatch {
   136  							parameters: [ for k, v in options.keyValues {
   137  								key:   k
   138  								value: v
   139  							}]
   140  						}
   141  					}]
   142  				}]
   143  			}
   144  		}
   145  		if options.type == "Expose" {
   146  			expose: [ for _, cName in options.componentNames {
   147  				componentName: cName
   148  				services: [ for _, svc in options.services {
   149  					name:        svc.name
   150  					serviceType: svc.serviceType
   151  					annotations: svc.annotations
   152  				}]
   153  			}]
   154  		}
   155  		if options.type == "Switchover" {
   156  			switchover: [{
   157  				if options.component == "" {
   158  					componentName: options.componentNames[0]
   159  				}
   160  				if options.component != "" {
   161  					componentName: options.component
   162  				}
   163  				if options.instance == "" {
   164  					instanceName: "*"
   165  				}
   166  				if options.instance != "" {
   167  					instanceName: options.instance
   168  				}
   169  			}]
   170  		}
   171  	}
   172  }