Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "feat: adding support for --profile cmd option" #1724

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion client/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ func (k *Kompose) Convert(options ConvertOptions) ([]runtime.Object, error) {
PushImageRegistry: options.PushImageRegistry,
CreateDeploymentConfig: k.createDeploymentConfig(options),
EmptyVols: false,
Profiles: options.Profiles,
Volumes: *options.VolumeType,
PVCRequestSize: options.PvcRequestSize,
InsecureRepository: k.insecureRepository(options),
Expand Down
90 changes: 1 addition & 89 deletions client/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package client

import (
"fmt"
v1 "k8s.io/api/core/v1"
"sort"
"testing"

"gotest.tools/v3/assert"
Expand Down Expand Up @@ -71,7 +69,7 @@ func TestConvertWithDefaultOptions(t *testing.T) {
client, err := NewClient(WithErrorOnWarning())
assert.Check(t, is.Equal(err, nil))
objects, err := client.Convert(ConvertOptions{
ToStdout: true,
OutFile: "./testdata/generated/",
InputFiles: []string{
"./testdata/docker-compose.yaml",
},
Expand All @@ -83,89 +81,3 @@ func TestConvertWithDefaultOptions(t *testing.T) {
}
}
}

func TestConvertWithProfiles(t *testing.T) {
client, err := NewClient(WithErrorOnWarning())
assert.Check(t, is.Equal(err, nil))

type Want struct {
deploymentsNames []string
servicesNames []string
}

tests := []struct {
name string
options ConvertOptions
want Want
}{
{
name: "No profiles provided",
options: ConvertOptions{
ToStdout: true,
InputFiles: []string{
"./testdata/docker-compose-profiles.yaml",
},
},
want: Want{
deploymentsNames: nil,
servicesNames: nil,
},
},
{
name: "All profiles provided",
options: ConvertOptions{
ToStdout: true,
InputFiles: []string{
"./testdata/docker-compose-profiles.yaml",
},
Profiles: []string{"hello", "world"},
},
want: Want{
deploymentsNames: []string{"backend", "frontend", "database"},
servicesNames: []string{"backend", "frontend", "database"},
},
},
{
name: "One profile only",
options: ConvertOptions{
ToStdout: true,
InputFiles: []string{
"./testdata/docker-compose-profiles.yaml",
},
Profiles: []string{"hello"},
},
want: Want{
deploymentsNames: []string{"backend", "frontend"},
servicesNames: []string{"backend", "frontend"},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
objects, err := client.Convert(tt.options)
assert.Check(t, is.Equal(err, nil))

sort.Strings(tt.want.deploymentsNames)
sort.Strings(tt.want.servicesNames)

var deploymentsNames []string
var servicesNames []string

for _, object := range objects {
if deployment, ok := object.(*appsv1.Deployment); ok {
deploymentsNames = append(deploymentsNames, deployment.Name)
}

if service, ok := object.(*v1.Service); ok {
servicesNames = append(servicesNames, service.Name)
}
}

sort.Strings(deploymentsNames)
sort.Strings(servicesNames)

assert.Check(t, is.DeepEqual(deploymentsNames, tt.want.deploymentsNames))
assert.Check(t, is.DeepEqual(servicesNames, tt.want.servicesNames))
})
}
}
17 changes: 0 additions & 17 deletions client/testdata/docker-compose-profiles.yaml

This file was deleted.

1 change: 0 additions & 1 deletion client/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ type ConvertOptions struct {
PvcRequestSize string
WithKomposeAnnotations *bool
InputFiles []string
Profiles []string
Provider
GenerateNetworkPolicies bool
}
Expand Down
4 changes: 0 additions & 4 deletions cmd/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ var (
ConvertDeploymentConfig bool
ConvertReplicas int
ConvertController string
ConvertProfiles []string
ConvertPushImage bool
ConvertNamespace string
ConvertPushImageRegistry string
Expand Down Expand Up @@ -116,7 +115,6 @@ var convertCmd = &cobra.Command{
IsReplicaSetFlag: cmd.Flags().Lookup("replicas").Changed,
IsDeploymentConfigFlag: cmd.Flags().Lookup("deployment-config").Changed,
YAMLIndent: ConvertYAMLIndent,
Profiles: ConvertProfiles,
WithKomposeAnnotation: WithKomposeAnnotation,
MultipleContainerMode: MultipleContainerMode,
ServiceGroupMode: ServiceGroupMode,
Expand Down Expand Up @@ -201,8 +199,6 @@ func init() {

convertCmd.Flags().IntVar(&ConvertYAMLIndent, "indent", 2, "Spaces length to indent generated yaml files")

convertCmd.Flags().StringArrayVar(&ConvertProfiles, "profile", []string{}, `Specify the profile to use, can use multiple profiles`)

// In order to 'separate' both OpenShift and Kubernetes only flags. A custom help page is created
customHelp := `Usage:{{if .Runnable}}
{{if .HasAvailableFlags}}{{appendIfNotPresent .UseLine "[flags]"}}{{else}}{{.UseLine}}{{end}}{{end}}{{if .HasAvailableSubCommands}}
Expand Down
2 changes: 1 addition & 1 deletion pkg/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func Convert(opt kobject.ConvertOptions) ([]runtime.Object, error) {
komposeObject := kobject.KomposeObject{
ServiceConfigs: make(map[string]kobject.ServiceConfig),
}
komposeObject, err = l.LoadFile(opt.InputFiles, opt.Profiles)
komposeObject, err = l.LoadFile(opt.InputFiles)
if err != nil {
log.Fatalf(err.Error())
}
Expand Down
1 change: 0 additions & 1 deletion pkg/kobject/kobject.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ type ConvertOptions struct {
BuildRepo string
BuildBranch string
Build string
Profiles []string
PushImage bool
PushImageRegistry string
CreateChart bool
Expand Down
9 changes: 2 additions & 7 deletions pkg/loader/compose/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,19 +149,14 @@ func checkUnsupportedKey(composeProject *types.Project) []string {
}

// LoadFile loads a compose file into KomposeObject
func (c *Compose) LoadFile(files []string, profiles []string) (kobject.KomposeObject, error) {
func (c *Compose) LoadFile(files []string) (kobject.KomposeObject, error) {
// Gather the working directory
workingDir, err := getComposeFileDir(files)
if err != nil {
return kobject.KomposeObject{}, err
}

projectOptions, err := cli.NewProjectOptions(
files, cli.WithOsEnv,
cli.WithWorkingDirectory(workingDir),
cli.WithInterpolation(true),
cli.WithProfiles(profiles),
)
projectOptions, err := cli.NewProjectOptions(files, cli.WithOsEnv, cli.WithWorkingDirectory(workingDir), cli.WithInterpolation(true))
if err != nil {
return kobject.KomposeObject{}, errors.Wrap(err, "Unable to create compose options")
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (

// Loader interface defines loader that loads files and converts it to kobject representation
type Loader interface {
LoadFile(files []string, profiles []string) (kobject.KomposeObject, error)
LoadFile(files []string) (kobject.KomposeObject, error)
///Name() string
}

Expand Down
Loading