Skip to content

Commit

Permalink
Merge branch 'master' of github.com:openshift/odo into issue-2635-dyn…
Browse files Browse the repository at this point in the history
…amicRegistrySupport

Signed-off-by: jingfu wang <jingfu.j.wang@ibm.com>
  • Loading branch information
GeekArthur committed May 4, 2020
2 parents 0e34086 + 3d7212b commit 6eb07c2
Show file tree
Hide file tree
Showing 66 changed files with 2,721 additions and 603 deletions.
31 changes: 23 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ env:
- MINIKUBE_WANTREPORTERRORPROMPT=false
- MINIKUBE_HOME=$HOME
- CHANGE_MINIKUBE_NONE_USER=true
- KUBECONFIG=$HOME/.kube/config
- KUBECONFIG=$HOME/.kube/config
jobs:
include:
# YAML alias, for settings shared across the tests
Expand Down Expand Up @@ -70,7 +70,7 @@ jobs:

- <<: *base-test
stage: test
name: "generic, login, component command integration tests"
name: "generic, login and component command integration tests"
script:
- ./scripts/oc-cluster.sh
- make bin
Expand Down Expand Up @@ -98,7 +98,7 @@ jobs:
# Run service-catalog e2e tests
- <<: *base-test
stage: test
name: "service, link, component sub-commands command integration tests"
name: "service, link and component sub-commands command integration tests"
script:
- ./scripts/oc-cluster.sh service-catalog
- make bin
Expand All @@ -111,7 +111,7 @@ jobs:

- <<: *base-test
stage: test
name: "watch, storage, app, project, push, devfile catalog, devfile create, devfile push, devfile delete, devfile registry command integration tests"
name: "watch, storage, app, project and push command integration tests"
script:
- ./scripts/oc-cluster.sh
- make bin
Expand All @@ -122,6 +122,22 @@ jobs:
- travis_wait make test-cmd-app
- travis_wait make test-cmd-push
- travis_wait make test-cmd-project
- odo logout

- <<: *base-test
stage: test
# Docker push target test command does not need a running cluster at all, however few test
# scenario of docker devfile url testing needs only Kube config file. So the test has been
# added here just to make sure docker devfile url command test gets a proper kube config file.
# without creating a separate OpenShift cluster.
name: "devfile catalog, create, push, delete, registry and docker devfile url command integration tests"
script:
- ./scripts/oc-cluster.sh
- make bin
- sudo cp odo /usr/bin
- travis_wait make test-cmd-docker-devfile-url
# These tests need cluster login as they will be interacting with a Kube environment
- odo login -u developer
- travis_wait make test-cmd-devfile-catalog
- travis_wait make test-cmd-devfile-create
- travis_wait make test-cmd-devfile-push
Expand All @@ -146,15 +162,14 @@ jobs:

- <<: *base-test
stage: test
name: "docker devfile push command integration tests"
name: "docker devfile push and delete command integration tests"
script:
- ./scripts/oc-cluster.sh
- make bin
- sudo cp odo /usr/bin
- travis_wait make test-cmd-docker-devfile-push
- travis_wait make test-cmd-docker-devfile-url
- travis_wait make test-cmd-docker-devfile-catalog
- travis_wait make test-cmd-docker-devfile-delete


# Run devfile integration test on Kubernetes cluster
- <<: *base-test
stage: test
Expand Down
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,16 @@ test-cmd-docker-devfile-push:
.PHONY: test-cmd-docker-devfile-url
test-cmd-docker-devfile-url:
ginkgo $(GINKGO_FLAGS) -focus="odo docker devfile url command tests" tests/integration/devfile/docker/

# Run odo docker devfile delete command tests
.PHONY: test-cmd-docker-devfile-delete
test-cmd-docker-devfile-delete:
ginkgo $(GINKGO_FLAGS) -focus="odo docker devfile delete command tests" tests/integration/devfile/docker/

# Run odo catalog devfile command tests
.PHONY: test-cmd-docker-devfile-catalog
test-cmd-docker-devfile-catalog:
ginkgo $(GINKGO_FLAGS) -focus="odo docker devfile catalog command tests" tests/integration/devfile/docker/

# Run odo watch command tests
.PHONY: test-cmd-watch
Expand Down
2 changes: 1 addition & 1 deletion README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ image:https://img.shields.io/github/license/openshift/odo?style=for-the-badge[Li

`odo` is a fast, iterative, and straightforward CLI tool for developers who write, build, and deploy applications on OpenShift.

Existing tools such as `oc` are more operations-focused and require a deep-understanding of Kubernetes and OpenShift concepts. `odo` abstracts away complex Kubernetes and OpenShift concepts for the developer, thus allowing developers to focus on what is most important to them: code.
Existing tools such as `oc` are more operations-focused and require a deep-understanding of Kubernetes and OpenShift concepts. `odo` abstracts away complex Kubernetes and OpenShift concepts for the developer.

[[key-features]]
== Key features
Expand Down
2 changes: 1 addition & 1 deletion cmd/cli-doc/cli-doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func referencePrinter(command *cobra.Command, level int) string {
}

// The main markdown "template" for everything
return fmt.Sprintf(`= Overview of the OpenShift Do (odo) CLI Structure
return fmt.Sprintf(`= Overview of the odo CLI Structure
___________________
Example application
Expand Down
7 changes: 6 additions & 1 deletion docs/dev/development.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ toc::[]

== Setting up

Requires *Go 1.13*
Requires *Go 1.12*

**WARNING**: If you are adding any features that require a higher version of golang, such as golang 1.13
for example, please contact maintainers to check of the releasing systems can handle the newer versions.

If that is ok, please ensure you update the required golang version, both here and in the file link:/scripts/rpm-prepare.sh[`scripts/rpm-prepare.sh`]

. link:https://help.github.com/en/articles/fork-a-repo[Fork] the link:https://github.com/openshift/odo[`odo`] repository.

Expand Down
194 changes: 62 additions & 132 deletions pkg/component/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io"
"os"
"path/filepath"
"strconv"
"strings"

"github.com/openshift/odo/pkg/devfile/adapters/common"
Expand Down Expand Up @@ -542,110 +543,49 @@ func ValidateComponentCreateRequest(client *occlient.Client, componentSettings c
// Returns:
// err: Errors if any else nil
func ApplyConfig(client *occlient.Client, kClient *kclient.Client, componentConfig config.LocalConfigInfo, envSpecificInfo envinfo.EnvSpecificInfo, stdout io.Writer, cmpExist bool) (err error) {
if !experimental.IsExperimentalModeEnabled() {
// if component exist then only call the update function
if cmpExist {
if err = Update(client, componentConfig, componentConfig.GetSourceLocation(), stdout); err != nil {
return err
}
}
}

showChanges, pushedURLMap, err := checkIfURLChangesWillBeMade(client, kClient, componentConfig, envSpecificInfo)
if err != nil {
return err
}
isExperimentalModeEnabled := experimental.IsExperimentalModeEnabled()

if showChanges {
log.Info("\nApplying URL changes")
// Create any URLs that have been added to the component
err = ApplyConfigCreateURL(client, kClient, componentConfig, envSpecificInfo, pushedURLMap)
if err != nil {
return err
}

// Delete any URLs
err = applyConfigDeleteURL(client, kClient, componentConfig, envSpecificInfo, pushedURLMap)
if client == nil {
var err error
client, err = occlient.New()
if err != nil {
return err
}
client.Namespace = envSpecificInfo.GetNamespace()
}

return
}

// ApplyConfigDeleteURL applies url config deletion onto component
func applyConfigDeleteURL(client *occlient.Client, kClient *kclient.Client, componentConfig config.LocalConfigInfo, envSpecificInfo envinfo.EnvSpecificInfo, pushedURLMap map[string]bool) (err error) {
if experimental.IsExperimentalModeEnabled() {
localURLList := envSpecificInfo.GetURL()
tempMap := make(map[string]envinfo.EnvInfoURL)
for _, urlElement := range localURLList {
tempMap[urlElement.Name] = urlElement
}
// urlName is the key of each element
for urlName := range pushedURLMap {
if _, exist := tempMap[urlName]; !exist {
err = urlpkg.Delete(client, kClient, urlName, componentConfig.GetApplication())
if err != nil {
return err
}
log.Successf("URL %s successfully deleted", urlName)
}
}
} else {
localURLList := componentConfig.GetURL()
tempMap := make(map[string]config.ConfigURL)
for _, urlElement := range localURLList {
tempMap[urlElement.Name] = urlElement
}
// urlName is the key of each element
for urlName := range pushedURLMap {
if _, exist := tempMap[urlName]; !exist {
err = urlpkg.Delete(client, kClient, urlName, componentConfig.GetApplication())
if err != nil {
return err
}
log.Successf("URL %s successfully deleted", urlName)
if !isExperimentalModeEnabled {
// if component exist then only call the update function
if cmpExist {
if err = Update(client, componentConfig, componentConfig.GetSourceLocation(), stdout); err != nil {
return err
}
}
}
return nil
}

// ApplyConfigCreateURL applies url config onto component
func ApplyConfigCreateURL(client *occlient.Client, kClient *kclient.Client, componentConfig config.LocalConfigInfo, envSpecificInfo envinfo.EnvSpecificInfo, pushedURLMap map[string]bool) error {
if experimental.IsExperimentalModeEnabled() {
urls := envSpecificInfo.GetURL()
componentName := envSpecificInfo.GetName()
for _, urlo := range urls {
_, exist := pushedURLMap[urlo.Name]
if exist {
log.Successf("URL %s already exists", urlo.Name)
} else {
host, err := urlpkg.Create(client, kClient, urlo.Name, urlo.Port, urlo.Secure, componentName, "", urlo.Host, urlo.TLSSecret)
if err != nil {
return errors.Wrapf(err, "unable to create url")
}
log.Successf("URL %s: %s created", urlo.Name, host)
}
}
var componentName string
var applicationName string
if !isExperimentalModeEnabled || kClient == nil {
componentName = componentConfig.GetName()
applicationName = componentConfig.GetApplication()
} else {
urls := componentConfig.GetURL()
for _, urlo := range urls {
_, exist := pushedURLMap[urlo.Name]
if exist {
log.Successf("URL %s already exists", urlo.Name)
} else {
host, err := urlpkg.Create(client, kClient, urlo.Name, urlo.Port, urlo.Secure, componentConfig.GetName(), componentConfig.GetApplication(), "", "")
if err != nil {
return errors.Wrapf(err, "unable to create url")
}
log.Successf("URL %s: %s created", urlo.Name, host)
}
}
componentName = envSpecificInfo.GetName()
}

return nil
isRouteSupported := false
isRouteSupported, err = client.IsRouteSupported()
if err != nil {
isRouteSupported = false
}

return urlpkg.Push(client, kClient, urlpkg.PushParameters{
ComponentName: componentName,
ApplicationName: applicationName,
ConfigURLs: componentConfig.GetURL(),
EnvURLS: envSpecificInfo.GetURL(),
IsRouteSupported: isRouteSupported,
IsExperimentalModeEnabled: isExperimentalModeEnabled,
})
}

// PushLocal push local code to the cluster and trigger build there.
Expand Down Expand Up @@ -954,8 +894,21 @@ func GetComponentFromConfig(localConfig *config.LocalConfigInfo) (Component, err
component.Spec.Source = util.GenFileURL(localConfig.GetSourceLocation())
}

for _, localURL := range localConfig.GetURL() {
component.Spec.URL = append(component.Spec.URL, localURL.Name)
urls := localConfig.GetURL()
if len(urls) > 0 {
// We will clean up the existing value of ports and re-populate it so that we don't panic in `odo describe` and don't show inconsistent info
// This will also help in the case where there are more URLs created than the number of ports exposed by a component #2776
oldPortsProtocol, err := getPortsProtocolMapping(component.Spec.Ports)
if err != nil {
return Component{}, err
}
component.Spec.Ports = []string{}

for _, url := range urls {
port := strconv.Itoa(url.Port)
component.Spec.Ports = append(component.Spec.Ports, fmt.Sprintf("%s/%s", port, oldPortsProtocol[port]))
component.Spec.URL = append(component.Spec.URL, url.Name)
}
}

for _, localEnv := range localConfig.GetEnvVars() {
Expand All @@ -970,6 +923,22 @@ func GetComponentFromConfig(localConfig *config.LocalConfigInfo) (Component, err
return Component{}, nil
}

// This function returns a mapping of port and protocol.
// So for a value of ports {"8080/TCP", "45/UDP"} it will return a map {"8080":
// "TCP", "45": "UDP"}
func getPortsProtocolMapping(ports []string) (map[string]string, error) {
oldPortsProtocol := make(map[string]string, len(ports))
for _, port := range ports {
portProtocol := strings.Split(port, "/")
if len(portProtocol) != 2 {
// this will be the case if value of a port is something like 8080/TCP/something-else or simply 8080
return nil, errors.New("invalid <port/protocol> mapping. Please update the component configuration")
}
oldPortsProtocol[portProtocol[0]] = portProtocol[1]
}
return oldPortsProtocol, nil
}

// ListIfPathGiven lists all available component in given path directory
func ListIfPathGiven(client *occlient.Client, paths []string) (ComponentList, error) {
var components []Component
Expand Down Expand Up @@ -1496,45 +1465,6 @@ func getStorageFromConfig(localConfig *config.LocalConfigInfo) storage.StorageLi
return storageList
}

// checkIfURLChangesWillBeMade checks to see if there are going to be any changes
// to the URLs when deploying and returns a true / false
func checkIfURLChangesWillBeMade(client *occlient.Client, kClient *kclient.Client, componentConfig config.LocalConfigInfo, envSpecificInfo envinfo.EnvSpecificInfo) (bool, map[string]bool, error) {
if experimental.IsExperimentalModeEnabled() {
componentName := envSpecificInfo.GetName()
urlList, err := urlpkg.ListPushedIngress(kClient, componentName)
if err != nil {
return false, nil, err
}

// If envinfo has URL(s) (since we check) or if the cluster has URL's but
// envinfo does not (deleting)
if len(envSpecificInfo.GetURL()) > 0 || len(envSpecificInfo.GetURL()) == 0 && (len(urlList.Items) > 0) {
pushedURLMap := make(map[string]bool)
for _, element := range urlList.Items {
pushedURLMap[element.Name] = true
}
return true, pushedURLMap, nil
}
} else {
urlList, err := urlpkg.ListPushed(client, componentConfig.GetName(), componentConfig.GetApplication())
if err != nil {
return false, nil, err
}

// If envinfo has URL(s) (since we check) or if the cluster has URL's but
// envinfo does not (deleting)
if len(componentConfig.GetURL()) > 0 || len(componentConfig.GetURL()) == 0 && (len(urlList.Items) > 0) {
pushedURLMap := make(map[string]bool)
for _, element := range urlList.Items {
pushedURLMap[element.Name] = true
}
return true, pushedURLMap, nil
}
}

return false, nil, nil
}

func addDebugPortToEnv(envVarList *config.EnvVarList, componentConfig config.LocalConfigInfo) {
// adding the debug port as an env variable
*envVarList = append(*envVarList, config.EnvVar{
Expand Down
4 changes: 3 additions & 1 deletion pkg/config/fakeConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ func GetOneExistingConfigInfo(componentName, applicationName, projectName string
},
}

portsValue := []string{"8080/TCP,45/UDP"}
portsValue := []string{"8080/TCP", "45/UDP"}

urlValue := []ConfigURL{
{
Name: "example-url-0",
Port: 8080,
},
{
Name: "example-url-1",
Port: 45,
},
}

Expand Down
Loading

0 comments on commit 6eb07c2

Please sign in to comment.