diff --git a/pkg/devfile/adapters/docker/utils/utils.go b/pkg/devfile/adapters/docker/utils/utils.go index bccb551a2c2..bde669f7658 100644 --- a/pkg/devfile/adapters/docker/utils/utils.go +++ b/pkg/devfile/adapters/docker/utils/utils.go @@ -226,12 +226,12 @@ func UpdateComponentWithSupervisord(comp *common.DevfileComponent, runCommand co }) } - if !adaptersCommon.IsEnvPresent(comp.Container.Env, adaptersCommon.EnvOdoCommandRunWorkingDir) && runCommand.Exec.WorkingDir != nil { + if !adaptersCommon.IsEnvPresent(comp.Container.Env, adaptersCommon.EnvOdoCommandRunWorkingDir) && runCommand.Exec.WorkingDir != "" { envName := adaptersCommon.EnvOdoCommandRunWorkingDir envValue := runCommand.Exec.WorkingDir comp.Container.Env = append(comp.Container.Env, &common.Env{ Name: envName, - Value: *envValue, + Value: envValue, }) } } diff --git a/pkg/devfile/adapters/kubernetes/utils/utils.go b/pkg/devfile/adapters/kubernetes/utils/utils.go index aa393980894..f414388e6ca 100644 --- a/pkg/devfile/adapters/kubernetes/utils/utils.go +++ b/pkg/devfile/adapters/kubernetes/utils/utils.go @@ -145,12 +145,12 @@ func UpdateContainersWithSupervisord(devfileObj devfileParser.DevfileObj, contai }) } - if !isEnvPresent(container.Env, adaptersCommon.EnvOdoCommandRunWorkingDir) && runCommand.Exec.WorkingDir != nil { + if !isEnvPresent(container.Env, adaptersCommon.EnvOdoCommandRunWorkingDir) && runCommand.Exec.WorkingDir != "" { klog.V(3).Infof("Updating container %v env with run command's workdir", container.Name) container.Env = append(container.Env, corev1.EnvVar{ Name: adaptersCommon.EnvOdoCommandRunWorkingDir, - Value: *runCommand.Exec.WorkingDir, + Value: runCommand.Exec.WorkingDir, }) } diff --git a/pkg/devfile/parser/data/1.0.0/components.go b/pkg/devfile/parser/data/1.0.0/components.go index b27b5c1afdd..a951a839412 100644 --- a/pkg/devfile/parser/data/1.0.0/components.go +++ b/pkg/devfile/parser/data/1.0.0/components.go @@ -7,7 +7,7 @@ import ( func (d *Devfile100) GetMetadata() common.DevfileMetadata { // No GenerateName field in V2 return common.DevfileMetadata{ - Name: *d.Metadata.Name, + Name: d.Metadata.Name, //Version: No field in V1 } } @@ -80,11 +80,11 @@ func convertV1CommandToCommon(c Command) (d common.DevfileCommand) { for _, action := range c.Actions { - if *action.Type == DevfileCommandTypeExec { + if action.Type == DevfileCommandTypeExec { exec = common.Exec{ Attributes: c.Attributes, - CommandLine: *action.Command, - Component: *action.Component, + CommandLine: action.Command, + Component: action.Component, Group: getGroup(c.Name), Id: c.Name, WorkingDir: action.Workdir, @@ -120,11 +120,11 @@ func convertV1ComponentToCommon(c Component) (d common.DevfileComponent) { } container := common.Container{ - Name: *c.Alias, + Name: c.Alias, Endpoints: endpoints, Env: envs, - Image: *c.ComponentDockerimage.Image, - MemoryLimit: *c.ComponentDockerimage.MemoryLimit, + Image: c.ComponentDockerimage.Image, + MemoryLimit: c.ComponentDockerimage.MemoryLimit, MountSources: c.MountSources, VolumeMounts: volumes, // SourceMapping: Not present in V1 @@ -139,32 +139,32 @@ func convertV1EndpointsToCommon(e DockerimageEndpoint) *common.Endpoint { return &common.Endpoint{ // Attributes: // Configuration: - Name: *e.Name, - TargetPort: *e.Port, + Name: e.Name, + TargetPort: e.Port, } } func convertV1EnvToCommon(e DockerimageEnv) *common.Env { return &common.Env{ - Name: *e.Name, - Value: *e.Value, + Name: e.Name, + Value: e.Value, } } func convertV1VolumeToCommon(v DockerimageVolume) *common.VolumeMount { return &common.VolumeMount{ - Name: *v.Name, - Path: *v.ContainerPath, + Name: v.Name, + Path: v.ContainerPath, } } func convertV1ProjectToCommon(p Project) common.DevfileProject { git := common.Git{ - Branch: *p.Source.Branch, + Branch: p.Source.Branch, Location: p.Source.Location, - SparseCheckoutDir: *p.Source.SparseCheckoutDir, - StartPoint: *p.Source.StartPoint, + SparseCheckoutDir: p.Source.SparseCheckoutDir, + StartPoint: p.Source.StartPoint, } return common.DevfileProject{ diff --git a/pkg/devfile/parser/data/1.0.0/types.go b/pkg/devfile/parser/data/1.0.0/types.go index af9774f81ca..5f59003ab6e 100644 --- a/pkg/devfile/parser/data/1.0.0/types.go +++ b/pkg/devfile/parser/data/1.0.0/types.go @@ -63,18 +63,18 @@ type Metadata struct { // Workspaces created from devfile, will use it as base and append random suffix. // It's used when name is not defined. - GenerateName *string `yaml:"generateName,omitempty" json:"generateName,omitempty"` + GenerateName string `yaml:"generateName,omitempty" json:"generateName,omitempty"` // The name of the devfile. Workspaces created from devfile, will inherit this // name - Name *string `yaml:"name,omitempty" json:"name,omitempty"` + Name string `yaml:"name,omitempty" json:"name,omitempty"` } // Description of the projects, containing names and sources locations type Project struct { // The path relative to the root of the projects to which this project should be cloned into. This is a unix-style relative path (i.e. uses forward slashes). The path is invalid if it is absolute or tries to escape the project root through the usage of '..'. If not specified, defaults to the project name." - ClonePath *string `yaml:"clonePath,omitempty" json:"clonePath,omitempty"` + ClonePath string `yaml:"clonePath,omitempty" json:"clonePath,omitempty"` // The Project Name Name string `yaml:"name" json:"name"` @@ -92,21 +92,21 @@ type ProjectSource struct { // The name of the of the branch to check out after obtaining the source from the location. // The branch has to already exist in the source otherwise the default branch is used. // In case of git, this is also the name of the remote branch to push to. - Branch *string `yaml:"branch,omitempty" json:"branch,omitempty"` + Branch string `yaml:"branch,omitempty" json:"branch,omitempty"` // The id of the commit to reset the checked out branch to. // Note that this is equivalent to 'startPoint' and provided for convenience. - CommitId *string `yaml:"commitId,omitempty" json:"commitId,omitempty"` + CommitId string `yaml:"commitId,omitempty" json:"commitId,omitempty"` // Part of project to populate in the working directory. - SparseCheckoutDir *string `yaml:"sparseCheckoutDir,omitempty" json:"sparseCheckoutDir,omitempty"` + SparseCheckoutDir string `yaml:"sparseCheckoutDir,omitempty" json:"sparseCheckoutDir,omitempty"` // The tag or commit id to reset the checked out branch to. - StartPoint *string `yaml:"startPoint,omitempty" json:"startPoint,omitempty"` + StartPoint string `yaml:"startPoint,omitempty" json:"startPoint,omitempty"` // The name of the tag to reset the checked out branch to. // Note that this is equivalent to 'startPoint' and provided for convenience. - Tag *string `yaml:"tag,omitempty" json:"tag,omitempty"` + Tag string `yaml:"tag,omitempty" json:"tag,omitempty"` } type Command struct { @@ -127,31 +127,31 @@ type Command struct { } type CommandPreviewUrl struct { - Port *int32 `yaml:"port,omitempty" json:"port,omitempty"` - Path *string `yaml:"path,omitempty" json:"path,omitempty"` + Port int32 `yaml:"port,omitempty" json:"port,omitempty"` + Path string `yaml:"path,omitempty" json:"path,omitempty"` } type CommandAction struct { // The actual action command-line string - Command *string `yaml:"command,omitempty" json:"command,omitempty"` + Command string `yaml:"command,omitempty" json:"command,omitempty"` // Describes component to which given action relates - Component *string `yaml:"component,omitempty" json:"component,omitempty"` + Component string `yaml:"component,omitempty" json:"component,omitempty"` // the path relative to the location of the devfile to the configuration file // defining one or more actions in the editor-specific format - Reference *string `yaml:"reference,omitempty" json:"reference,omitempty"` + Reference string `yaml:"reference,omitempty" json:"reference,omitempty"` // The content of the referenced configuration file that defines one or more // actions in the editor-specific format - ReferenceContent *string `yaml:"referenceContent,omitempty" json:"referenceContent,omitempty"` + ReferenceContent string `yaml:"referenceContent,omitempty" json:"referenceContent,omitempty"` // Describes action type - Type *CommandType `yaml:"type,omitempty" json:"type,omitempty"` + Type CommandType `yaml:"type,omitempty" json:"type,omitempty"` // Working directory where the command should be executed - Workdir *string `yaml:"workdir,omitempty" json:"workdir,omitempty"` + Workdir string `yaml:"workdir,omitempty" json:"workdir,omitempty"` } type Component struct { @@ -159,7 +159,7 @@ type Component struct { // The name using which other places of this devfile (like commands) can refer to // this component. This attribute is optional but must be unique in the devfile if // specified. - Alias *string `yaml:"alias,omitempty" json:"alias,omitempty"` + Alias string `yaml:"alias,omitempty" json:"alias,omitempty"` // Describes whether projects sources should be mount to the component. // `CHE_PROJECTS_ROOT` environment variable should contains a path where projects @@ -178,36 +178,36 @@ type Component struct { } type ComponentChePlugin struct { - Id *string `yaml:"id,omitempty" json:"id,omitempty"` - Reference *string `yaml:"reference,omitempty" json:"reference,omitempty"` - RegistryUrl *string `yaml:"registryUrl,omitempty" json:"registryUrl,omitempty"` + Id string `yaml:"id,omitempty" json:"id,omitempty"` + Reference string `yaml:"reference,omitempty" json:"reference,omitempty"` + RegistryUrl string `yaml:"registryUrl,omitempty" json:"registryUrl,omitempty"` } type ComponentCheEditor struct { - Id *string `yaml:"id,omitempty" json:"id,omitempty"` - Reference *string `yaml:"reference,omitempty" json:"reference,omitempty"` - RegistryUrl *string `yaml:"registryUrl,omitempty" json:"registryUrl,omitempty"` + Id string `yaml:"id,omitempty" json:"id,omitempty"` + Reference string `yaml:"reference,omitempty" json:"reference,omitempty"` + RegistryUrl string `yaml:"registryUrl,omitempty" json:"registryUrl,omitempty"` } type ComponentOpenshift struct { - Reference *string `yaml:"reference,omitempty" json:"reference,omitempty"` - ReferenceContent *string `yaml:"referenceContent,omitempty" json:"referenceContent,omitempty"` - Selector *string `yaml:"selector,omitempty" json:"selector,omitempty"` - EntryPoints *string `yaml:"entryPoints,omitempty" json:"entryPoints,omitempty"` - MemoryLimit *string `yaml:"memoryLimit,omitempty" json:"memoryLimit,omitempty"` + Reference string `yaml:"reference,omitempty" json:"reference,omitempty"` + ReferenceContent string `yaml:"referenceContent,omitempty" json:"referenceContent,omitempty"` + Selector string `yaml:"selector,omitempty" json:"selector,omitempty"` + EntryPoints string `yaml:"entryPoints,omitempty" json:"entryPoints,omitempty"` + MemoryLimit string `yaml:"memoryLimit,omitempty" json:"memoryLimit,omitempty"` } type ComponentKubernetes struct { - Reference *string `yaml:"reference,omitempty" json:"reference,omitempty"` - ReferenceContent *string `yaml:"referenceContent,omitempty" json:"referenceContent,omitempty"` - Selector *string `yaml:"selector,omitempty" json:"selector,omitempty"` - EntryPoints *string `yaml:"entryPoints,omitempty" json:"entryPoints,omitempty"` - MemoryLimit *string `yaml:"memoryLimit,omitempty" json:"memoryLimit,omitempty"` + Reference string `yaml:"reference,omitempty" json:"reference,omitempty"` + ReferenceContent string `yaml:"referenceContent,omitempty" json:"referenceContent,omitempty"` + Selector string `yaml:"selector,omitempty" json:"selector,omitempty"` + EntryPoints string `yaml:"entryPoints,omitempty" json:"entryPoints,omitempty"` + MemoryLimit string `yaml:"memoryLimit,omitempty" json:"memoryLimit,omitempty"` } type ComponentDockerimage struct { - Image *string `yaml:"image,omitempty" json:"image,omitempty"` - MemoryLimit *string `yaml:"memoryLimit,omitempty" json:"memoryLimit,omitempty"` + Image string `yaml:"image,omitempty" json:"image,omitempty"` + MemoryLimit string `yaml:"memoryLimit,omitempty" json:"memoryLimit,omitempty"` Command []string `yaml:"command,omitempty" json:"command,omitempty"` Args []string `yaml:"args,omitempty" json:"args,omitempty"` Volumes []DockerimageVolume `yaml:"volumes,omitempty" json:"volumes,omitempty"` @@ -216,16 +216,16 @@ type ComponentDockerimage struct { } type DockerimageVolume struct { - Name *string `yaml:"name,omitempty" json:"name,omitempty"` - ContainerPath *string `yaml:"containerPath,omitempty" json:"containerPath,omitempty"` + Name string `yaml:"name,omitempty" json:"name,omitempty"` + ContainerPath string `yaml:"containerPath,omitempty" json:"containerPath,omitempty"` } type DockerimageEnv struct { - Name *string `yaml:"name,omitempty" json:"name,omitempty"` - Value *string `yaml:"value,omitempty" json:"value,omitempty"` + Name string `yaml:"name,omitempty" json:"name,omitempty"` + Value string `yaml:"value,omitempty" json:"value,omitempty"` } type DockerimageEndpoint struct { - Name *string `yaml:"name,omitempty" json:"name,omitempty"` - Port *int32 `yaml:"port,omitempty" json:"port,omitempty"` + Name string `yaml:"name,omitempty" json:"name,omitempty"` + Port int32 `yaml:"port,omitempty" json:"port,omitempty"` } diff --git a/pkg/devfile/parser/data/common/types.go b/pkg/devfile/parser/data/common/types.go index 6e0b5064eff..bfaa132996d 100644 --- a/pkg/devfile/parser/data/common/types.go +++ b/pkg/devfile/parser/data/common/types.go @@ -97,7 +97,7 @@ type DevfileComponent struct { type DevfileProject struct { // Path relative to the root of the projects to which this project should be cloned into. This is a unix-style relative path (i.e. uses forward slashes). The path is invalid if it is absolute or tries to escape the project root through the usage of '..'. If not specified, defaults to the project name. - ClonePath *string `json:"clonePath,omitempty"` + ClonePath string `json:"clonePath,omitempty"` // Project's Custom source Custom *Custom `json:"custom,omitempty"` @@ -272,7 +272,7 @@ type Exec struct { Label string `json:"label,omitempty"` // Working directory where the command should be executed - WorkingDir *string `json:"workingDir,omitempty"` + WorkingDir string `json:"workingDir,omitempty"` } // Git Project's Git source diff --git a/pkg/exec/devfile.go b/pkg/exec/devfile.go index ce639ab422b..1485bc8743e 100644 --- a/pkg/exec/devfile.go +++ b/pkg/exec/devfile.go @@ -15,9 +15,9 @@ func ExecuteDevfileBuildAction(client ExecClient, exec common.Exec, commandName // Change to the workdir and execute the command var cmdArr []string - if exec.WorkingDir != nil { + if exec.WorkingDir != "" { // since we are using /bin/sh -c, the command needs to be within a single double quote instance, for example "cd /tmp && pwd" - cmdArr = []string{adaptersCommon.ShellExecutable, "-c", "cd " + *exec.WorkingDir + " && " + exec.CommandLine} + cmdArr = []string{adaptersCommon.ShellExecutable, "-c", "cd " + exec.WorkingDir + " && " + exec.CommandLine} } else { cmdArr = []string{adaptersCommon.ShellExecutable, "-c", exec.CommandLine} } diff --git a/pkg/odo/cli/component/create.go b/pkg/odo/cli/component/create.go index 9adbed77bca..4e2813ed0fb 100644 --- a/pkg/odo/cli/component/create.go +++ b/pkg/odo/cli/component/create.go @@ -750,8 +750,8 @@ func (co *CreateOptions) downloadProject(projectPassed string) error { return errors.Wrapf(err, "Could not get the current working directory.") } - if project.ClonePath != nil && *project.ClonePath != "" { - clonePath := *project.ClonePath + if project.ClonePath != "" { + clonePath := project.ClonePath if runtime.GOOS == "windows" { clonePath = strings.Replace(clonePath, "\\", "/", -1) } diff --git a/pkg/sync/adapter.go b/pkg/sync/adapter.go index cb6d47f3557..57a27002269 100644 --- a/pkg/sync/adapter.go +++ b/pkg/sync/adapter.go @@ -197,14 +197,14 @@ func getSyncFolder(projects []versionsCommon.DevfileProject) (string, error) { project := projects[0] // If the clonepath is set to a value, set it to be the sync folder // As some devfiles rely on the code being synced to the folder in the clonepath - if project.ClonePath != nil { - if strings.HasPrefix(*project.ClonePath, "/") { + if project.ClonePath != "" { + if strings.HasPrefix(project.ClonePath, "/") { return "", fmt.Errorf("the clonePath in the devfile must be a relative path") } - if strings.Contains(*project.ClonePath, "..") { + if strings.Contains(project.ClonePath, "..") { return "", fmt.Errorf("the clonePath in the devfile cannot escape the projects root. Don't use .. to try and do that") } - return filepath.ToSlash(filepath.Join(kclient.OdoSourceVolumeMount, *project.ClonePath)), nil + return filepath.ToSlash(filepath.Join(kclient.OdoSourceVolumeMount, project.ClonePath)), nil } return filepath.ToSlash(filepath.Join(kclient.OdoSourceVolumeMount, projects[0].Name)), nil }