github.com/loft-sh/loftctl/v2@v2.3.2/pkg/app/app.go (about)

     1  package app
     2  
     3  import (
     4  	managementv1 "github.com/loft-sh/api/v2/pkg/apis/management/v1"
     5  	storagev1 "github.com/loft-sh/api/v2/pkg/apis/storage/v1"
     6  	"strconv"
     7  )
     8  
     9  const (
    10  	// LoftHelmReleaseAppLabel indicates if the helm release was deployed via the loft app store
    11  	LoftHelmReleaseAppLabel = "loft.sh/app"
    12  
    13  	// LoftHelmReleaseAppNameAnnotation indicates if the helm release was deployed via the loft app store
    14  	LoftHelmReleaseAppNameAnnotation = "loft.sh/app-name"
    15  
    16  	// LoftHelmReleaseAppGenerationAnnotation indicates the resource version of the loft app
    17  	LoftHelmReleaseAppGenerationAnnotation = "loft.sh/app-generation"
    18  
    19  	// LoftDefaultSpaceTemplate indicates the default space template on a cluster
    20  	LoftDefaultSpaceTemplate = "space.loft.sh/default-template"
    21  )
    22  
    23  func ConvertAppToHelmTask(app *managementv1.App, namespace string) *storagev1.HelmTask {
    24  	helmTask := &storagev1.HelmTask{
    25  		Type: storagev1.HelmTaskTypeInstall,
    26  		Release: storagev1.HelmTaskRelease{
    27  			Name:      app.Name,
    28  			Namespace: namespace,
    29  			Labels: map[string]string{
    30  				LoftHelmReleaseAppLabel: "true",
    31  			},
    32  			Config: app.Spec.Config,
    33  		},
    34  		StreamContainer: app.Spec.StreamContainer,
    35  	}
    36  	if helmTask.Release.Config.Annotations == nil {
    37  		helmTask.Release.Config.Annotations = map[string]string{}
    38  	}
    39  	
    40  	helmTask.Release.Config.Annotations[LoftHelmReleaseAppNameAnnotation] = app.Name
    41  	helmTask.Release.Config.Annotations[LoftHelmReleaseAppGenerationAnnotation] = strconv.FormatInt(app.Generation, 10)
    42  	
    43  	if app.Spec.Wait {
    44  		helmTask.Args = append(helmTask.Args, "--wait")
    45  	}
    46  	if app.Spec.Timeout != "" {
    47  		helmTask.Args = append(helmTask.Args, "--timeout", app.Spec.Timeout)
    48  	}
    49  	return helmTask
    50  }