...

Source file src/github.com/redhat-developer/odo/pkg/deploy/deploy.go

Documentation: github.com/redhat-developer/odo/pkg/deploy

     1  package deploy
     2  
     3  import (
     4  	"context"
     5  	"path/filepath"
     6  
     7  	"github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
     8  	"github.com/devfile/library/v2/pkg/devfile/parser"
     9  
    10  	"github.com/redhat-developer/odo/pkg/component"
    11  	"github.com/redhat-developer/odo/pkg/configAutomount"
    12  	"github.com/redhat-developer/odo/pkg/devfile/image"
    13  	"github.com/redhat-developer/odo/pkg/kclient"
    14  	"github.com/redhat-developer/odo/pkg/libdevfile"
    15  	odocontext "github.com/redhat-developer/odo/pkg/odo/context"
    16  	"github.com/redhat-developer/odo/pkg/testingutil/filesystem"
    17  )
    18  
    19  type DeployClient struct {
    20  	kubeClient            kclient.ClientInterface
    21  	configAutomountClient configAutomount.Client
    22  	fs                    filesystem.Filesystem
    23  }
    24  
    25  var _ Client = (*DeployClient)(nil)
    26  
    27  func NewDeployClient(kubeClient kclient.ClientInterface, configAutomountClient configAutomount.Client, fs filesystem.Filesystem) *DeployClient {
    28  	return &DeployClient{
    29  		kubeClient:            kubeClient,
    30  		configAutomountClient: configAutomountClient,
    31  		fs:                    fs,
    32  	}
    33  }
    34  
    35  func (o *DeployClient) Deploy(ctx context.Context) error {
    36  	var (
    37  		devfileObj  = odocontext.GetEffectiveDevfileObj(ctx)
    38  		devfilePath = odocontext.GetDevfilePath(ctx)
    39  		path        = filepath.Dir(devfilePath)
    40  	)
    41  
    42  	_, err := libdevfile.ValidateAndGetCommand(*devfileObj, "", v1alpha2.DeployCommandGroupKind)
    43  	if err != nil {
    44  		return err
    45  	}
    46  
    47  	handler := component.NewRunHandler(
    48  		ctx,
    49  		o.kubeClient,
    50  		nil,
    51  		o.configAutomountClient,
    52  		o.fs,
    53  		image.SelectBackend(ctx),
    54  		component.HandlerOptions{
    55  			Devfile: *devfileObj,
    56  			Path:    path,
    57  		},
    58  	)
    59  
    60  	err = o.buildPushAutoImageComponents(handler, *devfileObj)
    61  	if err != nil {
    62  		return err
    63  	}
    64  
    65  	err = o.applyAutoK8sOrOcComponents(handler, *devfileObj)
    66  	if err != nil {
    67  		return err
    68  	}
    69  
    70  	return libdevfile.Deploy(ctx, *devfileObj, handler)
    71  }
    72  
    73  func (o *DeployClient) buildPushAutoImageComponents(handler libdevfile.Handler, devfileObj parser.DevfileObj) error {
    74  	components, err := libdevfile.GetImageComponentsToPushAutomatically(devfileObj)
    75  	if err != nil {
    76  		return err
    77  	}
    78  
    79  	for _, c := range components {
    80  		err = handler.ApplyImage(c)
    81  		if err != nil {
    82  			return err
    83  		}
    84  	}
    85  	return nil
    86  }
    87  
    88  func (o *DeployClient) applyAutoK8sOrOcComponents(handler libdevfile.Handler, devfileObj parser.DevfileObj) error {
    89  	components, err := libdevfile.GetK8sAndOcComponentsToPush(devfileObj, false)
    90  	if err != nil {
    91  		return err
    92  	}
    93  
    94  	for _, c := range components {
    95  		var f func(component2 v1alpha2.Component, kind v1alpha2.CommandGroupKind) error
    96  		if c.Kubernetes != nil {
    97  			f = handler.ApplyKubernetes
    98  		} else if c.Openshift != nil {
    99  			f = handler.ApplyOpenShift
   100  		}
   101  		if f == nil {
   102  			continue
   103  		}
   104  		if err = f(c, v1alpha2.DeployCommandGroupKind); err != nil {
   105  			return err
   106  		}
   107  	}
   108  	return nil
   109  }
   110  

View as plain text