|
| 1 | +package v1alpha1 |
| 2 | + |
| 3 | +import runtime "k8s.io/apimachinery/pkg/runtime" |
| 4 | + |
| 5 | +// CommandType describes the type of command. |
| 6 | +// Only one of the following command type may be specified. |
| 7 | +// +kubebuilder:validation:Enum=Exec;Apply;VscodeTask;VscodeLaunch;Composite;Custom |
| 8 | +type CommandType string |
| 9 | + |
| 10 | +const ( |
| 11 | + ExecCommandType CommandType = "Exec" |
| 12 | + ApplyCommandType CommandType = "Apply" |
| 13 | + VscodeTaskCommandType CommandType = "VscodeTask" |
| 14 | + VscodeLaunchCommandType CommandType = "VscodeLaunch" |
| 15 | + CompositeCommandType CommandType = "Composite" |
| 16 | + CustomCommandType CommandType = "Custom" |
| 17 | +) |
| 18 | + |
| 19 | +// CommandGroupKind describes the kind of command group. |
| 20 | +// +kubebuilder:validation:Enum=build;run;test;debug |
| 21 | +type CommandGroupKind string |
| 22 | + |
| 23 | +const ( |
| 24 | + BuildCommandGroupKind CommandGroupKind = "build" |
| 25 | + RunCommandGroupKind CommandGroupKind = "run" |
| 26 | + TestCommandGroupKind CommandGroupKind = "test" |
| 27 | + DebugCommandGroupKind CommandGroupKind = "debug" |
| 28 | +) |
| 29 | + |
| 30 | +type CommandGroup struct { |
| 31 | + // Kind of group the command is part of |
| 32 | + Kind CommandGroupKind `json:"kind"` |
| 33 | + |
| 34 | + // +optional |
| 35 | + // Identifies the default command for a given group kind |
| 36 | + IsDefault bool `json:"isDefault,omitempty"` |
| 37 | +} |
| 38 | + |
| 39 | +type BaseCommand struct { |
| 40 | + // Mandatory identifier that allows referencing |
| 41 | + // this command in composite commands, from |
| 42 | + // a parent, or in events. |
| 43 | + Id string `json:"id"` |
| 44 | + |
| 45 | + // +optional |
| 46 | + // Defines the group this command is part of |
| 47 | + Group *CommandGroup `json:"group,omitempty"` |
| 48 | + |
| 49 | + // Optional map of free-form additional command attributes |
| 50 | + Attributes map[string]string `json:"attributes,omitempty"` |
| 51 | +} |
| 52 | + |
| 53 | +type LabeledCommand struct { |
| 54 | + BaseCommand `json:",inline"` |
| 55 | + |
| 56 | + // +optional |
| 57 | + // Optional label that provides a label for this command |
| 58 | + // to be used in Editor UI menus for example |
| 59 | + Label string `json:"label,omitempty"` |
| 60 | +} |
| 61 | + |
| 62 | +// +k8s:openapi-gen=true |
| 63 | +// +union |
| 64 | +type Command struct { |
| 65 | + // Type of workspace command |
| 66 | + // +unionDiscriminator |
| 67 | + // +optional |
| 68 | + CommandType CommandType `json:"commandType,omitempty"` |
| 69 | + |
| 70 | + // CLI Command executed in an existing component container |
| 71 | + // +optional |
| 72 | + Exec *ExecCommand `json:"exec,omitempty"` |
| 73 | + |
| 74 | + // Command that consists in applying a given component definition, |
| 75 | + // typically bound to a workspace event. |
| 76 | + // |
| 77 | + // For example, when an `apply` command is bound to a `preStart` event, |
| 78 | + // and references a `container` component, it will start the container as a |
| 79 | + // K8S initContainer in the workspace POD, unless the component has its |
| 80 | + // `dedicatedPod` field set to `true`. |
| 81 | + // |
| 82 | + // When no `apply` command exist for a given component, |
| 83 | + // it is assumed the component will be applied at workspace start |
| 84 | + // by default. |
| 85 | + // +optional |
| 86 | + Apply *ApplyCommand `json:"apply,omitempty"` |
| 87 | + |
| 88 | + // Command providing the definition of a VsCode Task |
| 89 | + // |
| 90 | + // Deprecated; removed in v1alpha2 |
| 91 | + // +optional |
| 92 | + VscodeTask *VscodeConfigurationCommand `json:"vscodeTask,omitempty"` |
| 93 | + |
| 94 | + // Command providing the definition of a VsCode launch action |
| 95 | + // |
| 96 | + // Deprecated; removed in v1alpha2 |
| 97 | + // +optional |
| 98 | + VscodeLaunch *VscodeConfigurationCommand `json:"vscodeLaunch,omitempty"` |
| 99 | + |
| 100 | + // Composite command that allows executing several sub-commands |
| 101 | + // either sequentially or concurrently |
| 102 | + // +optional |
| 103 | + Composite *CompositeCommand `json:"composite,omitempty"` |
| 104 | + |
| 105 | + // Custom command whose logic is implementation-dependant |
| 106 | + // and should be provided by the user |
| 107 | + // possibly through some dedicated plugin |
| 108 | + // +optional |
| 109 | + Custom *CustomCommand `json:"custom,omitempty"` |
| 110 | +} |
| 111 | + |
| 112 | +type ExecCommand struct { |
| 113 | + LabeledCommand `json:",inline"` |
| 114 | + |
| 115 | + // The actual command-line string |
| 116 | + // |
| 117 | + // Special variables that can be used: |
| 118 | + // |
| 119 | + // - `$PROJECTS_ROOT`: A path where projects sources are mounted |
| 120 | + // |
| 121 | + // - `$PROJECT_SOURCE`: A path to a project source ($PROJECTS_ROOT/<project-name>). If there are multiple projects, this will point to the directory of the first one. |
| 122 | + CommandLine string `json:"commandLine,omitempty"` |
| 123 | + |
| 124 | + // Describes component to which given action relates |
| 125 | + Component string `json:"component,omitempty"` |
| 126 | + |
| 127 | + // Working directory where the command should be executed |
| 128 | + // |
| 129 | + // Special variables that can be used: |
| 130 | + // |
| 131 | + // - `${PROJECTS_ROOT}`: A path where projects sources are mounted |
| 132 | + // |
| 133 | + // - `${PROJECT_SOURCE}`: A path to a project source (${PROJECTS_ROOT}/<project-name>). If there are multiple projects, this will point to the directory of the first one. |
| 134 | + WorkingDir string `json:"workingDir,omitempty"` |
| 135 | + |
| 136 | + // +optional |
| 137 | + // Optional list of environment variables that have to be set |
| 138 | + // before running the command |
| 139 | + Env []EnvVar `json:"env,omitempty" patchStrategy:"merge" patchMergeKey:"name"` |
| 140 | + |
| 141 | + // +optional |
| 142 | + // Whether the command is capable to reload itself when source code changes. |
| 143 | + // If set to `true` the command won't be restarted and it is expected to handle file changes on its own. |
| 144 | + // |
| 145 | + // Default value is `false` |
| 146 | + HotReloadCapable bool `json:"hotReloadCapable,omitempty"` |
| 147 | +} |
| 148 | + |
| 149 | +type ApplyCommand struct { |
| 150 | + LabeledCommand `json:",inline"` |
| 151 | + |
| 152 | + // Describes component that will be applied |
| 153 | + Component string `json:"component,omitempty"` |
| 154 | +} |
| 155 | + |
| 156 | +type CompositeCommand struct { |
| 157 | + LabeledCommand `json:",inline"` |
| 158 | + |
| 159 | + // The commands that comprise this composite command |
| 160 | + Commands []string `json:"commands,omitempty" patchStrategy:"replace"` |
| 161 | + |
| 162 | + // Indicates if the sub-commands should be executed concurrently |
| 163 | + // +optional |
| 164 | + Parallel bool `json:"parallel,omitempty"` |
| 165 | +} |
| 166 | + |
| 167 | +// VscodeConfigurationCommandLocationType describes the type of |
| 168 | +// the location the configuration is fetched from. |
| 169 | +// Only one of the following component type may be specified. |
| 170 | +// +kubebuilder:validation:Enum=Uri;Inlined |
| 171 | +type VscodeConfigurationCommandLocationType string |
| 172 | + |
| 173 | +const ( |
| 174 | + UriVscodeConfigurationCommandLocationType VscodeConfigurationCommandLocationType = "Uri" |
| 175 | + InlinedVscodeConfigurationCommandLocationType VscodeConfigurationCommandLocationType = "Inlined" |
| 176 | +) |
| 177 | + |
| 178 | +// +k8s:openapi-gen=true |
| 179 | +// +union |
| 180 | +type VscodeConfigurationCommandLocation struct { |
| 181 | + // Type of Vscode configuration command location |
| 182 | + // + |
| 183 | + // +unionDiscriminator |
| 184 | + // +optional |
| 185 | + LocationType VscodeConfigurationCommandLocationType `json:"locationType,omitempty"` |
| 186 | + |
| 187 | + // Location as an absolute of relative URI |
| 188 | + // the VsCode configuration will be fetched from |
| 189 | + // +optional |
| 190 | + Uri string `json:"uri,omitempty"` |
| 191 | + |
| 192 | + // Inlined content of the VsCode configuration |
| 193 | + // +optional |
| 194 | + Inlined string `json:"inlined,omitempty"` |
| 195 | +} |
| 196 | + |
| 197 | +type VscodeConfigurationCommand struct { |
| 198 | + BaseCommand `json:",inline"` |
| 199 | + VscodeConfigurationCommandLocation `json:",inline"` |
| 200 | +} |
| 201 | + |
| 202 | +type CustomCommand struct { |
| 203 | + LabeledCommand `json:",inline"` |
| 204 | + |
| 205 | + // Class of command that the associated implementation component |
| 206 | + // should use to process this command with the appropriate logic |
| 207 | + CommandClass string `json:"commandClass"` |
| 208 | + |
| 209 | + // Additional free-form configuration for this custom command |
| 210 | + // that the implementation component will know how to use |
| 211 | + // |
| 212 | + // +kubebuilder:pruning:PreserveUnknownFields |
| 213 | + // +kubebuilder:validation:EmbeddedResource |
| 214 | + EmbeddedResource runtime.RawExtension `json:"embeddedResource"` |
| 215 | +} |
0 commit comments