mirror of
https://github.com/redhat-developer/odo.git
synced 2025-10-19 03:06:19 +03:00
* initial work on adding AppName * completed the implementation and tests * resolved failing tests * reverting an un-necessary change * dryed the tests * added test for having both devfile and s2i together * uncommented some stuff * skip s2i test on kuberenetes * resolved charlie's comments * addressed mrinal's comments * resolved the panic * use client and dc support for specific cases * resolved final tests and odo list now worked for unpushed components * resolved failing unit tests * update the component adapter in other places * resolved all comments * removed the created context at the end of the test * addressed tomas's comment * resolved all comments * updated all devfiles with proper name * resolved rebase * addressed a missed error and more validation in the tests * use random cmpName for tests
71 lines
2.2 KiB
Go
71 lines
2.2 KiB
Go
package adapters
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/openshift/odo/pkg/devfile/adapters/common"
|
|
"github.com/openshift/odo/pkg/devfile/adapters/docker"
|
|
"github.com/openshift/odo/pkg/devfile/adapters/kubernetes"
|
|
devfileParser "github.com/openshift/odo/pkg/devfile/parser"
|
|
"github.com/openshift/odo/pkg/kclient"
|
|
"github.com/openshift/odo/pkg/lclient"
|
|
"github.com/openshift/odo/pkg/odo/util/pushtarget"
|
|
)
|
|
|
|
// NewComponentAdapter returns a Devfile adapter for the targeted platform
|
|
func NewComponentAdapter(componentName string, context string, appName string, devObj devfileParser.DevfileObj, platformContext interface{}) (common.ComponentAdapter, error) {
|
|
|
|
adapterContext := common.AdapterContext{
|
|
ComponentName: componentName,
|
|
Context: context,
|
|
AppName: appName,
|
|
Devfile: devObj,
|
|
}
|
|
|
|
// If the pushtarget is set to Docker, initialize the Docker adapter, otherwise initialize the Kubernetes adapter
|
|
if pushtarget.IsPushTargetDocker() {
|
|
return createDockerAdapter(adapterContext)
|
|
}
|
|
|
|
kc, ok := platformContext.(kubernetes.KubernetesContext)
|
|
if !ok {
|
|
return nil, fmt.Errorf("Error retrieving context for Kubernetes")
|
|
}
|
|
return createKubernetesAdapter(adapterContext, kc.Namespace)
|
|
|
|
}
|
|
|
|
func createKubernetesAdapter(adapterContext common.AdapterContext, namespace string) (common.ComponentAdapter, error) {
|
|
client, err := kclient.New()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// If a namespace was passed in
|
|
if namespace != "" {
|
|
client.Namespace = namespace
|
|
}
|
|
return newKubernetesAdapter(adapterContext, *client)
|
|
}
|
|
|
|
func newKubernetesAdapter(adapterContext common.AdapterContext, client kclient.Client) (common.ComponentAdapter, error) {
|
|
// Feed the common metadata to the platform-specific adapter
|
|
kubernetesAdapter := kubernetes.New(adapterContext, client)
|
|
|
|
return kubernetesAdapter, nil
|
|
}
|
|
|
|
func createDockerAdapter(adapterContext common.AdapterContext) (common.ComponentAdapter, error) {
|
|
client, err := lclient.New()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return newDockerAdapter(adapterContext, *client)
|
|
}
|
|
|
|
func newDockerAdapter(adapterContext common.AdapterContext, client lclient.Client) (common.ComponentAdapter, error) {
|
|
dockerAdapter := docker.New(adapterContext, client)
|
|
return dockerAdapter, nil
|
|
}
|