github.com/verrazzano/verrazzano@v1.7.0/platform-operator/controllers/configmaps/components/dev_helm_component.go (about)

     1  // Copyright (c) 2023, Oracle and/or its affiliates.
     2  // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
     3  
     4  package components
     5  
     6  import (
     7  	"fmt"
     8  	"github.com/verrazzano/verrazzano/platform-operator/apis/verrazzano/v1alpha1"
     9  	"github.com/verrazzano/verrazzano/platform-operator/constants"
    10  	helmcomp "github.com/verrazzano/verrazzano/platform-operator/controllers/verrazzano/component/helm"
    11  	"github.com/verrazzano/verrazzano/platform-operator/controllers/verrazzano/component/spi"
    12  	"github.com/verrazzano/verrazzano/platform-operator/internal/config"
    13  	v1 "k8s.io/api/core/v1"
    14  	"k8s.io/apimachinery/pkg/runtime"
    15  	"path/filepath"
    16  )
    17  
    18  const (
    19  	devComponentConfigMapKindLabel         = "experimental.verrazzano.io/configmap-kind"
    20  	devComponentConfigMapKindHelmComponent = "HelmComponent"
    21  	devComponentConfigMapKindShimComponent = "ShimComponent"
    22  	devComponentConfigMapAPIVersionLabel   = "experimental.verrazzano.io/configmap-apiversion"
    23  	devComponentConfigMapAPIVersionv1beta2 = "v1beta2"
    24  	componentNameKey                       = "name"
    25  	componentNamespaceKey                  = "namespace"
    26  	chartPathKey                           = "chartPath"
    27  	overridesKey                           = "overrides"
    28  )
    29  
    30  type devComponent struct {
    31  	helmcomp.HelmComponent
    32  }
    33  
    34  var _ spi.Component = devComponent{}
    35  
    36  func newDevHelmComponent(cm *v1.ConfigMap) (devComponent, error) {
    37  	componentName, ok := cm.Data[componentNameKey]
    38  	if !ok {
    39  		return devComponent{}, fmt.Errorf("ConfigMap %s does not contain the name field, cannot reconcile component", cm.Name)
    40  	}
    41  
    42  	componentNamespace, ok := cm.Data[componentNamespaceKey]
    43  	if !ok {
    44  		return devComponent{}, fmt.Errorf("ConfigMap %s does not contain the namespace field, cannot reconcile component %s", cm.Name, componentName)
    45  	}
    46  
    47  	chartPath, ok := cm.Data[chartPathKey]
    48  	if !ok {
    49  		return devComponent{}, fmt.Errorf("ConfigMap %s does not contain the chartPath field, cannot reconcile component %s", cm.Name, componentName)
    50  	}
    51  
    52  	return devComponent{
    53  		helmcomp.HelmComponent{
    54  			ReleaseName:             componentName,
    55  			ChartDir:                filepath.Join(config.GetThirdPartyDir(), chartPath),
    56  			ChartNamespace:          componentNamespace,
    57  			IgnoreNamespaceOverride: true,
    58  			GetInstallOverridesFunc: func(_ runtime.Object) interface{} {
    59  				return []v1alpha1.Overrides{{
    60  					ConfigMapRef: &v1.ConfigMapKeySelector{
    61  						Key: overridesKey,
    62  						LocalObjectReference: v1.LocalObjectReference{
    63  							Name: cm.Name,
    64  						},
    65  					},
    66  				}}
    67  			},
    68  			ImagePullSecretKeyname: constants.GlobalImagePullSecName,
    69  		},
    70  	}, nil
    71  }