Skip to content

Commit

Permalink
Cleanup S2I; remove BuildConfig, LocalConfig, Imagestreams and Deploy…
Browse files Browse the repository at this point in the history
…mentConfig (redhat-developer#5125)

* Clean LocalConfig

* Clean dc, bc, is

* Remove leftover code

* Comment the failing unit test

* Fix failing tests: part 1

* Fix failing tests: part 2

* Remove unused flag: temp

* Fix failing tests: part3

* Fix ci failures

* Rename devfile specific context

* Fix merge conflicts: remove convert.go

* Changes requested by Philippe

* Add missing changes requested by Philippe

* Fix unit test failure
  • Loading branch information
valaparthvi committed Oct 15, 2021
1 parent 56741d6 commit fc34e88
Show file tree
Hide file tree
Showing 101 changed files with 407 additions and 15,398 deletions.
51 changes: 11 additions & 40 deletions pkg/application/application.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package application

import (
"github.com/openshift/odo/pkg/kclient"
"github.com/pkg/errors"
"k8s.io/klog"

Expand All @@ -18,42 +19,24 @@ const (
appList = "List"
)

// List all applications names in current project by looking at `app` labels in deploymentconfigs, deployments and services instances
func List(client *occlient.Client) ([]string, error) {
var appNames []string

// List all applications names in current project by looking at `app` labels in deployments
func List(client *kclient.Client) ([]string, error) {
if client == nil {
return appNames, nil
}

deploymentSupported, err := client.IsDeploymentConfigSupported()
if err != nil {
return nil, err
return nil, nil
}

// Get all DeploymentConfigs with the "app" label
deploymentAppNames, err := client.GetKubeClient().GetDeploymentLabelValues(applabels.ApplicationLabel, applabels.ApplicationLabel)
// Get all Deployments with the "app" label
deploymentAppNames, err := client.GetDeploymentLabelValues(applabels.ApplicationLabel, applabels.ApplicationLabel)
if err != nil {
return nil, errors.Wrap(err, "unable to list applications from deployments")
}

appNames = append(appNames, deploymentAppNames...)

if deploymentSupported {
// Get all DeploymentConfigs with the "app" label
deploymentConfigAppNames, err := client.GetDeploymentConfigLabelValues(applabels.ApplicationLabel, applabels.ApplicationLabel)
if err != nil {
return nil, errors.Wrap(err, "unable to list applications from deployment config")
}
appNames = append(appNames, deploymentConfigAppNames...)
}

// Filter out any names, as there could be multiple components but within the same application
return util.RemoveDuplicates(appNames), nil
return util.RemoveDuplicates(deploymentAppNames), nil
}

// Exists checks whether the given app exist or not in the list of applications
func Exists(app string, client *occlient.Client) (bool, error) {
func Exists(app string, client *kclient.Client) (bool, error) {

appList, err := List(client)

Expand All @@ -68,26 +51,14 @@ func Exists(app string, client *occlient.Client) (bool, error) {
return false, nil
}

// Delete the given application by deleting deploymentconfigs, deployments and services instances belonging to this application
func Delete(client *occlient.Client, name string) error {
// Delete the given application by deleting deployments and services instances belonging to this application
func Delete(client *kclient.Client, name string) error {
klog.V(4).Infof("Deleting application %s", name)

labels := applabels.GetLabels(name, false)

supported, err := client.IsDeploymentConfigSupported()
if err != nil {
return err
}
if supported {
// delete application from cluster
err = client.Delete(labels, false)
if err != nil {
return errors.Wrapf(err, "unable to delete application %s", name)
}
}

// delete application from cluster
err = client.GetKubeClient().Delete(labels, false)
err := client.Delete(labels, false)
if err != nil {
return errors.Wrapf(err, "unable to delete application %s", name)
}
Expand Down
45 changes: 18 additions & 27 deletions pkg/application/application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,21 @@ import (
"reflect"
"testing"

"github.com/openshift/odo/pkg/testingutil"
"github.com/openshift/odo/pkg/version"

appsv1 "github.com/openshift/api/apps/v1"
applabels "github.com/openshift/odo/pkg/application/labels"
"github.com/openshift/odo/pkg/component"
componentlabels "github.com/openshift/odo/pkg/component/labels"
"github.com/openshift/odo/pkg/occlient"
"github.com/openshift/odo/pkg/testingutil"
"github.com/openshift/odo/pkg/version"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
ktesting "k8s.io/client-go/testing"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func TestGetMachineReadableFormat(t *testing.T) {
type args struct {
// client *occlient.Client
appName string
projectName string
active bool
Expand Down Expand Up @@ -53,9 +51,8 @@ func TestGetMachineReadableFormat(t *testing.T) {
},
},
}

dcList := appsv1.DeploymentConfigList{
Items: []appsv1.DeploymentConfig{
deploymentList := appsv1.DeploymentList{
Items: []appsv1.Deployment{
{
ObjectMeta: metav1.ObjectMeta{
Name: "frontend-myapp",
Expand All @@ -67,12 +64,9 @@ func TestGetMachineReadableFormat(t *testing.T) {
applabels.ManagedBy: "odo",
applabels.ManagerVersion: version.VERSION,
},
Annotations: map[string]string{
component.ComponentSourceTypeAnnotation: "local",
},
},
Spec: appsv1.DeploymentConfigSpec{
Template: &corev1.PodTemplateSpec{
Spec: appsv1.DeploymentSpec{
Template: corev1.PodTemplateSpec{
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Expand All @@ -94,12 +88,9 @@ func TestGetMachineReadableFormat(t *testing.T) {
applabels.ManagedBy: "odo",
applabels.ManagerVersion: version.VERSION,
},
Annotations: map[string]string{
component.ComponentSourceTypeAnnotation: "local",
},
},
Spec: appsv1.DeploymentConfigSpec{
Template: &corev1.PodTemplateSpec{
Spec: appsv1.DeploymentSpec{
Template: corev1.PodTemplateSpec{
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Expand All @@ -119,18 +110,18 @@ func TestGetMachineReadableFormat(t *testing.T) {
client, fakeClientSet := occlient.FakeNew()

// fake the project
fakeClientSet.ProjClientset.PrependReactor("get", "projects", func(action ktesting.Action) (handled bool, ret runtime.Object, err error) {
fakeClientSet.Kubernetes.PrependReactor("get", "projects", func(action ktesting.Action) (handled bool, ret runtime.Object, err error) {
return true, &testingutil.FakeOnlyOneExistingProjects().Items[0], nil
})

//fake the dcs
fakeClientSet.AppsClientset.PrependReactor("list", "deploymentconfigs", func(action ktesting.Action) (bool, runtime.Object, error) {
return true, &dcList, nil
//fake the deployments
fakeClientSet.Kubernetes.PrependReactor("list", "deployments", func(action ktesting.Action) (bool, runtime.Object, error) {
return true, &deploymentList, nil
})

for i := range dcList.Items {
fakeClientSet.AppsClientset.PrependReactor("get", "deploymentconfigs", func(action ktesting.Action) (bool, runtime.Object, error) {
return true, &dcList.Items[i], nil
for i := range deploymentList.Items {
fakeClientSet.Kubernetes.PrependReactor("get", "deployments", func(action ktesting.Action) (bool, runtime.Object, error) {
return true, &deploymentList.Items[i], nil
})
}
if got := GetMachineReadableFormat(client, tt.args.appName, tt.args.projectName); !reflect.DeepEqual(got, tt.want) {
Expand Down
Loading

0 comments on commit fc34e88

Please sign in to comment.