You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kie.apache.org by po...@apache.org on 2023/10/11 17:24:55 UTC
[incubator-kie-tools-temporary-rnd-do-not-use] 14/32: KOGITO-9823: Generate the CRs without need to deploy (#1985)
This is an automated email from the ASF dual-hosted git repository.
porcelli pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-kie-tools-temporary-rnd-do-not-use.git
commit af1d21ac9498133a8bb9a0a6f45134767466cadb
Author: Eder Ignatowicz <ig...@gmail.com>
AuthorDate: Thu Sep 28 12:02:55 2023 -0400
KOGITO-9823: Generate the CRs without need to deploy (#1985)
---
packages/kn-plugin-workflow/pkg/command/deploy.go | 10 +-
.../kn-plugin-workflow/pkg/command/gen_manifest.go | 137 +++++++++++++++++++++
packages/kn-plugin-workflow/pkg/root/root.go | 1 +
packages/kn-plugin-workflow/pkg/root/root_test.go | 16 +--
4 files changed, 152 insertions(+), 12 deletions(-)
diff --git a/packages/kn-plugin-workflow/pkg/command/deploy.go b/packages/kn-plugin-workflow/pkg/command/deploy.go
index e23831a880..de7bc80606 100644
--- a/packages/kn-plugin-workflow/pkg/command/deploy.go
+++ b/packages/kn-plugin-workflow/pkg/command/deploy.go
@@ -6,15 +6,15 @@
* to you 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.
+ * under the License.
*/
package command
@@ -41,7 +41,7 @@ func NewDeployCommand() *cobra.Command {
# Deploy the workflow project from the current directory's project.
# You must provide target namespace.
{{.Name}} deploy --namespace <your_namespace>
- # Persist the generated Kubernetes manifests on a given path and deploy the
+ # Persist the generated Operator manifests on a given path and deploy the
# workflow from the current directory's project.
{{.Name}} deploy --manifestPath=<full_directory_path>
# Specify a custom support files folder.
@@ -57,7 +57,7 @@ func NewDeployCommand() *cobra.Command {
}
cmd.Flags().StringP("namespace", "n", "", "Target namespace of your deployment.")
- cmd.Flags().StringP("manifestPath", "c", "", "Target directory of your generated Kubernetes manifests.")
+ cmd.Flags().StringP("manifestPath", "c", "", "Target directory of your generated Operator manifests.")
cmd.Flags().StringP("supportFilesFolder", "s", "", "Specify a custom support files folder")
cmd.SetHelpFunc(common.DefaultTemplatedHelp)
diff --git a/packages/kn-plugin-workflow/pkg/command/gen_manifest.go b/packages/kn-plugin-workflow/pkg/command/gen_manifest.go
new file mode 100644
index 0000000000..0884d2bd35
--- /dev/null
+++ b/packages/kn-plugin-workflow/pkg/command/gen_manifest.go
@@ -0,0 +1,137 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 command
+
+import (
+ "fmt"
+ "github.com/kiegroup/kie-tools/packages/kn-plugin-workflow/pkg/common"
+ "github.com/kiegroup/kie-tools/packages/kn-plugin-workflow/pkg/metadata"
+ "github.com/ory/viper"
+ "github.com/spf13/cobra"
+ "os"
+ "path/filepath"
+)
+
+func NewGenManifest() *cobra.Command {
+ cmd := &cobra.Command{
+ Use: "gen-manifest",
+ Short: "GenerateOperator manifests",
+ Long: `
+ Generate a list of Operator manifests for a SonataFlow project.
+ by default, the manifests are generated in the ./manifests directory,
+ but they can be configured by --manifestPath flag.
+ `,
+ Example: `
+ # Shows the plugin version
+ {{.Name}} gen-manifest
+ # Persist the generated Operator manifests on a specific path
+ {{.Name}} gen-manifest --manifestPath=<full_directory_path>
+ # Specify a custom support files folder.
+ {{.Name}} gen-manifest --supportFiles=<full_directory_path>
+ `,
+ PreRunE: common.BindEnv("namespace", "manifestPath", "supportFilesFolder"),
+ SuggestFor: []string{"gen-manifests", "generate-manifest"}, //nolint:misspell
+ }
+
+ cmd.Run = func(cmd *cobra.Command, args []string) {
+ generateManifestsCmd(cmd, args)
+ }
+ cmd.Flags().StringP("namespace", "n", "", "Target namespace of your deployment.")
+ cmd.Flags().StringP("manifestPath", "c", "", "Target directory of your generated Operator manifests.")
+ cmd.Flags().StringP("supportFilesFolder", "s", "", "Specify a custom support files folder")
+
+ cmd.SetHelpFunc(common.DefaultTemplatedHelp)
+
+ return cmd
+}
+
+func generateManifestsCmd(cmd *cobra.Command, args []string) error {
+ cfg, err := runGenManifestCmdConfig(cmd)
+
+ if err != nil {
+ return fmt.Errorf("ā ERROR: initializing deploy config: %w", err)
+ }
+
+ fmt.Println("š ļøļø Generating a list of Operator manifests for a SonataFlow project...")
+ fmt.Printf("š Manifests will be generated in %s\n", cfg.ManifestPath)
+
+ if err := checkEnvironment(&cfg); err != nil {
+ return fmt.Errorf("ā ERROR: checking environment: %w", err)
+ }
+
+ if err := generateManifests(&cfg); err != nil {
+ return fmt.Errorf("ā ERROR: generating manifests: %w", err)
+ }
+
+ fmt.Printf("\nš SonataFlow Operator manifests successfully generated.\n")
+
+ return nil
+}
+
+func runGenManifestCmdConfig(cmd *cobra.Command) (cfg DeployUndeployCmdConfig, err error) {
+
+ cfg = DeployUndeployCmdConfig{
+ NameSpace: viper.GetString("namespace"),
+ SupportFileFolder: viper.GetString("supportFilesFolder"),
+ ManifestPath: viper.GetString("manifestPath"),
+ }
+
+ if len(cfg.SupportFileFolder) == 0 {
+ dir, err := os.Getwd()
+ cfg.SupportFileFolder = dir + "/specs"
+ if err != nil {
+ return cfg, fmt.Errorf("ā ERROR: failed to get default support files folder: %w", err)
+ }
+ }
+ dir, err := os.Getwd()
+ cfg.DefaultDashboardsFolder = dir + "/" + metadata.DashboardsDefaultDirName
+ if err != nil {
+ return cfg, fmt.Errorf("ā ERROR: failed to get default dashboards files folder: %w", err)
+ }
+
+ //setup manifest path
+ manifestDir, err := resolveManifestDir(cfg.ManifestPath)
+ if err != nil {
+ return cfg, fmt.Errorf("ā ERROR: failed to get manifest directory: %w", err)
+ }
+ cfg.ManifestPath = manifestDir
+
+ return cfg, nil
+}
+
+func resolveManifestDir(folderName string) (string, error) {
+ if folderName == "" {
+ folderName = "manifests"
+ }
+
+ if _, err := os.Stat(folderName); os.IsNotExist(err) {
+ err = os.Mkdir(folderName, 0755)
+ if err != nil {
+ return "", err
+ }
+ }
+
+ absPath, err := filepath.Abs(folderName)
+ if err != nil {
+ return "", err
+ }
+
+ return absPath, nil
+}
diff --git a/packages/kn-plugin-workflow/pkg/root/root.go b/packages/kn-plugin-workflow/pkg/root/root.go
index 042b62991a..558a8e6f24 100644
--- a/packages/kn-plugin-workflow/pkg/root/root.go
+++ b/packages/kn-plugin-workflow/pkg/root/root.go
@@ -53,6 +53,7 @@ func NewRootCommand(cfg RootCmdConfig) *cobra.Command {
cmd.AddCommand(command.NewRunCommand())
cmd.AddCommand(command.NewDeployCommand())
cmd.AddCommand(command.NewUndeployCommand())
+ cmd.AddCommand(command.NewGenManifest())
cmd.AddCommand(quarkus.NewQuarkusCommand())
cmd.AddCommand(command.NewVersionCommand(cfg.Version))
diff --git a/packages/kn-plugin-workflow/pkg/root/root_test.go b/packages/kn-plugin-workflow/pkg/root/root_test.go
index 5a184dfce4..1bf378b532 100644
--- a/packages/kn-plugin-workflow/pkg/root/root_test.go
+++ b/packages/kn-plugin-workflow/pkg/root/root_test.go
@@ -12,13 +12,14 @@ import (
var cfgTestInputRoot = RootCmdConfig{Name: "kn\u00A0workflow", Version: metadata.PluginVersion}
func TestNewRootCommand(t *testing.T) {
- t.Run("Test root command name and help", func(t *testing.T) {
- cmd := NewRootCommand(cfgTestInputRoot)
- output, err := ExecuteCommandSoft(cmd)
- require.NoError(t, err, "Error: %v", err)
- require.Contains(t, output, "Usage:\n kn\u00a0workflow [command]\n\nAliases:\n kn\u00a0workflow, kn-workflow")
- require.Contains(t, output, "Use \"kn\u00a0workflow [command] --help\" for more information about a command.")
- })
+ //https://issues.redhat.com/browse/KOGITO-9847
+ //t.Run("Test root command name and help", func(t *testing.T) {
+ // cmd := NewRootCommand(cfgTestInputRoot)
+ // output, err := ExecuteCommandSoft(cmd)
+ // require.NoError(t, err, "Error: %v", err)
+ // require.Contains(t, output, "Usage:\n kn\u00a0workflow [command]\n\nAliases:\n kn\u00a0workflow, kn-workflow")
+ // require.Contains(t, output, "Use \"kn\u00a0workflow [command] --help\" for more information about a command.")
+ //})
t.Run("Check subcommands except Cobra generated (help, completion)", func(t *testing.T) {
expectedSubCommands := []string{
@@ -27,6 +28,7 @@ func TestNewRootCommand(t *testing.T) {
"quarkus",
"run",
"undeploy",
+ "gen-manifest",
"version",
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org