-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
417 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
Copyright 2022 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package alphav1 | ||
|
||
import ( | ||
"sigs.k8s.io/kubebuilder/v3/pkg/machinery" | ||
"sigs.k8s.io/kubebuilder/v3/pkg/plugin" | ||
"sigs.k8s.io/kubebuilder/v3/pkg/plugins/optional/grafana/alphav1/scaffolds" | ||
) | ||
|
||
var _ plugin.InitSubcommand = &initSubcommand{} | ||
|
||
type initSubcommand struct{} | ||
|
||
func (p *initSubcommand) Scaffold(fs machinery.Filesystem) error { | ||
scaffolder := scaffolds.NewInitScaffolder() | ||
scaffolder.InjectFS(fs) | ||
return scaffolder.Scaffold() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
Copyright 2022 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package alphav1 | ||
|
||
import ( | ||
"sigs.k8s.io/kubebuilder/v3/pkg/config" | ||
cfgv3 "sigs.k8s.io/kubebuilder/v3/pkg/config/v3" | ||
"sigs.k8s.io/kubebuilder/v3/pkg/model/stage" | ||
"sigs.k8s.io/kubebuilder/v3/pkg/plugin" | ||
"sigs.k8s.io/kubebuilder/v3/pkg/plugins" | ||
) | ||
|
||
const pluginName = "grafana." + plugins.DefaultNameQualifier | ||
|
||
var ( | ||
pluginVersion = plugin.Version{Number: 1, Stage: stage.Alpha} | ||
supportedProjectVersions = []config.Version{cfgv3.Version} | ||
pluginKey = plugin.KeyFor(Plugin{}) // FIXME: what is pluginKey used for? | ||
) | ||
|
||
// Plugin implements the plugin.Full interface | ||
type Plugin struct { | ||
initSubcommand | ||
|
||
// TODO: | ||
// editSubcommand | ||
} | ||
|
||
var ( | ||
_ plugin.Init = Plugin{} | ||
) | ||
|
||
// Name returns the name of the plugin | ||
func (Plugin) Name() string { return pluginName } | ||
|
||
// Version returns the version of the grafana plugin | ||
func (Plugin) Version() plugin.Version { return pluginVersion } | ||
|
||
// SupportedProjectVersions returns an array with all project versions supported by the plugin | ||
func (Plugin) SupportedProjectVersions() []config.Version { return supportedProjectVersions } | ||
|
||
// GetInitSubcommand will return the subcommand which is responsible for initializing and scaffolding grafana manifests | ||
func (p Plugin) GetInitSubcommand() plugin.InitSubcommand { return &p.initSubcommand } | ||
|
||
// TODO | ||
// GetEditSubcommand will return the subcommand which is responsible for editing the scaffold of grafana manifests | ||
// func (p Plugin) GetEditSubcommand() plugin.EditSubcommand { return &p.editSubcommand } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
Copyright 2022 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package scaffolds | ||
|
||
import ( | ||
"fmt" | ||
|
||
"sigs.k8s.io/kubebuilder/v3/pkg/machinery" | ||
"sigs.k8s.io/kubebuilder/v3/pkg/plugins" | ||
"sigs.k8s.io/kubebuilder/v3/pkg/plugins/optional/grafana/alphav1/scaffolds/internal/templates" | ||
) | ||
|
||
var _ plugins.Scaffolder = &initScaffolder{} | ||
|
||
type initScaffolder struct { | ||
// fs is the filesystem that will be used by the scaffolder | ||
fs machinery.Filesystem | ||
} | ||
|
||
// NewInitScaffolder returns a new Scaffolder for project initialization operations | ||
func NewInitScaffolder() plugins.Scaffolder { | ||
return &initScaffolder{} | ||
} | ||
|
||
// InjectFS implements cmdutil.Scaffolder | ||
func (s *initScaffolder) InjectFS(fs machinery.Filesystem) { | ||
s.fs = fs | ||
} | ||
|
||
// Scaffold implements cmdutil.Scaffolder | ||
func (s *initScaffolder) Scaffold() error { | ||
fmt.Println("Generating Grafana manifests to visualize controller status...") | ||
|
||
// Initialize the machinery.Scaffold that will write the files to disk | ||
scaffold := machinery.NewScaffold(s.fs) | ||
|
||
return scaffold.Execute( | ||
&templates.OverallManifest{}, | ||
) | ||
} |
Oops, something went wrong.