1717
1818package com .cloud .kubernetes .version ;
1919
20+ import java .net .MalformedURLException ;
2021import java .util .ArrayList ;
2122import java .util .List ;
2223
2627import org .apache .cloudstack .api .ApiConstants ;
2728import org .apache .cloudstack .api .command .admin .kubernetes .version .AddKubernetesSupportedVersionCmd ;
2829import org .apache .cloudstack .api .command .admin .kubernetes .version .DeleteKubernetesSupportedVersionCmd ;
30+ import org .apache .cloudstack .api .command .admin .kubernetes .version .GetUploadParamsForKubernetesSupportedVersionCmd ;
2931import org .apache .cloudstack .api .command .admin .kubernetes .version .UpdateKubernetesSupportedVersionCmd ;
3032import org .apache .cloudstack .api .command .user .iso .DeleteIsoCmd ;
33+ import org .apache .cloudstack .api .command .user .iso .GetUploadParamsForIsoCmd ;
3134import org .apache .cloudstack .api .command .user .iso .RegisterIsoCmd ;
3235import org .apache .cloudstack .api .command .user .kubernetes .version .ListKubernetesSupportedVersionsCmd ;
36+ import org .apache .cloudstack .api .response .GetUploadParamsResponse ;
3337import org .apache .cloudstack .api .response .KubernetesSupportedVersionResponse ;
3438import org .apache .cloudstack .api .response .ListResponse ;
3539import org .apache .cloudstack .context .CallContext ;
@@ -162,6 +166,33 @@ private List <KubernetesSupportedVersionVO> filterKubernetesSupportedVersions(Li
162166 return versions ;
163167 }
164168
169+ private GetUploadParamsResponse registerKubernetesVersionIsoForUpload (final Long zoneId , final String versionName , final String isoChecksum ) {
170+ CallContext .register (CallContext .current (), ApiCommandResourceType .Iso );
171+ String isoName = String .format ("%s-Kubernetes-Binaries-ISO" , versionName );
172+ GetUploadParamsForIsoCmd uploadIso = new GetUploadParamsForIsoCmd ();
173+ uploadIso = ComponentContext .inject (uploadIso );
174+ uploadIso .setName (isoName );
175+ uploadIso .setPublicIso (true );
176+ if (zoneId != null ) {
177+ uploadIso .setZoneId (zoneId );
178+ }
179+ uploadIso .setDisplayText (isoName );
180+ uploadIso .setBootable (false );
181+ if (StringUtils .isNotEmpty (isoChecksum )) {
182+ uploadIso .setChecksum (isoChecksum );
183+ }
184+ uploadIso .setAccountName (accountManager .getSystemAccount ().getAccountName ());
185+ uploadIso .setDomainId (accountManager .getSystemAccount ().getDomainId ());
186+ try {
187+ return templateService .registerIsoForPostUpload (uploadIso );
188+ } catch (MalformedURLException | ResourceAllocationException e ) {
189+ logger .error (String .format ("Unable to register binaries ISO for supported kubernetes version, %s" , versionName ), e );
190+ throw new CloudRuntimeException (String .format ("Unable to register binaries ISO for supported kubernetes version, %s" , versionName ), e );
191+ } finally {
192+ CallContext .unregister ();
193+ }
194+ }
195+
165196 private VirtualMachineTemplate registerKubernetesVersionIso (final Long zoneId , final String versionName , final String isoUrl , final String isoChecksum , final boolean directDownload , CPU .CPUArch arch ) throws IllegalAccessException , NoSuchFieldException ,
166197 IllegalArgumentException , ResourceAllocationException {
167198 CallContext .register (CallContext .current (), ApiCommandResourceType .Iso );
@@ -316,23 +347,8 @@ public ListResponse<KubernetesSupportedVersionResponse> listKubernetesSupportedV
316347 return createKubernetesSupportedVersionListResponse (versions , versionsAndCount .second ());
317348 }
318349
319- @ Override
320- @ ActionEvent (eventType = KubernetesVersionEventTypes .EVENT_KUBERNETES_VERSION_ADD ,
321- eventDescription = "Adding Kubernetes supported version" )
322- public KubernetesSupportedVersionResponse addKubernetesSupportedVersion (final AddKubernetesSupportedVersionCmd cmd ) {
323- if (!KubernetesClusterService .KubernetesServiceEnabled .value ()) {
324- throw new CloudRuntimeException ("Kubernetes Service plugin is disabled" );
325- }
326- String name = cmd .getName ();
327- final String semanticVersion = cmd .getSemanticVersion ();
328- final Long zoneId = cmd .getZoneId ();
329- final String isoUrl = cmd .getUrl ();
330- final String isoChecksum = cmd .getChecksum ();
331- final Integer minimumCpu = cmd .getMinimumCpu ();
332- final Integer minimumRamSize = cmd .getMinimumRamSize ();
333- final boolean isDirectDownload = cmd .isDirectDownload ();
334- CPU .CPUArch arch = cmd .getArch ();
335-
350+ private void validateKubernetesSupportedVersion (Long zoneId , String semanticVersion , Integer minimumCpu ,
351+ Integer minimumRamSize , boolean isDirectDownload ) {
336352 if (minimumCpu == null || minimumCpu < KubernetesClusterService .MIN_KUBERNETES_CLUSTER_NODE_CPU ) {
337353 throw new InvalidParameterValueException (String .format ("Invalid value for %s parameter. Minimum %d vCPUs required." , ApiConstants .MIN_CPU_NUMBER , KubernetesClusterService .MIN_KUBERNETES_CLUSTER_NODE_CPU ));
338354 }
@@ -351,6 +367,27 @@ public KubernetesSupportedVersionResponse addKubernetesSupportedVersion(final Ad
351367 throw new InvalidParameterValueException (String .format ("Zone: %s supports only direct download Kubernetes versions" , zone .getName ()));
352368 }
353369 }
370+ }
371+
372+ @ Override
373+ @ ActionEvent (eventType = KubernetesVersionEventTypes .EVENT_KUBERNETES_VERSION_ADD ,
374+ eventDescription = "Adding Kubernetes supported version" )
375+ public KubernetesSupportedVersionResponse addKubernetesSupportedVersion (final AddKubernetesSupportedVersionCmd cmd ) {
376+ if (!KubernetesClusterService .KubernetesServiceEnabled .value ()) {
377+ throw new CloudRuntimeException ("Kubernetes Service plugin is disabled" );
378+ }
379+ String name = cmd .getName ();
380+ final String semanticVersion = cmd .getSemanticVersion ();
381+ final Long zoneId = cmd .getZoneId ();
382+ final String isoUrl = cmd .getUrl ();
383+ final String isoChecksum = cmd .getChecksum ();
384+ final Integer minimumCpu = cmd .getMinimumCpu ();
385+ final Integer minimumRamSize = cmd .getMinimumRamSize ();
386+ final boolean isDirectDownload = cmd .isDirectDownload ();
387+ CPU .CPUArch arch = cmd .getArch ();
388+
389+ validateKubernetesSupportedVersion (zoneId , semanticVersion , minimumCpu , minimumRamSize , isDirectDownload );
390+
354391 if (StringUtils .isEmpty (isoUrl )) {
355392 throw new InvalidParameterValueException (String .format ("Invalid URL for ISO specified, %s" , isoUrl ));
356393 }
@@ -377,6 +414,30 @@ public KubernetesSupportedVersionResponse addKubernetesSupportedVersion(final Ad
377414 return createKubernetesSupportedVersionResponse (supportedVersionVO );
378415 }
379416
417+ @ Override
418+ public GetUploadParamsResponse registerKubernetesSupportedVersionForPostUpload (GetUploadParamsForKubernetesSupportedVersionCmd cmd ) {
419+ if (!KubernetesClusterService .KubernetesServiceEnabled .value ()) {
420+ throw new CloudRuntimeException ("Kubernetes Service plugin is disabled" );
421+ }
422+ String name = cmd .getName ();
423+ final String semanticVersion = cmd .getSemanticVersion ();
424+ final Long zoneId = cmd .getZoneId ();
425+ final String isoChecksum = cmd .getChecksum ();
426+ final Integer minimumCpu = cmd .getMinimumCpu ();
427+ final Integer minimumRamSize = cmd .getMinimumRamSize ();
428+
429+ validateKubernetesSupportedVersion (zoneId , semanticVersion , minimumCpu , minimumRamSize , false );
430+
431+ GetUploadParamsResponse response = registerKubernetesVersionIsoForUpload (zoneId , name , isoChecksum );
432+
433+ VMTemplateVO template = templateDao .findByUuid (response .getId ().toString ());
434+ KubernetesSupportedVersionVO supportedVersionVO = new KubernetesSupportedVersionVO (name , semanticVersion , template .getId (), zoneId , minimumCpu , minimumRamSize );
435+ supportedVersionVO = kubernetesSupportedVersionDao .persist (supportedVersionVO );
436+ CallContext .current ().putContextParameter (KubernetesSupportedVersion .class , supportedVersionVO .getUuid ());
437+
438+ return response ;
439+ }
440+
380441 @ Override
381442 @ ActionEvent (eventType = KubernetesVersionEventTypes .EVENT_KUBERNETES_VERSION_DELETE ,
382443 eventDescription = "deleting Kubernetes supported version" , async = true )
@@ -445,6 +506,7 @@ public List<Class<?>> getCommands() {
445506 return cmdList ;
446507 }
447508 cmdList .add (AddKubernetesSupportedVersionCmd .class );
509+ cmdList .add (GetUploadParamsForKubernetesSupportedVersionCmd .class );
448510 cmdList .add (ListKubernetesSupportedVersionsCmd .class );
449511 cmdList .add (DeleteKubernetesSupportedVersionCmd .class );
450512 cmdList .add (UpdateKubernetesSupportedVersionCmd .class );
0 commit comments