Skip to content

Commit

Permalink
Revert "odo dev: Add support for non-exec commands part of a compos…
Browse files Browse the repository at this point in the history
…ite run or debug command (#5923)"

This reverts commit 224069c.
  • Loading branch information
feloy committed Aug 18, 2022
1 parent 0e71623 commit 3c63d21
Show file tree
Hide file tree
Showing 47 changed files with 1,097 additions and 1,498 deletions.
5 changes: 2 additions & 3 deletions pkg/binding/binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ import (
"fmt"
"path/filepath"

"github.com/redhat-developer/odo/pkg/project"
bindingApis "github.com/redhat-developer/service-binding-operator/apis"
bindingApi "github.com/redhat-developer/service-binding-operator/apis/binding/v1alpha1"
specApi "github.com/redhat-developer/service-binding-operator/apis/spec/v1alpha3"

"github.com/redhat-developer/odo/pkg/project"

"github.com/devfile/library/pkg/devfile/parser"
devfilefs "github.com/devfile/library/pkg/testingutil/filesystem"
"gopkg.in/yaml.v2"
Expand Down Expand Up @@ -302,7 +301,7 @@ func (o *BindingClient) checkServiceBindingOperatorInstalled() error {

func (o *BindingClient) CheckServiceBindingsInjectionDone(componentName string, appName string) (bool, error) {

deployment, err := o.kubernetesClient.GetOneDeployment(componentName, appName, true)
deployment, err := o.kubernetesClient.GetOneDeployment(componentName, appName)
if err != nil {
// If not deployment yet => all bindings are done
if _, ok := err.(*kclient.DeploymentNotFoundError); ok {
Expand Down
4 changes: 2 additions & 2 deletions pkg/component/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func Exists(client kclient.ClientInterface, componentName, applicationName strin

// GetOnePod gets a pod using the component and app name
func GetOnePod(client kclient.ClientInterface, componentName string, appName string) (*corev1.Pod, error) {
return client.GetRunningPodFromSelector(odolabels.GetSelector(componentName, appName, odolabels.ComponentDevMode, false))
return client.GetRunningPodFromSelector(odolabels.GetSelector(componentName, appName, odolabels.ComponentDevMode))
}

// Log returns log from component
Expand Down Expand Up @@ -212,7 +212,7 @@ func ListAllClusterComponents(client kclient.ClientInterface, namespace string)
}

func getResourcesForComponent(client kclient.ClientInterface, name string, namespace string) ([]unstructured.Unstructured, error) {
selector := labels.GetSelector(name, "app", labels.ComponentAnyMode, false)
selector := labels.GetSelector(name, "app", labels.ComponentAnyMode)
resourceList, err := client.GetAllResourcesFromSelector(selector, namespace)
if err != nil {
return nil, err
Expand Down
46 changes: 21 additions & 25 deletions pkg/component/delete/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"path/filepath"

"github.com/devfile/library/pkg/devfile/parser"
"k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
kerrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
Expand Down Expand Up @@ -37,7 +36,7 @@ func NewDeleteComponentClient(kubeClient kclient.ClientInterface) *DeleteCompone
// It only returns resources not owned by another resource of the component, letting the garbage collector do its job
func (do *DeleteComponentClient) ListClusterResourcesToDelete(componentName string, namespace string) ([]unstructured.Unstructured, error) {
var result []unstructured.Unstructured
selector := odolabels.GetSelector(componentName, "app", odolabels.ComponentAnyMode, false)
selector := odolabels.GetSelector(componentName, "app", odolabels.ComponentAnyMode)
list, err := do.kubeClient.GetAllResourcesFromSelector(selector, namespace)
if err != nil {
return nil, err
Expand Down Expand Up @@ -91,7 +90,7 @@ func references(list []unstructured.Unstructured, ownerRef metav1.OwnerReference

// ListResourcesToDeleteFromDevfile parses all the devfile components and returns a list of resources that are present on the cluster and can be deleted
func (do DeleteComponentClient) ListResourcesToDeleteFromDevfile(devfileObj parser.DevfileObj, appName string, mode string) (isInnerLoopDeployed bool, resources []unstructured.Unstructured, err error) {
var deployment *v1.Deployment

if mode == odolabels.ComponentDevMode || mode == odolabels.ComponentAnyMode {
// Inner Loop
// Fetch the deployment of the devfile component
Expand All @@ -102,7 +101,7 @@ func (do DeleteComponentClient) ListResourcesToDeleteFromDevfile(devfileObj pars
return isInnerLoopDeployed, resources, fmt.Errorf("failed to get the resource %q name for component %q; cause: %w", kclient.DeploymentKind, componentName, err)
}

deployment, err = do.kubeClient.GetDeploymentByName(deploymentName)
deployment, err := do.kubeClient.GetDeploymentByName(deploymentName)
if err != nil && !kerrors.IsNotFound(err) {
return isInnerLoopDeployed, resources, err
}
Expand All @@ -121,30 +120,27 @@ func (do DeleteComponentClient) ListResourcesToDeleteFromDevfile(devfileObj pars
}
}

// Parse the devfile for K8s resources; these may belong to either innerloop or outerloop
localResources, err := libdevfile.ListKubernetesComponents(devfileObj, filepath.Dir(devfileObj.Ctx.GetAbsPath()))
if err != nil {
return isInnerLoopDeployed, resources, fmt.Errorf("failed to gather resources for deletion: %w", err)
}
for _, lr := range localResources {
var gvr *meta.RESTMapping
gvr, err = do.kubeClient.GetRestMappingFromUnstructured(lr)
if mode == odolabels.ComponentDeployMode || mode == odolabels.ComponentAnyMode {
// Outer Loop
// Parse the devfile for outerloop K8s resources
localResources, err := libdevfile.ListKubernetesComponents(devfileObj, filepath.Dir(devfileObj.Ctx.GetAbsPath()))
if err != nil {
continue
return isInnerLoopDeployed, resources, fmt.Errorf("failed to gather resources for deletion: %w", err)
}
// Try to fetch the resource from the cluster; if it exists, append it to the resources list
var cr *unstructured.Unstructured
cr, err = do.kubeClient.GetDynamicResource(gvr.Resource, lr.GetName())
// If a specific mode is asked for, then make sure it matches with the cr's mode.
if err != nil || (mode != odolabels.ComponentAnyMode && odolabels.GetMode(cr.GetLabels()) != mode) {
if cr != nil {
klog.V(4).Infof("Ignoring resource: %s/%s; its mode(%s) does not match with the given mode(%s)", gvr.Resource.Resource, lr.GetName(), odolabels.GetMode(cr.GetLabels()), mode)
} else {
klog.V(4).Infof("Ignoring resource: %s/%s; it does not exist on the cluster", gvr.Resource.Resource, lr.GetName())
for _, lr := range localResources {
var gvr *meta.RESTMapping
gvr, err = do.kubeClient.GetRestMappingFromUnstructured(lr)
if err != nil {
continue
}
continue
// Try to fetch the resource from the cluster; if it exists, append it to the resources list
var cr *unstructured.Unstructured
cr, err = do.kubeClient.GetDynamicResource(gvr.Resource, lr.GetName())
if err != nil {
continue
}
resources = append(resources, *cr)
}
resources = append(resources, *cr)
}

return isInnerLoopDeployed, resources, nil
Expand All @@ -159,7 +155,7 @@ func (do *DeleteComponentClient) ExecutePreStopEvents(devfileObj parser.DevfileO
klog.V(4).Infof("Gathering information for component: %q", componentName)

klog.V(3).Infof("Checking component status for %q", componentName)
selector := odolabels.GetSelector(componentName, appName, odolabels.ComponentDevMode, false)
selector := odolabels.GetSelector(componentName, appName, odolabels.ComponentDevMode)
pod, err := do.kubeClient.GetRunningPodFromSelector(selector)
if err != nil {
klog.V(1).Info("Component not found on the cluster.")
Expand Down
Loading

0 comments on commit 3c63d21

Please sign in to comment.