Skip to content

Commit 6fcb6c4

Browse files
authored
✨ Convert OpenShift BuildConfigs to Shipwright Builds (#168)
* ✨ Convert OpenShift BuildConfigs to Shipwright Builds * Fix failing tests
1 parent 1a2aed5 commit 6fcb6c4

File tree

8 files changed

+357
-213
lines changed

8 files changed

+357
-213
lines changed

.github/workflows/go.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ jobs:
55
name: Build
66
runs-on: ubuntu-latest
77
steps:
8-
- name: Set up Go 1.21
8+
- name: Set up Go 1.24
99
uses: actions/setup-go@v2
1010
with:
11-
go-version: 1.21
11+
go-version: 1.24
1212

1313
- name: Check out source code
1414
uses: actions/checkout@v2

cmd/convert/convert.go

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
package convert
2+
3+
import (
4+
"github.com/konveyor/crane-lib/convert"
5+
"github.com/sirupsen/logrus"
6+
"github.com/spf13/cobra"
7+
"k8s.io/cli-runtime/pkg/genericclioptions"
8+
"k8s.io/client-go/kubernetes/scheme"
9+
"k8s.io/client-go/rest"
10+
"sigs.k8s.io/controller-runtime/pkg/client"
11+
12+
buildv1 "github.com/openshift/api/build/v1"
13+
imagev1 "github.com/openshift/api/image/v1"
14+
)
15+
16+
type ConvertOptions struct {
17+
configFlags *genericclioptions.ConfigFlags
18+
genericclioptions.IOStreams
19+
SourceContext string
20+
Namespace string
21+
logger logrus.FieldLogger
22+
ResourceType string
23+
SearchRegistries []string
24+
InsecureRegistries []string
25+
BlockRegistries []string
26+
exportDir string
27+
}
28+
29+
func NewConvertOptions(streams genericclioptions.IOStreams) *cobra.Command {
30+
t := &ConvertOptions{
31+
configFlags: genericclioptions.NewConfigFlags(false),
32+
33+
IOStreams: streams,
34+
logger: logrus.New(),
35+
}
36+
37+
cmd := &cobra.Command{
38+
Use: "convert",
39+
Short: "Convert a deprecated resource to its replacement",
40+
RunE: func(c *cobra.Command, args []string) error {
41+
if err := t.Complete(c, args); err != nil {
42+
return err
43+
}
44+
// if err := t.Validate(); err != nil {
45+
// return err
46+
// }
47+
if err := t.Run(); err != nil {
48+
return err
49+
}
50+
51+
return nil
52+
},
53+
}
54+
addFlagsForConvertOptions(t, cmd)
55+
56+
return cmd
57+
}
58+
59+
func addFlagsForConvertOptions(t *ConvertOptions, cmd *cobra.Command) {
60+
cmd.Flags().StringVar(&t.SourceContext, "source-context", "", "The source context in current kubeconfig")
61+
cmd.Flags().StringVarP(&t.Namespace, "namespace", "n", "", "The namespace to convert resources from")
62+
cmd.Flags().StringVarP(&t.ResourceType, "resource", "r", "", "The deprecated plural resource type to convert, e.g. BuildConfigs")
63+
cmd.Flags().StringSliceVarP(&t.SearchRegistries, "search-registries", "s", []string{}, "List of search registries")
64+
cmd.Flags().StringSliceVar(&t.InsecureRegistries, "insecure-registries", []string{}, "List of search registries")
65+
cmd.Flags().StringSliceVar(&t.BlockRegistries, "block-registries", []string{}, "List of search registries")
66+
cmd.Flags().StringVarP(&t.exportDir, "export-dir", "e", "convert", "The path where files are to be exported")
67+
}
68+
69+
func (t *ConvertOptions) Complete(c *cobra.Command, args []string) error {
70+
return nil
71+
}
72+
73+
func (t *ConvertOptions) Run() error {
74+
return t.run()
75+
}
76+
77+
func (t *ConvertOptions) run() error {
78+
srcClient, err := t.getClientFromContext()
79+
if err != nil {
80+
return err
81+
}
82+
83+
convertOptions := convert.ConvertOptions{
84+
Client: srcClient,
85+
Namespace: t.Namespace,
86+
ResourceType: t.ResourceType,
87+
SearchRegistries: t.SearchRegistries,
88+
InsecureRegistries: t.InsecureRegistries,
89+
BlockRegistries: t.BlockRegistries,
90+
ExportDir: t.exportDir,
91+
}
92+
93+
err = convertOptions.Convert()
94+
if err != nil {
95+
return err
96+
}
97+
98+
return nil
99+
}
100+
101+
func (t *ConvertOptions) getClientFromContext() (client.Client, error) {
102+
err := buildv1.Install(scheme.Scheme)
103+
if err != nil {
104+
return nil, err
105+
}
106+
107+
err = imagev1.Install(scheme.Scheme)
108+
if err != nil {
109+
return nil, err
110+
}
111+
112+
restConfig, err := t.getRestConfigFromContext(t.SourceContext)
113+
if err != nil {
114+
return nil, err
115+
}
116+
117+
restConfig.Burst = 1000
118+
restConfig.QPS = 100
119+
120+
return client.New(restConfig, client.Options{Scheme: scheme.Scheme})
121+
}
122+
123+
func (t *ConvertOptions) getRestConfigFromContext(ctx string) (*rest.Config, error) {
124+
c := ctx
125+
t.configFlags.Context = &c
126+
127+
return t.configFlags.ToRESTConfig()
128+
}

cmd/plugin-manager/add/add.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func NewAddCommand(f *flags.GlobalFlags) *cobra.Command {
104104
return err
105105
}
106106
if err := o.Validate(args); err != nil {
107-
log.Errorf(fmt.Sprintf("%s", err.Error()))
107+
log.Errorf("%s", err.Error())
108108
return nil
109109
}
110110
if err := o.Run(args); err != nil {
@@ -145,7 +145,7 @@ func (o *Options) run(args []string) error {
145145
case len(manifestMap) > 1:
146146
// if the plugin is found across multiple repository then fail and ask for a specific repo
147147
// TODO: if the version is mentioned look for a plugin with the same version, if found in only one repo add the same else fail and ask for the repo
148-
log.Errorf(fmt.Sprintf("The plugin %s is found across multiple repos, please specify one repo with --repo flag", args[0]))
148+
log.Errorf("The plugin %s is found across multiple repos, please specify one repo with --repo flag", args[0])
149149
case len(manifestMap) == 1:
150150
// the plugin is found in only one repo
151151
for _, pluginsMap := range manifestMap {
@@ -157,7 +157,7 @@ func (o *Options) run(args []string) error {
157157
if value.Name != "" && (o.Version == "" || string(value.Version) == o.Version) {
158158
return downloadBinary(o.PluginDir, value.Name, value.Binaries[0].URI, log)
159159
} else {
160-
log.Errorf(fmt.Sprintf("The version %s of plugin %s is not available", installVersion, value.Name))
160+
log.Errorf("The version %s of plugin %s is not available", installVersion, value.Name)
161161
fmt.Printf("Run \"crane plugin-manager list --name %s --params\" to see available versions along with additional information \n", args[0])
162162
}
163163
}
@@ -176,11 +176,11 @@ func (o *Options) run(args []string) error {
176176
return downloadBinary(o.PluginDir, value.Name, value.Binaries[0].URI, log)
177177
}
178178
}
179-
log.Errorf(fmt.Sprintf("The %s version of the plugin %s is not found", installVersion, args[0]))
179+
log.Errorf("The %s version of the plugin %s is not found", installVersion, args[0])
180180
fmt.Printf("Run \"crane plugin-manager list --name %s --params\" to see available versions along with additional information \n", args[0])
181181
default:
182182
// throw error saying that the plugin doest exists
183-
log.Errorf(fmt.Sprintf("The plugin %s is not found", args[0]))
183+
log.Errorf("The plugin %s is not found", args[0])
184184
fmt.Println(fmt.Sprintf("Run \"crane plugin-manager list\" to list all the available plugins \n"))
185185
}
186186
}

cmd/plugin-manager/list/list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func (o *Options) run() error {
136136
}
137137
}
138138
} else {
139-
log.Errorf(fmt.Sprintf("name flag must be used with wither params or versions"))
139+
log.Errorf("name flag must be used with wither params or versions")
140140
}
141141
} else {
142142
manifestMap, err := plugin.BuildManifestMap(log, "", o.Repo)

cmd/plugin-manager/remove/remove.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func (o *Options) run(args []string) error {
9999
fmt.Printf("%s \n", path)
100100
}
101101
} else if len(paths) == 0 {
102-
log.Errorf(fmt.Sprintf("Plugin %s not found in the plugin dir %s", args[0], pluginDir))
102+
log.Errorf("Plugin %s not found in the plugin dir %s", args[0], pluginDir)
103103
fmt.Printf("Run \"crane plugin-manager list --installed -p %s\" to see the list of installed plugins \n", pluginDir)
104104
} else {
105105
err = os.Remove(paths[0])

go.mod

Lines changed: 61 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,67 @@
11
module github.com/konveyor/crane
22

3-
go 1.23.0
3+
go 1.24.0
44

5-
toolchain go1.24.2
5+
toolchain go1.24.4
66

77
require (
88
github.com/backube/pvc-transfer v0.0.0-20220718185428-1d2440958552
99
github.com/bombsimon/logrusr/v3 v3.0.0
1010
github.com/ghodss/yaml v1.0.0
11-
github.com/go-logr/logr v1.2.3
11+
github.com/go-logr/logr v1.4.3
1212
github.com/jarcoal/httpmock v1.2.0
13-
github.com/konveyor/crane-lib v0.0.8
13+
github.com/konveyor/crane-lib v0.1.5-0.20250909151500-172f817bb41b
1414
github.com/olekukonko/tablewriter v0.0.5
1515
github.com/openshift/api v0.0.0-20220525145417-ee5b62754c68
1616
github.com/openshift/library-go v0.0.0-20220704153411-3ea4b775d418
17-
github.com/sirupsen/logrus v1.8.1
18-
github.com/spf13/cobra v1.5.0
17+
github.com/sirupsen/logrus v1.9.3
18+
github.com/spf13/cobra v1.9.1
1919
github.com/spf13/viper v1.12.0
2020
github.com/vmware-tanzu/velero v1.6.3
21-
golang.org/x/mod v0.8.0
21+
golang.org/x/mod v0.24.0
2222
gotest.tools/v3 v3.0.3
23-
k8s.io/api v0.24.2
24-
k8s.io/apimachinery v0.24.2
25-
k8s.io/cli-runtime v0.24.2
26-
k8s.io/client-go v0.24.2
27-
sigs.k8s.io/controller-runtime v0.12.2
23+
k8s.io/api v0.33.2
24+
k8s.io/apimachinery v0.33.2
25+
k8s.io/cli-runtime v0.33.2
26+
k8s.io/client-go v0.33.2
27+
sigs.k8s.io/controller-runtime v0.20.4
2828
sigs.k8s.io/kustomize/cmd/config v0.10.7
29-
sigs.k8s.io/kustomize/kyaml v0.13.7
30-
sigs.k8s.io/yaml v1.3.0
29+
sigs.k8s.io/kustomize/kyaml v0.19.0
30+
sigs.k8s.io/yaml v1.4.0
3131
)
3232

3333
require (
34+
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect
3435
github.com/Luzifer/go-dhparam v1.1.0 // indirect
35-
github.com/PuerkitoBio/purell v1.1.1 // indirect
36-
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
37-
github.com/davecgh/go-spew v1.1.1 // indirect
38-
github.com/emicklei/go-restful v2.9.5+incompatible // indirect
39-
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
40-
github.com/evanphx/json-patch/v5 v5.5.0 // indirect
41-
github.com/fsnotify/fsnotify v1.5.4 // indirect
42-
github.com/go-errors/errors v1.0.1 // indirect
43-
github.com/go-logr/zapr v1.2.3 // indirect
44-
github.com/go-openapi/jsonpointer v0.19.5 // indirect
45-
github.com/go-openapi/jsonreference v0.19.5 // indirect
46-
github.com/go-openapi/swag v0.19.14 // indirect
36+
github.com/blang/semver/v4 v4.0.0 // indirect
37+
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
38+
github.com/emicklei/go-restful/v3 v3.12.1 // indirect
39+
github.com/evanphx/json-patch v5.9.11+incompatible // indirect
40+
github.com/evanphx/json-patch/v5 v5.9.11 // indirect
41+
github.com/fsnotify/fsnotify v1.8.0 // indirect
42+
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
43+
github.com/go-errors/errors v1.4.2 // indirect
44+
github.com/go-logr/zapr v1.3.0 // indirect
45+
github.com/go-openapi/jsonpointer v0.21.0 // indirect
46+
github.com/go-openapi/jsonreference v0.21.0 // indirect
47+
github.com/go-openapi/swag v0.23.0 // indirect
4748
github.com/gogo/protobuf v1.3.2 // indirect
48-
github.com/golang/protobuf v1.5.2 // indirect
49-
github.com/google/btree v1.0.1 // indirect
50-
github.com/google/gnostic v0.5.7-v3refs // indirect
51-
github.com/google/go-cmp v0.5.9 // indirect
52-
github.com/google/gofuzz v1.2.0 // indirect
49+
github.com/google/btree v1.1.3 // indirect
50+
github.com/google/gnostic-models v0.6.9 // indirect
51+
github.com/google/go-cmp v0.7.0 // indirect
5352
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
54-
github.com/google/uuid v1.1.2 // indirect
55-
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 // indirect
53+
github.com/google/uuid v1.6.0 // indirect
54+
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect
5655
github.com/hashicorp/hcl v1.0.0 // indirect
57-
github.com/imdario/mergo v0.3.12 // indirect
58-
github.com/inconshreveable/mousetrap v1.0.0 // indirect
56+
github.com/inconshreveable/mousetrap v1.1.0 // indirect
5957
github.com/josharian/intern v1.0.0 // indirect
6058
github.com/json-iterator/go v1.1.12 // indirect
6159
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect
6260
github.com/magiconair/properties v1.8.6 // indirect
63-
github.com/mailru/easyjson v0.7.6 // indirect
64-
github.com/mattn/go-runewidth v0.0.9 // indirect
61+
github.com/mailru/easyjson v0.9.0 // indirect
62+
github.com/mattn/go-runewidth v0.0.16 // indirect
6563
github.com/mitchellh/mapstructure v1.5.0 // indirect
64+
github.com/moby/term v0.5.0 // indirect
6665
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
6766
github.com/modern-go/reflect2 v1.0.2 // indirect
6867
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
@@ -71,29 +70,35 @@ require (
7170
github.com/pelletier/go-toml/v2 v2.0.1 // indirect
7271
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
7372
github.com/pkg/errors v0.9.1 // indirect
74-
github.com/spf13/afero v1.8.2 // indirect
73+
github.com/rivo/uniseg v0.4.7 // indirect
74+
github.com/shipwright-io/build v0.16.4 // indirect
75+
github.com/spf13/afero v1.9.2 // indirect
7576
github.com/spf13/cast v1.5.0 // indirect
7677
github.com/spf13/jwalterweatherman v1.1.0 // indirect
77-
github.com/spf13/pflag v1.0.5 // indirect
78+
github.com/spf13/pflag v1.0.6 // indirect
7879
github.com/subosito/gotenv v1.3.0 // indirect
79-
github.com/xlab/treeprint v0.0.0-20181112141820-a009c3971eca // indirect
80-
go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5 // indirect
81-
golang.org/x/net v0.24.0 // indirect
82-
golang.org/x/oauth2 v0.27.0 // indirect
83-
golang.org/x/sys v0.19.0 // indirect
84-
golang.org/x/term v0.19.0 // indirect
85-
golang.org/x/text v0.14.0 // indirect
86-
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect
87-
google.golang.org/appengine v1.6.7 // indirect
88-
google.golang.org/protobuf v1.33.0 // indirect
80+
github.com/x448/float16 v0.8.4 // indirect
81+
github.com/xlab/treeprint v1.2.0 // indirect
82+
go.uber.org/multierr v1.11.0 // indirect
83+
go.uber.org/zap v1.27.0 // indirect
84+
golang.org/x/net v0.39.0 // indirect
85+
golang.org/x/oauth2 v0.29.0 // indirect
86+
golang.org/x/sync v0.13.0 // indirect
87+
golang.org/x/sys v0.32.0 // indirect
88+
golang.org/x/term v0.31.0 // indirect
89+
golang.org/x/text v0.24.0 // indirect
90+
golang.org/x/time v0.10.0 // indirect
91+
google.golang.org/protobuf v1.36.6 // indirect
92+
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
8993
gopkg.in/inf.v0 v0.9.1 // indirect
9094
gopkg.in/ini.v1 v1.66.4 // indirect
9195
gopkg.in/yaml.v2 v2.4.0 // indirect
92-
gopkg.in/yaml.v3 v3.0.0 // indirect
93-
k8s.io/klog/v2 v2.60.1 // indirect
94-
k8s.io/kube-openapi v0.0.0-20220401212409-b28bf2818661 // indirect
95-
k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9 // indirect
96-
sigs.k8s.io/json v0.0.0-20211208200746-9f7c6b3444d2 // indirect
97-
sigs.k8s.io/kustomize/api v0.11.5 // indirect
98-
sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect
96+
gopkg.in/yaml.v3 v3.0.1 // indirect
97+
k8s.io/klog/v2 v2.130.1 // indirect
98+
k8s.io/kube-openapi v0.0.0-20250318190949-c8a335a9a2ff // indirect
99+
k8s.io/utils v0.0.0-20241210054802-24370beab758 // indirect
100+
sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8 // indirect
101+
sigs.k8s.io/kustomize/api v0.19.0 // indirect
102+
sigs.k8s.io/randfill v1.0.0 // indirect
103+
sigs.k8s.io/structured-merge-diff/v4 v4.6.0 // indirect
99104
)

0 commit comments

Comments
 (0)