Files
odo/pkg/component/types.go
Armel Soro 2132cb516f [#5561] Remove odo url (#5571)
* Remove `odo url` from CLI layer

* Adapt tests

* Adapt test from deleted `cmd_devfile_delete_test.go`

This test still makes sense, as it tests the removal
of URL-related resources, like Services and Ingresses.

* Remove call to `odo project set ...` in test, as suggested in review

This command will get removed in the near future.

* Remove places where URL manipulation could modify  Devfiles

Also remove dead code

* Remove unused `updateURL` field from EnvInfo struct

* Adapt test by mimicking some behavior that `odo url create` used to perform

`odo url` used to modify the `env.yaml` file,
and `odo dev` currently creates Kubernetes/OCP resources related to URLs.

We may remove this test later on if `odo dev`
no longer needs to create such Ingresses and Routes.

* Remove all places where URLs, Ingresses and Routes are manipulated

* Port test in cmd_dev_test instead and make sure no Ingress/Route is created

* Remove no-longer `test-cmd-devfile-url` target from Makefile

The corresponding test file has been deleted.

* Remove `create url` command reference from V3 docs, as suggested in review

* Use existing `devfile-with-multiple-endpoints.yaml` Devfile  in test, as suggested in review
2022-03-28 16:39:53 +02:00

126 lines
3.6 KiB
Go

package component
import (
"github.com/redhat-developer/odo/pkg/machineoutput"
"github.com/redhat-developer/odo/pkg/storage"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
const ComponentKind = "Component"
// Component
type Component struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec ComponentSpec `json:"spec,omitempty"`
Status ComponentStatus `json:"status,omitempty"`
}
// ComponentSpec is spec of components
type ComponentSpec struct {
App string `json:"app,omitempty"`
Type string `json:"type,omitempty"`
Source string `json:"source,omitempty"`
Storage []string `json:"storage,omitempty"`
StorageSpec []storage.Storage `json:"-"`
Env []corev1.EnvVar `json:"env,omitempty"`
Ports []string `json:"ports,omitempty"`
}
// ComponentList is list of components
type ComponentList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Component `json:"items"`
}
// SecretMount describes a Secret mount (either as environment variables with envFrom or as a volume)
type SecretMount struct {
ServiceName string
SecretName string
MountVolume bool
MountPath string
}
// ComponentStatus is Status of components
type ComponentStatus struct {
Context string `json:"context,omitempty"`
State string `json:"state"`
LinkedServices []SecretMount `json:"linkedServices,omitempty"`
}
// CombinedComponentList is list of s2i and devfile components
type CombinedComponentList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
DevfileComponents []Component `json:"devfileComponents"`
OtherComponents []Component `json:"otherComponents"`
}
const (
// StateTypePushed means that Storage is present both locally and on cluster
StateTypePushed = "Pushed"
// StateTypeNotPushed means that Storage is only in local config, but not on the cluster
StateTypeNotPushed = "Not Pushed"
// StateTypeUnknown means that odo cannot tell its state
StateTypeUnknown = "Unknown"
)
func newComponentWithType(componentName, componentType string) Component {
cmp := NewComponent(componentName)
cmp.Spec.Type = componentType
return cmp
}
// NewComponent provides a constructor to component struct with some metadata prefilled
func NewComponent(componentName string) Component {
return Component{
TypeMeta: metav1.TypeMeta{
Kind: ComponentKind,
APIVersion: machineoutput.APIVersion,
},
ObjectMeta: metav1.ObjectMeta{
Name: componentName,
},
Status: ComponentStatus{},
}
}
// newComponentList returns list of devfile and s2i components in machine readable format
func newComponentList(comps []Component) ComponentList {
if len(comps) == 0 {
comps = []Component{}
}
return ComponentList{
TypeMeta: metav1.TypeMeta{
Kind: machineoutput.ListKind,
APIVersion: machineoutput.APIVersion,
},
ListMeta: metav1.ListMeta{},
Items: comps,
}
}
// NewCombinedComponentList returns list of devfile, s2i components and other components(not managed by odo) in machine readable format
func NewCombinedComponentList(devfileComps []Component, otherComps []Component) CombinedComponentList {
if len(devfileComps) == 0 {
devfileComps = []Component{}
}
if len(otherComps) == 0 {
otherComps = []Component{}
}
return CombinedComponentList{
TypeMeta: metav1.TypeMeta{
Kind: machineoutput.ListKind,
APIVersion: machineoutput.APIVersion,
},
ListMeta: metav1.ListMeta{},
DevfileComponents: devfileComps,
OtherComponents: otherComps,
}
}