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 ;
@@ -159,6 +163,33 @@ private List <KubernetesSupportedVersionVO> filterKubernetesSupportedVersions(Li
159163 return versions ;
160164 }
161165
166+ private GetUploadParamsResponse registerKubernetesVersionIsoForUpload (final Long zoneId , final String versionName , final String isoChecksum ) {
167+ CallContext .register (CallContext .current (), ApiCommandResourceType .Iso );
168+ String isoName = String .format ("%s-Kubernetes-Binaries-ISO" , versionName );
169+ GetUploadParamsForIsoCmd uploadIso = new GetUploadParamsForIsoCmd ();
170+ uploadIso = ComponentContext .inject (uploadIso );
171+ uploadIso .setName (isoName );
172+ uploadIso .setPublicIso (true );
173+ if (zoneId != null ) {
174+ uploadIso .setZoneId (zoneId );
175+ }
176+ uploadIso .setDisplayText (isoName );
177+ uploadIso .setBootable (false );
178+ if (StringUtils .isNotEmpty (isoChecksum )) {
179+ uploadIso .setChecksum (isoChecksum );
180+ }
181+ uploadIso .setAccountName (accountManager .getSystemAccount ().getAccountName ());
182+ uploadIso .setDomainId (accountManager .getSystemAccount ().getDomainId ());
183+ try {
184+ return templateService .registerIsoForPostUpload (uploadIso );
185+ } catch (MalformedURLException | ResourceAllocationException e ) {
186+ logger .error (String .format ("Unable to register binaries ISO for supported kubernetes version, %s" , versionName ), e );
187+ throw new CloudRuntimeException (String .format ("Unable to register binaries ISO for supported kubernetes version, %s" , versionName ), e );
188+ } finally {
189+ CallContext .unregister ();
190+ }
191+ }
192+
162193 private VirtualMachineTemplate registerKubernetesVersionIso (final Long zoneId , final String versionName , final String isoUrl , final String isoChecksum , final boolean directDownload ) throws IllegalAccessException , NoSuchFieldException ,
163194 IllegalArgumentException , ResourceAllocationException {
164195 CallContext .register (CallContext .current (), ApiCommandResourceType .Iso );
@@ -301,21 +332,8 @@ public ListResponse<KubernetesSupportedVersionResponse> listKubernetesSupportedV
301332 return createKubernetesSupportedVersionListResponse (versions , versionsAndCount .second ());
302333 }
303334
304- @ Override
305- @ ActionEvent (eventType = KubernetesVersionEventTypes .EVENT_KUBERNETES_VERSION_ADD ,
306- eventDescription = "Adding Kubernetes supported version" )
307- public KubernetesSupportedVersionResponse addKubernetesSupportedVersion (final AddKubernetesSupportedVersionCmd cmd ) {
308- if (!KubernetesClusterService .KubernetesServiceEnabled .value ()) {
309- throw new CloudRuntimeException ("Kubernetes Service plugin is disabled" );
310- }
311- String name = cmd .getName ();
312- final String semanticVersion = cmd .getSemanticVersion ();
313- final Long zoneId = cmd .getZoneId ();
314- final String isoUrl = cmd .getUrl ();
315- final String isoChecksum = cmd .getChecksum ();
316- final Integer minimumCpu = cmd .getMinimumCpu ();
317- final Integer minimumRamSize = cmd .getMinimumRamSize ();
318- final boolean isDirectDownload = cmd .isDirectDownload ();
335+ private void validateKubernetesSupportedVersion (Long zoneId , String semanticVersion , Integer minimumCpu ,
336+ Integer minimumRamSize , boolean isDirectDownload ) {
319337 if (minimumCpu == null || minimumCpu < KubernetesClusterService .MIN_KUBERNETES_CLUSTER_NODE_CPU ) {
320338 throw new InvalidParameterValueException (String .format ("Invalid value for %s parameter. Minimum %d vCPUs required." , ApiConstants .MIN_CPU_NUMBER , KubernetesClusterService .MIN_KUBERNETES_CLUSTER_NODE_CPU ));
321339 }
@@ -334,6 +352,26 @@ public KubernetesSupportedVersionResponse addKubernetesSupportedVersion(final Ad
334352 throw new InvalidParameterValueException (String .format ("Zone: %s supports only direct download Kubernetes versions" , zone .getName ()));
335353 }
336354 }
355+ }
356+
357+ @ Override
358+ @ ActionEvent (eventType = KubernetesVersionEventTypes .EVENT_KUBERNETES_VERSION_ADD ,
359+ eventDescription = "Adding Kubernetes supported version" )
360+ public KubernetesSupportedVersionResponse addKubernetesSupportedVersion (final AddKubernetesSupportedVersionCmd cmd ) {
361+ if (!KubernetesClusterService .KubernetesServiceEnabled .value ()) {
362+ throw new CloudRuntimeException ("Kubernetes Service plugin is disabled" );
363+ }
364+ String name = cmd .getName ();
365+ final String semanticVersion = cmd .getSemanticVersion ();
366+ final Long zoneId = cmd .getZoneId ();
367+ final String isoUrl = cmd .getUrl ();
368+ final String isoChecksum = cmd .getChecksum ();
369+ final Integer minimumCpu = cmd .getMinimumCpu ();
370+ final Integer minimumRamSize = cmd .getMinimumRamSize ();
371+ final boolean isDirectDownload = cmd .isDirectDownload ();
372+
373+ validateKubernetesSupportedVersion (zoneId , semanticVersion , minimumCpu , minimumRamSize , isDirectDownload );
374+
337375 if (StringUtils .isEmpty (isoUrl )) {
338376 throw new InvalidParameterValueException (String .format ("Invalid URL for ISO specified, %s" , isoUrl ));
339377 }
@@ -360,6 +398,30 @@ public KubernetesSupportedVersionResponse addKubernetesSupportedVersion(final Ad
360398 return createKubernetesSupportedVersionResponse (supportedVersionVO );
361399 }
362400
401+ @ Override
402+ public GetUploadParamsResponse registerKubernetesSupportedVersionForPostUpload (GetUploadParamsForKubernetesSupportedVersionCmd cmd ) {
403+ if (!KubernetesClusterService .KubernetesServiceEnabled .value ()) {
404+ throw new CloudRuntimeException ("Kubernetes Service plugin is disabled" );
405+ }
406+ String name = cmd .getName ();
407+ final String semanticVersion = cmd .getSemanticVersion ();
408+ final Long zoneId = cmd .getZoneId ();
409+ final String isoChecksum = cmd .getChecksum ();
410+ final Integer minimumCpu = cmd .getMinimumCpu ();
411+ final Integer minimumRamSize = cmd .getMinimumRamSize ();
412+
413+ validateKubernetesSupportedVersion (zoneId , semanticVersion , minimumCpu , minimumRamSize , false );
414+
415+ GetUploadParamsResponse response = registerKubernetesVersionIsoForUpload (zoneId , name , isoChecksum );
416+
417+ VMTemplateVO template = templateDao .findByUuid (response .getId ().toString ());
418+ KubernetesSupportedVersionVO supportedVersionVO = new KubernetesSupportedVersionVO (name , semanticVersion , template .getId (), zoneId , minimumCpu , minimumRamSize );
419+ supportedVersionVO = kubernetesSupportedVersionDao .persist (supportedVersionVO );
420+ CallContext .current ().putContextParameter (KubernetesSupportedVersion .class , supportedVersionVO .getUuid ());
421+
422+ return response ;
423+ }
424+
363425 @ Override
364426 @ ActionEvent (eventType = KubernetesVersionEventTypes .EVENT_KUBERNETES_VERSION_DELETE ,
365427 eventDescription = "deleting Kubernetes supported version" , async = true )
@@ -428,6 +490,7 @@ public List<Class<?>> getCommands() {
428490 return cmdList ;
429491 }
430492 cmdList .add (AddKubernetesSupportedVersionCmd .class );
493+ cmdList .add (GetUploadParamsForKubernetesSupportedVersionCmd .class );
431494 cmdList .add (ListKubernetesSupportedVersionsCmd .class );
432495 cmdList .add (DeleteKubernetesSupportedVersionCmd .class );
433496 cmdList .add (UpdateKubernetesSupportedVersionCmd .class );
0 commit comments