mirror of
https://github.com/redhat-developer/odo.git
synced 2025-10-19 03:06:19 +03:00
Removing unused flags in link command (#5070)
* Removing unused link flags Signed-off-by: Mohammed Zeeshan Ahmed <mohammed.zee1000@gmail.com> * Removing wait-for-target flag Signed-off-by: Mohammed Zeeshan Ahmed <mohammed.zee1000@gmail.com> * Removing unused var Signed-off-by: Mohammed Zeeshan Ahmed <mohammed.zee1000@gmail.com> * Removing project and app flags Signed-off-by: Mohammed Zeeshan Ahmed <mohammed.zee1000@gmail.com> * Removing port flag Signed-off-by: Mohammed Zeeshan Ahmed <mohammed.zee1000@gmail.com> * Fixing as per feloy's comments Signed-off-by: Mohammed Zeeshan Ahmed <mohammed.zee1000@gmail.com> * Fixing after rebase Signed-off-by: Mohammed Zeeshan Ahmed <mohammed.zee1000@gmail.com>
This commit is contained in:
@@ -6,18 +6,14 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/openshift/odo/pkg/component"
|
||||
componentlabels "github.com/openshift/odo/pkg/component/labels"
|
||||
"github.com/openshift/odo/pkg/kclient"
|
||||
"github.com/openshift/odo/pkg/log"
|
||||
"github.com/openshift/odo/pkg/occlient"
|
||||
"github.com/openshift/odo/pkg/odo/genericclioptions"
|
||||
"github.com/openshift/odo/pkg/secret"
|
||||
svc "github.com/openshift/odo/pkg/service"
|
||||
"github.com/openshift/odo/pkg/util"
|
||||
servicebinding "github.com/redhat-developer/service-binding-operator/apis/binding/v1alpha1"
|
||||
"github.com/spf13/cobra"
|
||||
"gopkg.in/yaml.v2"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
kerrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
)
|
||||
@@ -25,8 +21,6 @@ import (
|
||||
const unlink = "unlink"
|
||||
|
||||
type commonLinkOptions struct {
|
||||
wait bool
|
||||
port string
|
||||
secretName string
|
||||
isTargetAService bool
|
||||
name string
|
||||
@@ -95,29 +89,14 @@ func (o *commonLinkOptions) complete(name string, cmd *cobra.Command, args []str
|
||||
return err
|
||||
}
|
||||
|
||||
if o.Context.EnvSpecificInfo != nil {
|
||||
return o.completeForOperator()
|
||||
if o.Context.EnvSpecificInfo == nil {
|
||||
return fmt.Errorf("failed to find environment info")
|
||||
}
|
||||
|
||||
cmpExists, err := component.Exists(o.Client, suppliedName, o.Application)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Unable to determine if component exists:\n%v", err)
|
||||
}
|
||||
|
||||
if !cmpExists {
|
||||
return fmt.Errorf("Neither a service nor a component named %s could be located. Please create one of the two before attempting to use 'odo %s'", suppliedName, o.operationName)
|
||||
}
|
||||
|
||||
secretName, err := secret.DetermineSecretName(o.Client, suppliedName, o.Application, o.port)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
o.secretName = secretName
|
||||
|
||||
return nil
|
||||
return o.completeForOperator()
|
||||
}
|
||||
|
||||
func (o *commonLinkOptions) validate(wait bool) (err error) {
|
||||
func (o *commonLinkOptions) validate() (err error) {
|
||||
if o.EnvSpecificInfo == nil {
|
||||
return fmt.Errorf("failed to find environment info to validate")
|
||||
}
|
||||
@@ -188,44 +167,9 @@ You can now access the environment variables from within the component pod, for
|
||||
$%s is now available as a variable within component %s`, exampleEnv, component)
|
||||
}
|
||||
}
|
||||
|
||||
if o.wait {
|
||||
if err := o.waitForLinkToComplete(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (o *commonLinkOptions) waitForLinkToComplete() (err error) {
|
||||
var component string
|
||||
if o.csvSupport && o.Context.EnvSpecificInfo != nil {
|
||||
component = o.EnvSpecificInfo.GetName()
|
||||
} else {
|
||||
component = o.Component()
|
||||
}
|
||||
|
||||
labels := componentlabels.GetLabels(component, o.Application, true)
|
||||
selectorLabels, err := util.NamespaceOpenShiftObject(labels[componentlabels.ComponentLabel], labels["app"])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
podSelector := fmt.Sprintf("deploymentconfig=%s", selectorLabels)
|
||||
|
||||
// first wait for the pod to be pending (meaning that the deployment is being put into effect)
|
||||
// we need this intermediate wait because there is a change that the this point could be reached
|
||||
// without Openshift having had the time to launch the new deployment
|
||||
_, err = o.Client.GetKubeClient().WaitAndGetPodWithEvents(podSelector, corev1.PodPending, "Waiting for component to redeploy")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// now wait for the pod to be running
|
||||
_, err = o.Client.GetKubeClient().WaitAndGetPodWithEvents(podSelector, corev1.PodRunning, "Waiting for component to start")
|
||||
return err
|
||||
}
|
||||
|
||||
// getServiceBindingName creates a name to be used for creation/deletion of SBR during link/unlink operations
|
||||
func (o *commonLinkOptions) getServiceBindingName(componentName string) string {
|
||||
if len(o.name) > 0 {
|
||||
|
||||
@@ -8,8 +8,6 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/openshift/odo/pkg/component"
|
||||
appCmd "github.com/openshift/odo/pkg/odo/cli/application"
|
||||
projectCmd "github.com/openshift/odo/pkg/odo/cli/project"
|
||||
"github.com/openshift/odo/pkg/odo/genericclioptions"
|
||||
odoutil "github.com/openshift/odo/pkg/odo/util"
|
||||
svc "github.com/openshift/odo/pkg/service"
|
||||
@@ -62,7 +60,6 @@ The value of the '--name' flag indicates the name of the directory under '/bindi
|
||||
|
||||
// LinkOptions encapsulates the options for the odo link command
|
||||
type LinkOptions struct {
|
||||
waitForTarget bool
|
||||
componentContext string
|
||||
|
||||
*commonLinkOptions
|
||||
@@ -97,7 +94,7 @@ func (o *LinkOptions) Complete(name string, cmd *cobra.Command, args []string) (
|
||||
|
||||
// Validate validates the LinkOptions based on completed values
|
||||
func (o *LinkOptions) Validate() (err error) {
|
||||
err = o.validate(o.waitForTarget)
|
||||
err = o.validate()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -144,17 +141,10 @@ func NewCmdLink(name, fullName string) *cobra.Command {
|
||||
}
|
||||
|
||||
linkCmd.PersistentFlags().BoolVarP(&o.inlined, "inlined", "", false, "Puts the link definition in the devfile instead of a separate file")
|
||||
linkCmd.PersistentFlags().StringVar(&o.port, "port", "", "Port of the backend to which to link")
|
||||
linkCmd.PersistentFlags().BoolVarP(&o.wait, "wait", "w", false, "If enabled the link will return only when the component is fully running after the link is created")
|
||||
linkCmd.PersistentFlags().BoolVar(&o.waitForTarget, "wait-for-target", false, "If enabled, the link command will wait for the service to be provisioned (has no effect when linking to a component)")
|
||||
linkCmd.PersistentFlags().StringVar(&o.name, "name", "", "Name of the created ServiceBinding resource")
|
||||
linkCmd.PersistentFlags().BoolVar(&o.bindAsFiles, "bind-as-files", false, "If enabled, configuration values will be mounted as files, instead of declared as environment variables")
|
||||
linkCmd.SetUsageTemplate(odoutil.CmdUsageTemplate)
|
||||
|
||||
//Adding `--project` flag
|
||||
projectCmd.AddProjectFlag(linkCmd)
|
||||
//Adding `--application` flag
|
||||
appCmd.AddApplicationFlag(linkCmd)
|
||||
//Adding `--component` flag
|
||||
AddComponentFlag(linkCmd)
|
||||
|
||||
|
||||
@@ -5,8 +5,6 @@ import (
|
||||
|
||||
"github.com/openshift/odo/pkg/odo/genericclioptions"
|
||||
|
||||
appCmd "github.com/openshift/odo/pkg/odo/cli/application"
|
||||
projectCmd "github.com/openshift/odo/pkg/odo/cli/project"
|
||||
svc "github.com/openshift/odo/pkg/service"
|
||||
|
||||
"github.com/openshift/odo/pkg/odo/util"
|
||||
@@ -74,7 +72,7 @@ func (o *UnlinkOptions) Complete(name string, cmd *cobra.Command, args []string)
|
||||
|
||||
// Validate validates the UnlinkOptions based on completed values
|
||||
func (o *UnlinkOptions) Validate() (err error) {
|
||||
return o.validate(false)
|
||||
return o.validate()
|
||||
}
|
||||
|
||||
// Run contains the logic for the odo link command
|
||||
@@ -98,14 +96,7 @@ func NewCmdUnlink(name, fullName string) *cobra.Command {
|
||||
},
|
||||
}
|
||||
|
||||
unlinkCmd.PersistentFlags().StringVar(&o.port, "port", "", "Port of the backend to which to unlink")
|
||||
unlinkCmd.PersistentFlags().BoolVarP(&o.wait, "wait", "w", false, "If enabled the link will return only when the component is fully running after the link is deleted")
|
||||
|
||||
unlinkCmd.SetUsageTemplate(util.CmdUsageTemplate)
|
||||
//Adding `--project` flag
|
||||
projectCmd.AddProjectFlag(unlinkCmd)
|
||||
//Adding `--application` flag
|
||||
appCmd.AddApplicationFlag(unlinkCmd)
|
||||
//Adding `--component` flag
|
||||
AddComponentFlag(unlinkCmd)
|
||||
// Adding context flag
|
||||
|
||||
Reference in New Issue
Block a user