diff --git a/pkg/devfile/adapters/common/apply.go b/pkg/devfile/adapters/common/apply.go deleted file mode 100644 index 15eb4f53b6d..00000000000 --- a/pkg/devfile/adapters/common/apply.go +++ /dev/null @@ -1,7 +0,0 @@ -package common - -// ApplyClient is a wrapper around ApplyComponent which runs an apply command on a component -type ApplyClient interface { - ApplyComponent(component string) error - UnApplyComponent(component string) error -} diff --git a/pkg/devfile/adapters/common/command.go b/pkg/devfile/adapters/common/command.go index 6443afe24e0..3d8e1638dd8 100644 --- a/pkg/devfile/adapters/common/command.go +++ b/pkg/devfile/adapters/common/command.go @@ -43,7 +43,7 @@ func New(devfile devfilev1.Command, knowCommands map[string]devfilev1.Command, e } else if devfile.Exec != nil { return newExecCommand(devfile, executor) } else { - return newApplyCommand(devfile, executor) + return nil, errors.New("apply command not implemented") } } diff --git a/pkg/devfile/adapters/common/command_apply.go b/pkg/devfile/adapters/common/command_apply.go deleted file mode 100644 index f6f22ba1575..00000000000 --- a/pkg/devfile/adapters/common/command_apply.go +++ /dev/null @@ -1,32 +0,0 @@ -package common - -import ( - devfilev1 "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2" -) - -// applyCommand is a command implementation for Apply commands -type applyCommand struct { - adapter commandExecutor - id string - component string -} - -// newApplyCommand creates a new applyCommand instance, adapting the devfile-defined command to run in the target component's container -func newApplyCommand(command devfilev1.Command, executor commandExecutor) (command, error) { - apply := command.Apply - return &applyCommand{ - adapter: executor, - id: command.Id, - component: apply.Component, - }, nil -} - -func (s applyCommand) Execute(show bool) error { - err := s.adapter.ApplyComponent(s.component) - return err -} - -func (s applyCommand) UnExecute() error { - err := s.adapter.UnApplyComponent(s.component) - return err -} diff --git a/pkg/devfile/adapters/common/executor.go b/pkg/devfile/adapters/common/executor.go index b71f2e83888..4f9eac40d67 100644 --- a/pkg/devfile/adapters/common/executor.go +++ b/pkg/devfile/adapters/common/executor.go @@ -8,7 +8,6 @@ import ( // commandExecutor defines the interface adapters must implement to be able to execute commands in a generic way type commandExecutor interface { ExecClient - ApplyClient // Logger returns the MachineEventLoggingClient associated with this executor Logger() machineoutput.MachineEventLoggingClient // ComponentInfo retrieves the component information associated with the specified command diff --git a/pkg/devfile/adapters/common/generic.go b/pkg/devfile/adapters/common/generic.go index b1f6be0da96..7c0faec0d10 100644 --- a/pkg/devfile/adapters/common/generic.go +++ b/pkg/devfile/adapters/common/generic.go @@ -166,11 +166,3 @@ func (a GenericAdapter) addToComposite(commandsMap PushCommandsMap, groupType de } return commands, nil } - -func (a GenericAdapter) ApplyComponent(component string) error { - return nil -} - -func (a GenericAdapter) UnApplyComponent(component string) error { - return nil -} diff --git a/pkg/devfile/adapters/common/interface.go b/pkg/devfile/adapters/common/interface.go index 26d8f375ad0..6e0a5509e77 100644 --- a/pkg/devfile/adapters/common/interface.go +++ b/pkg/devfile/adapters/common/interface.go @@ -6,7 +6,6 @@ import ( // ComponentAdapter defines the functions that platform-specific adapters must implement type ComponentAdapter interface { - commandExecutor Push(parameters PushParameters) error CheckSupervisordCommandStatus(command devfilev1.Command) error } diff --git a/pkg/devfile/adapters/kubernetes/adapter.go b/pkg/devfile/adapters/kubernetes/adapter.go index 5022d7dfeb6..51c78569bfc 100644 --- a/pkg/devfile/adapters/kubernetes/adapter.go +++ b/pkg/devfile/adapters/kubernetes/adapter.go @@ -1,11 +1,8 @@ package kubernetes import ( - "io" - devfilev1 "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2" "github.com/redhat-developer/odo/pkg/kclient" - "github.com/redhat-developer/odo/pkg/machineoutput" "github.com/redhat-developer/odo/pkg/preference" "github.com/pkg/errors" @@ -52,26 +49,3 @@ func (k Adapter) CheckSupervisordCommandStatus(command devfilev1.Command) error return nil } - -func (k Adapter) ExecCMDInContainer(info common.ComponentInfo, cmd []string, stdOut io.Writer, stdErr io.Writer, stdIn io.Reader, show bool) error { - return k.componentAdapter.ExecCMDInContainer(info, cmd, stdOut, stdErr, stdIn, show) -} -func (k Adapter) Logger() machineoutput.MachineEventLoggingClient { - return k.componentAdapter.Logger() -} - -func (k Adapter) ComponentInfo(command devfilev1.Command) (common.ComponentInfo, error) { - return k.componentAdapter.ComponentInfo(command) -} - -func (k Adapter) SupervisorComponentInfo(command devfilev1.Command) (common.ComponentInfo, error) { - return k.componentAdapter.SupervisorComponentInfo(command) -} - -func (k Adapter) ApplyComponent(component string) error { - return k.componentAdapter.ApplyComponent(component) -} - -func (k Adapter) UnApplyComponent(component string) error { - return k.componentAdapter.UnApplyComponent(component) -} diff --git a/pkg/devfile/adapters/kubernetes/component/adapter.go b/pkg/devfile/adapters/kubernetes/component/adapter.go index 9dfd24e68f0..68727276e8e 100644 --- a/pkg/devfile/adapters/kubernetes/component/adapter.go +++ b/pkg/devfile/adapters/kubernetes/component/adapter.go @@ -645,59 +645,6 @@ func getFirstContainerWithSourceVolume(containers []corev1.Container) (string, s return "", "", fmt.Errorf("in order to sync files, odo requires at least one component in a devfile to set 'mountSources: true'") } -/* -// Delete deletes the component -func (a Adapter) Delete(labels map[string]string, show bool, wait bool) error { - if labels == nil { - return fmt.Errorf("cannot delete with labels being nil") - } - log.Printf("Gathering information for component: %q", a.ComponentName) - podSpinner := log.Spinner("Checking status for component") - defer podSpinner.End(false) - - pod, err := component.GetOnePod(a.Client, a.ComponentName, a.AppName) - if kerrors.IsForbidden(err) { - klog.V(2).Infof("Resource for %s forbidden", a.ComponentName) - // log the error if it failed to determine if the component exists due to insufficient RBACs - podSpinner.End(false) - log.Warningf("%v", err) - return nil - } else if e, ok := err.(*kclient.PodNotFoundError); ok { - podSpinner.End(false) - log.Warningf("%v", e) - return nil - } else if err != nil { - return errors.Wrapf(err, "unable to determine if component %s exists", a.ComponentName) - } - - podSpinner.End(true) - - // if there are preStop events, execute them before deleting the deployment - if libdevfile.HasPreStopEvents(a.Devfile) { - if pod.Status.Phase != corev1.PodRunning { - return fmt.Errorf("unable to execute preStop events, pod for component %s is not running", a.ComponentName) - } - log.Infof("\nExecuting %s event commands for component %s", libdevfile.PreStop, a.ComponentName) - err = libdevfile.ExecPreStopEvents(a.Devfile, a.ComponentName, newExecHandler(a.Client, pod.Name, show)) - if err != nil { - return err - } - } - - log.Infof("\nDeleting component %s", a.ComponentName) - spinner := log.Spinner("Deleting Kubernetes resources for component") - defer spinner.End(false) - - err = a.Client.Delete(labels, wait) - if err != nil { - return err - } - - spinner.End(true) - log.Successf("Successfully deleted component") - return nil -}*/ - func (a Adapter) ExecCMDInContainer(componentInfo common.ComponentInfo, cmd []string, stdout io.Writer, stderr io.Writer, stdin io.Reader, tty bool) error { return a.Client.ExecCMDInContainer(componentInfo.ContainerName, componentInfo.PodName, cmd, stdout, stderr, stdin, tty) } @@ -706,47 +653,3 @@ func (a Adapter) ExecCMDInContainer(componentInfo common.ComponentInfo, cmd []st func (a Adapter) ExtractProjectToComponent(componentInfo common.ComponentInfo, targetPath string, stdin io.Reader) error { return a.Client.ExtractProjectToComponent(componentInfo.ContainerName, componentInfo.PodName, targetPath, stdin) } - -// ApplyComponent 'applies' a devfile component -func (a Adapter) ApplyComponent(componentName string) error { - cmp, err := a.getApplyComponent(componentName) - if err != nil { - return err - } - - return cmp.Apply(a.Devfile, a.Context) -} - -// UnApplyComponent un-'applies' a devfile component -func (a Adapter) UnApplyComponent(componentName string) error { - cmp, err := a.getApplyComponent(componentName) - if err != nil { - return err - } - return cmp.UnApply(a.Context) -} - -// getApplyComponent returns the 'Apply' command's component(kubernetes/image) -func (a Adapter) getApplyComponent(componentName string) (componentToApply, error) { - components, err := a.Devfile.Data.GetComponents(parsercommon.DevfileOptions{}) - if err != nil { - return nil, err - } - var component devfilev1.Component - var found bool - for _, component = range components { - if component.Name == componentName { - found = true - break - } - } - if !found { - return nil, fmt.Errorf("component %q not found", componentName) - } - - cmp, err := createComponent(a, component) - if err != nil { - return nil, err - } - return cmp, nil -} diff --git a/pkg/devfile/adapters/kubernetes/component/component.go b/pkg/devfile/adapters/kubernetes/component/component.go deleted file mode 100644 index d750b4b81ba..00000000000 --- a/pkg/devfile/adapters/kubernetes/component/component.go +++ /dev/null @@ -1,24 +0,0 @@ -package component - -import ( - "fmt" - - devfilev1 "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2" - "github.com/devfile/library/pkg/devfile/parser" -) - -// componentToApply represents a devfile component that can be applied -type componentToApply interface { - Apply(devfileObj parser.DevfileObj, devfilePath string) error - UnApply(devfilePath string) error -} - -// createComponent returns an instance of a devfile component specific to its type (image, kubernetes, etc) -func createComponent(adapter Adapter, component devfilev1.Component) (componentToApply, error) { - if component.Image != nil { - return newComponentImage(component), nil - } else if component.Kubernetes != nil { - return newComponentKubernetes(adapter.Client, component, adapter.ComponentName, adapter.AppName), nil - } - return nil, fmt.Errorf("component type not supported for component %q", component.Name) -} diff --git a/pkg/devfile/adapters/kubernetes/component/component_image.go b/pkg/devfile/adapters/kubernetes/component/component_image.go deleted file mode 100644 index b5317908905..00000000000 --- a/pkg/devfile/adapters/kubernetes/component/component_image.go +++ /dev/null @@ -1,25 +0,0 @@ -package component - -import ( - devfilev1 "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2" - "github.com/devfile/library/pkg/devfile/parser" - "github.com/redhat-developer/odo/pkg/devfile/image" -) - -// componentImage represents a devfile component of type Image -type componentImage struct { - component devfilev1.Component -} - -func newComponentImage(component devfilev1.Component) componentImage { - return componentImage{component: component} -} - -// Apply a component of type Image by building and pushing the image -func (o componentImage) Apply(devfileObj parser.DevfileObj, devfilePath string) error { - return image.BuildPushSpecificImage(devfileObj, devfilePath, o.component, true) -} - -func (o componentImage) UnApply(devfilePath string) error { - return nil -} diff --git a/pkg/devfile/adapters/kubernetes/component/component_kubernetes.go b/pkg/devfile/adapters/kubernetes/component/component_kubernetes.go deleted file mode 100644 index 3e8d37a1304..00000000000 --- a/pkg/devfile/adapters/kubernetes/component/component_kubernetes.go +++ /dev/null @@ -1,74 +0,0 @@ -package component - -import ( - "strings" - - devfilev1 "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2" - "github.com/devfile/library/pkg/devfile/parser" - devfilefs "github.com/devfile/library/pkg/testingutil/filesystem" - "github.com/pkg/errors" - componentlabels "github.com/redhat-developer/odo/pkg/component/labels" - "github.com/redhat-developer/odo/pkg/kclient" - "github.com/redhat-developer/odo/pkg/log" - "github.com/redhat-developer/odo/pkg/service" -) - -// componentKubernetes represents a devfile component of type Kubernetes -type componentKubernetes struct { - client kclient.ClientInterface - component devfilev1.Component - componentName string - appName string -} - -func newComponentKubernetes(client kclient.ClientInterface, component devfilev1.Component, componentName string, appName string) componentKubernetes { - return componentKubernetes{ - client: client, - component: component, - componentName: componentName, - appName: appName, - } -} - -// Apply a component of type Kubernetes by creating resources into a Kubernetes cluster -func (o componentKubernetes) Apply(devfileObj parser.DevfileObj, devfilePath string) error { - // validate if the GVRs represented by Kubernetes inlined components are supported by the underlying cluster - _, err := service.ValidateResourceExist(o.client, o.component, devfilePath) - if err != nil { - return err - } - - labels := componentlabels.GetLabels(o.componentName, o.appName, true) - u, err := service.GetK8sComponentAsUnstructured(o.component.Kubernetes, devfilePath, devfilefs.DefaultFs{}) - if err != nil { - return err - } - - log.Infof("\nDeploying Kubernetes %s: %s", u.GetKind(), u.GetName()) - isOperatorBackedService, err := service.PushKubernetesResource(o.client, u, labels) - if err != nil { - return errors.Wrap(err, "failed to create service(s) associated with the component") - } - if isOperatorBackedService { - log.Successf("Kubernetes resource %q on the cluster; refer %q to know how to link it to the component", strings.Join([]string{u.GetKind(), u.GetName()}, "/"), "odo link -h") - - } - return nil -} - -func (o componentKubernetes) UnApply(devfilePath string) error { - // Parse the component's Kubernetes manifest - u, err := service.GetK8sComponentAsUnstructured(o.component.Kubernetes, devfilePath, devfilefs.DefaultFs{}) - if err != nil { - return err - } - - // Get the REST mappings - gvr, err := o.client.GetRestMappingFromUnstructured(u) - if err != nil { - return err - } - log.Printf("Un-deploying the Kubernetes %s: %s", u.GetKind(), u.GetName()) - // Un-deploy the K8s manifest - return o.client.DeleteDynamicResource(u.GetName(), gvr.Resource.Group, gvr.Resource.Version, gvr.Resource.Resource) -}