1717
1818package com .cloud .kubernetes .version ;
1919
20+ import java .net .MalformedURLException ;
2021import java .util .ArrayList ;
2122import java .util .List ;
2223
2728import org .apache .cloudstack .api .ApiConstants ;
2829import org .apache .cloudstack .api .command .admin .kubernetes .version .AddKubernetesSupportedVersionCmd ;
2930import org .apache .cloudstack .api .command .admin .kubernetes .version .DeleteKubernetesSupportedVersionCmd ;
31+ import org .apache .cloudstack .api .command .admin .kubernetes .version .GetUploadParamsForKubernetesSupportedVersionCmd ;
3032import org .apache .cloudstack .api .command .admin .kubernetes .version .UpdateKubernetesSupportedVersionCmd ;
3133import org .apache .cloudstack .api .command .user .iso .DeleteIsoCmd ;
34+ import org .apache .cloudstack .api .command .user .iso .GetUploadParamsForIsoCmd ;
3235import org .apache .cloudstack .api .command .user .iso .RegisterIsoCmd ;
3336import org .apache .cloudstack .api .command .user .kubernetes .version .ListKubernetesSupportedVersionsCmd ;
37+ import org .apache .cloudstack .api .response .GetUploadParamsResponse ;
3438import org .apache .cloudstack .api .response .KubernetesSupportedVersionResponse ;
3539import org .apache .cloudstack .api .response .ListResponse ;
3640import org .apache .cloudstack .context .CallContext ;
@@ -160,6 +164,33 @@ private List <KubernetesSupportedVersionVO> filterKubernetesSupportedVersions(Li
160164 return versions ;
161165 }
162166
167+ private GetUploadParamsResponse registerKubernetesVersionIsoForUpload (final Long zoneId , final String versionName , final String isoChecksum ) {
168+ CallContext .register (CallContext .current (), ApiCommandResourceType .Iso );
169+ String isoName = String .format ("%s-Kubernetes-Binaries-ISO" , versionName );
170+ GetUploadParamsForIsoCmd uploadIso = new GetUploadParamsForIsoCmd ();
171+ uploadIso = ComponentContext .inject (uploadIso );
172+ uploadIso .setName (isoName );
173+ uploadIso .setPublicIso (true );
174+ if (zoneId != null ) {
175+ uploadIso .setZoneId (zoneId );
176+ }
177+ uploadIso .setDisplayText (isoName );
178+ uploadIso .setBootable (false );
179+ if (StringUtils .isNotEmpty (isoChecksum )) {
180+ uploadIso .setChecksum (isoChecksum );
181+ }
182+ uploadIso .setAccountName (accountManager .getSystemAccount ().getAccountName ());
183+ uploadIso .setDomainId (accountManager .getSystemAccount ().getDomainId ());
184+ try {
185+ return templateService .registerIsoForPostUpload (uploadIso );
186+ } catch (MalformedURLException | ResourceAllocationException e ) {
187+ logger .error (String .format ("Unable to register binaries ISO for supported kubernetes version, %s" , versionName ), e );
188+ throw new CloudRuntimeException (String .format ("Unable to register binaries ISO for supported kubernetes version, %s" , versionName ), e );
189+ } finally {
190+ CallContext .unregister ();
191+ }
192+ }
193+
163194 private VirtualMachineTemplate registerKubernetesVersionIso (final Long zoneId , final String versionName , final String isoUrl , final String isoChecksum , final boolean directDownload , CPU .CPUArch arch ) throws IllegalAccessException , NoSuchFieldException ,
164195 IllegalArgumentException , ResourceAllocationException {
165196 CallContext .register (CallContext .current (), ApiCommandResourceType .Iso );
@@ -303,23 +334,8 @@ public ListResponse<KubernetesSupportedVersionResponse> listKubernetesSupportedV
303334 return createKubernetesSupportedVersionListResponse (versions , versionsAndCount .second ());
304335 }
305336
306- @ Override
307- @ ActionEvent (eventType = KubernetesVersionEventTypes .EVENT_KUBERNETES_VERSION_ADD ,
308- eventDescription = "Adding Kubernetes supported version" )
309- public KubernetesSupportedVersionResponse addKubernetesSupportedVersion (final AddKubernetesSupportedVersionCmd cmd ) {
310- if (!KubernetesClusterService .KubernetesServiceEnabled .value ()) {
311- throw new CloudRuntimeException ("Kubernetes Service plugin is disabled" );
312- }
313- String name = cmd .getName ();
314- final String semanticVersion = cmd .getSemanticVersion ();
315- final Long zoneId = cmd .getZoneId ();
316- final String isoUrl = cmd .getUrl ();
317- final String isoChecksum = cmd .getChecksum ();
318- final Integer minimumCpu = cmd .getMinimumCpu ();
319- final Integer minimumRamSize = cmd .getMinimumRamSize ();
320- final boolean isDirectDownload = cmd .isDirectDownload ();
321- CPU .CPUArch arch = cmd .getArch ();
322-
337+ private void validateKubernetesSupportedVersion (Long zoneId , String semanticVersion , Integer minimumCpu ,
338+ Integer minimumRamSize , boolean isDirectDownload ) {
323339 if (minimumCpu == null || minimumCpu < KubernetesClusterService .MIN_KUBERNETES_CLUSTER_NODE_CPU ) {
324340 throw new InvalidParameterValueException (String .format ("Invalid value for %s parameter. Minimum %d vCPUs required." , ApiConstants .MIN_CPU_NUMBER , KubernetesClusterService .MIN_KUBERNETES_CLUSTER_NODE_CPU ));
325341 }
@@ -338,6 +354,27 @@ public KubernetesSupportedVersionResponse addKubernetesSupportedVersion(final Ad
338354 throw new InvalidParameterValueException (String .format ("Zone: %s supports only direct download Kubernetes versions" , zone .getName ()));
339355 }
340356 }
357+ }
358+
359+ @ Override
360+ @ ActionEvent (eventType = KubernetesVersionEventTypes .EVENT_KUBERNETES_VERSION_ADD ,
361+ eventDescription = "Adding Kubernetes supported version" )
362+ public KubernetesSupportedVersionResponse addKubernetesSupportedVersion (final AddKubernetesSupportedVersionCmd cmd ) {
363+ if (!KubernetesClusterService .KubernetesServiceEnabled .value ()) {
364+ throw new CloudRuntimeException ("Kubernetes Service plugin is disabled" );
365+ }
366+ String name = cmd .getName ();
367+ final String semanticVersion = cmd .getSemanticVersion ();
368+ final Long zoneId = cmd .getZoneId ();
369+ final String isoUrl = cmd .getUrl ();
370+ final String isoChecksum = cmd .getChecksum ();
371+ final Integer minimumCpu = cmd .getMinimumCpu ();
372+ final Integer minimumRamSize = cmd .getMinimumRamSize ();
373+ final boolean isDirectDownload = cmd .isDirectDownload ();
374+ CPU .CPUArch arch = cmd .getArch ();
375+
376+ validateKubernetesSupportedVersion (zoneId , semanticVersion , minimumCpu , minimumRamSize , isDirectDownload );
377+
341378 if (StringUtils .isEmpty (isoUrl )) {
342379 throw new InvalidParameterValueException (String .format ("Invalid URL for ISO specified, %s" , isoUrl ));
343380 }
@@ -364,6 +401,30 @@ public KubernetesSupportedVersionResponse addKubernetesSupportedVersion(final Ad
364401 return createKubernetesSupportedVersionResponse (supportedVersionVO );
365402 }
366403
404+ @ Override
405+ public GetUploadParamsResponse registerKubernetesSupportedVersionForPostUpload (GetUploadParamsForKubernetesSupportedVersionCmd cmd ) {
406+ if (!KubernetesClusterService .KubernetesServiceEnabled .value ()) {
407+ throw new CloudRuntimeException ("Kubernetes Service plugin is disabled" );
408+ }
409+ String name = cmd .getName ();
410+ final String semanticVersion = cmd .getSemanticVersion ();
411+ final Long zoneId = cmd .getZoneId ();
412+ final String isoChecksum = cmd .getChecksum ();
413+ final Integer minimumCpu = cmd .getMinimumCpu ();
414+ final Integer minimumRamSize = cmd .getMinimumRamSize ();
415+
416+ validateKubernetesSupportedVersion (zoneId , semanticVersion , minimumCpu , minimumRamSize , false );
417+
418+ GetUploadParamsResponse response = registerKubernetesVersionIsoForUpload (zoneId , name , isoChecksum );
419+
420+ VMTemplateVO template = templateDao .findByUuid (response .getId ().toString ());
421+ KubernetesSupportedVersionVO supportedVersionVO = new KubernetesSupportedVersionVO (name , semanticVersion , template .getId (), zoneId , minimumCpu , minimumRamSize );
422+ supportedVersionVO = kubernetesSupportedVersionDao .persist (supportedVersionVO );
423+ CallContext .current ().putContextParameter (KubernetesSupportedVersion .class , supportedVersionVO .getUuid ());
424+
425+ return response ;
426+ }
427+
367428 @ Override
368429 @ ActionEvent (eventType = KubernetesVersionEventTypes .EVENT_KUBERNETES_VERSION_DELETE ,
369430 eventDescription = "deleting Kubernetes supported version" , async = true )
@@ -432,6 +493,7 @@ public List<Class<?>> getCommands() {
432493 return cmdList ;
433494 }
434495 cmdList .add (AddKubernetesSupportedVersionCmd .class );
496+ cmdList .add (GetUploadParamsForKubernetesSupportedVersionCmd .class );
435497 cmdList .add (ListKubernetesSupportedVersionsCmd .class );
436498 cmdList .add (DeleteKubernetesSupportedVersionCmd .class );
437499 cmdList .add (UpdateKubernetesSupportedVersionCmd .class );
0 commit comments