Skip to content
This repository was archived by the owner on Mar 17, 2023. It is now read-only.

Commit 66c7fa4

Browse files
committed
feat: initial no-op plugin implementation
1 parent a458b47 commit 66c7fa4

File tree

7 files changed

+470
-0
lines changed

7 files changed

+470
-0
lines changed

go.mod

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module github.com/java-operator-sdk/kubebuilder-plugin
2+
3+
go 1.15
4+
5+
require github.com/spf13/pflag v1.0.5
6+
7+
require sigs.k8s.io/kubebuilder/v3 v3.0.0-alpha.0.0.20210203175028-3c8e370d49c5

go.sum

+183
Large diffs are not rendered by default.

pkg/java/v1/api.go

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright 2021 The Java Operator SDK Authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package v1
18+
19+
import (
20+
"fmt"
21+
"github.com/spf13/pflag"
22+
"sigs.k8s.io/kubebuilder/v3/pkg/config"
23+
"sigs.k8s.io/kubebuilder/v3/pkg/plugin"
24+
)
25+
26+
type createAPISubcommand struct {
27+
config config.Config
28+
}
29+
30+
var (
31+
_ plugin.CreateAPISubcommand = &createAPISubcommand{}
32+
)
33+
34+
func (p createAPISubcommand) UpdateContext(ctx *plugin.Context) {
35+
ctx.Description = `Scaffold a Kubernetes API by creating a Resource definition and / or a Controller.
36+
37+
create resource will prompt the user for if it should scaffold the Resource and / or Controller. To only
38+
scaffold a Controller for an existing Resource, select "n" for Resource. To only define
39+
the schema for a Resource without writing a Controller, select "n" for Controller.
40+
`
41+
}
42+
43+
func (p *createAPISubcommand) BindFlags(fs *pflag.FlagSet) {
44+
}
45+
46+
func (p *createAPISubcommand) InjectConfig(c config.Config) {
47+
p.config = c
48+
}
49+
50+
func (p *createAPISubcommand) Run() error {
51+
fmt.Println("create called")
52+
return nil
53+
}

pkg/java/v1/edit.go

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright 2021 The Java Operator SDK Authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package v1
18+
19+
import (
20+
"fmt"
21+
22+
"github.com/spf13/pflag"
23+
24+
"sigs.k8s.io/kubebuilder/v3/pkg/config"
25+
"sigs.k8s.io/kubebuilder/v3/pkg/plugin"
26+
)
27+
28+
type editSubcommand struct {
29+
config config.Config
30+
}
31+
32+
var (
33+
_ plugin.EditSubcommand = &editSubcommand{}
34+
)
35+
36+
func (p *editSubcommand) UpdateContext(ctx *plugin.Context) {
37+
ctx.Description = `This command will edit the project configuration.`
38+
}
39+
40+
func (p *editSubcommand) BindFlags(fs *pflag.FlagSet) {
41+
}
42+
43+
func (p *editSubcommand) InjectConfig(c config.Config) {
44+
p.config = c
45+
}
46+
47+
func (p *editSubcommand) Run() error {
48+
fmt.Println("edit called")
49+
return nil
50+
}

pkg/java/v1/init.go

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright 2021 The Java Operator SDK Authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package v1
18+
19+
import (
20+
"fmt"
21+
"github.com/spf13/pflag"
22+
23+
"sigs.k8s.io/kubebuilder/v3/pkg/config"
24+
"sigs.k8s.io/kubebuilder/v3/pkg/plugin"
25+
)
26+
27+
type initSubcommand struct {
28+
config config.Config
29+
// For help text.
30+
commandName string
31+
}
32+
33+
var (
34+
_ plugin.InitSubcommand = &initSubcommand{}
35+
)
36+
37+
func (p *initSubcommand) UpdateContext(ctx *plugin.Context) {
38+
ctx.Description = `Initialize a new project based on the java-operator-sdk project.
39+
40+
Writes the following files:
41+
- a basic, Quarkus-based operator set-up
42+
- a pom.xml file to build the project with Maven
43+
`
44+
p.commandName = ctx.CommandName
45+
}
46+
47+
func (p *initSubcommand) BindFlags(fs *pflag.FlagSet) {
48+
}
49+
50+
func (p *initSubcommand) InjectConfig(c config.Config) {
51+
p.config = c
52+
}
53+
54+
func (p *initSubcommand) Run() error {
55+
fmt.Println("init called")
56+
return nil
57+
}

pkg/java/v1/plugin.go

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright 2021 The Java Operator SDK Authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package v1
18+
19+
import (
20+
"sigs.k8s.io/kubebuilder/v3/pkg/config"
21+
"sigs.k8s.io/kubebuilder/v3/pkg/model/stage"
22+
"sigs.k8s.io/kubebuilder/v3/pkg/plugin"
23+
)
24+
25+
const pluginName = "quarkus.javaoperatorsdk.io"
26+
27+
var (
28+
supportedProjectVersions = []config.Version{{
29+
Number: 1,
30+
Stage: stage.Alpha,
31+
}}
32+
pluginVersion = plugin.Version{Number: 1}
33+
)
34+
35+
var _ plugin.Full = Plugin{}
36+
37+
// Plugin implements the plugin.Full interface
38+
type Plugin struct {
39+
initSubcommand
40+
createAPISubcommand
41+
createWebhookSubcommand
42+
editSubcommand
43+
}
44+
45+
// Name returns the name of the plugin
46+
func (Plugin) Name() string { return pluginName }
47+
48+
// Version returns the version of the plugin
49+
func (Plugin) Version() plugin.Version { return pluginVersion }
50+
51+
// SupportedProjectVersions returns an array with all project versions supported by the plugin
52+
func (Plugin) SupportedProjectVersions() []config.Version { return supportedProjectVersions }
53+
54+
// GetInitSubcommand will return the subcommand which is responsible for initializing and common scaffolding
55+
func (p Plugin) GetInitSubcommand() plugin.InitSubcommand { return &p.initSubcommand }
56+
57+
// GetCreateAPISubcommand will return the subcommand which is responsible for scaffolding apis
58+
func (p Plugin) GetCreateAPISubcommand() plugin.CreateAPISubcommand { return &p.createAPISubcommand }
59+
60+
// GetCreateWebhookSubcommand will return the subcommand which is responsible for scaffolding webhooks
61+
func (p Plugin) GetCreateWebhookSubcommand() plugin.CreateWebhookSubcommand {
62+
return &p.createWebhookSubcommand
63+
}
64+
65+
// GetEditSubcommand will return the subcommand which is responsible for editing the scaffold of the project
66+
func (p Plugin) GetEditSubcommand() plugin.EditSubcommand { return &p.editSubcommand }

pkg/java/v1/webhook.go

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright 2021 The Java Operator SDK Authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package v1
18+
19+
import (
20+
"fmt"
21+
"github.com/spf13/pflag"
22+
23+
"sigs.k8s.io/kubebuilder/v3/pkg/config"
24+
"sigs.k8s.io/kubebuilder/v3/pkg/plugin"
25+
)
26+
27+
type createWebhookSubcommand struct {
28+
config config.Config
29+
// For help text.
30+
commandName string
31+
}
32+
33+
var (
34+
_ plugin.CreateWebhookSubcommand = &createWebhookSubcommand{}
35+
)
36+
37+
func (p *createWebhookSubcommand) UpdateContext(ctx *plugin.Context) {
38+
ctx.Description = `Scaffold a webhook for an API resource. You can choose to scaffold defaulting,
39+
validating and (or) conversion webhooks.
40+
`
41+
p.commandName = ctx.CommandName
42+
}
43+
44+
func (p *createWebhookSubcommand) BindFlags(fs *pflag.FlagSet) {
45+
}
46+
47+
func (p *createWebhookSubcommand) InjectConfig(c config.Config) {
48+
p.config = c
49+
}
50+
51+
func (p *createWebhookSubcommand) Run() error {
52+
fmt.Println("webhook called")
53+
return nil
54+
}

0 commit comments

Comments
 (0)