(dwTemplateSpec *v1alpha2.DevWorkspaceTemplateSpec)
| 143 | } |
| 144 | |
| 145 | func addInitContainer(dwTemplateSpec *v1alpha2.DevWorkspaceTemplateSpec) error { |
| 146 | |
| 147 | if initComponentExists(dwTemplateSpec) { |
| 148 | return fmt.Errorf("component named %s already exists in the devworkspace", constants.HomeInitComponentName) |
| 149 | } |
| 150 | |
| 151 | if initCommandExists(dwTemplateSpec) { |
| 152 | return fmt.Errorf("command with id %s already exists in the devworkspace", constants.HomeInitEventId) |
| 153 | } |
| 154 | |
| 155 | if initEventExists(dwTemplateSpec) { |
| 156 | return fmt.Errorf("event with id %s already exists in the devworkspace", constants.HomeInitEventId) |
| 157 | } |
| 158 | |
| 159 | initContainer := inferInitContainer(dwTemplateSpec) |
| 160 | if initContainer == nil { |
| 161 | return fmt.Errorf("cannot infer initcontainer for home persistence setup") |
| 162 | } |
| 163 | |
| 164 | addInitContainerComponent(dwTemplateSpec, initContainer) |
| 165 | |
| 166 | if dwTemplateSpec.Commands == nil { |
| 167 | dwTemplateSpec.Commands = []v1alpha2.Command{} |
| 168 | } |
| 169 | |
| 170 | if dwTemplateSpec.Events == nil { |
| 171 | dwTemplateSpec.Events = &v1alpha2.Events{} |
| 172 | } |
| 173 | |
| 174 | dwTemplateSpec.Commands = append(dwTemplateSpec.Commands, v1alpha2.Command{ |
| 175 | Id: constants.HomeInitEventId, |
| 176 | CommandUnion: v1alpha2.CommandUnion{ |
| 177 | Apply: &v1alpha2.ApplyCommand{ |
| 178 | Component: constants.HomeInitComponentName, |
| 179 | }, |
| 180 | }, |
| 181 | }) |
| 182 | |
| 183 | dwTemplateSpec.Events.PreStart = append(dwTemplateSpec.Events.PreStart, constants.HomeInitEventId) |
| 184 | |
| 185 | return nil |
| 186 | } |
| 187 | |
| 188 | func initComponentExists(dwTemplateSpec *v1alpha2.DevWorkspaceTemplateSpec) bool { |
| 189 | if dwTemplateSpec.Components == nil { |
no test coverage detected