Skip to content

Commit 639531c

Browse files
authored
Merge pull request #1 from kris-nova/init
Init
2 parents 5d8acbf + 3c74e1c commit 639531c

18 files changed

+3936
-487
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.idea
2+
*.idea*
3+
.idea/*

.idea/falcoctl.iml

Lines changed: 0 additions & 9 deletions
This file was deleted.

.idea/misc.xml

Lines changed: 0 additions & 6 deletions
This file was deleted.

.idea/modules.xml

Lines changed: 0 additions & 8 deletions
This file was deleted.

.idea/vcs.xml

Lines changed: 0 additions & 6 deletions
This file was deleted.

.idea/watcherTasks.xml

Lines changed: 0 additions & 53 deletions
This file was deleted.

.idea/workspace.xml

Lines changed: 0 additions & 63 deletions
This file was deleted.

cmd/installRule.go renamed to cmd/delete.go

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,26 @@ import (
2121
"github.com/spf13/cobra"
2222
)
2323

24-
// installRuleCmd represents the installRule command
25-
var installRuleCmd = &cobra.Command{
26-
Use: "installRule",
27-
Short: "A brief description of your command",
28-
Long: `A longer description that spans multiple lines and likely contains examples
29-
and usage of using your command. For example:
30-
31-
Cobra is a CLI library for Go that empowers applications.
32-
This application is a tool to generate the needed files
33-
to quickly create a Cobra application.`,
24+
// deleteCmd represents the delete command
25+
var deleteCmd = &cobra.Command{
26+
Use: "delete",
27+
Short: "Delete a resource",
28+
Long: ``,
3429
Run: func(cmd *cobra.Command, args []string) {
35-
fmt.Println("installRule called")
30+
fmt.Println("delete called")
3631
},
3732
}
3833

3934
func init() {
40-
installCmd.AddCommand(installRuleCmd)
35+
rootCmd.AddCommand(deleteCmd)
4136

4237
// Here you will define your flags and configuration settings.
4338

4439
// Cobra supports Persistent Flags which will work for this command
4540
// and all subcommands, e.g.:
46-
// installRuleCmd.PersistentFlags().String("foo", "", "A help for foo")
41+
// deleteCmd.PersistentFlags().String("foo", "", "A help for foo")
4742

4843
// Cobra supports local flags which will only run when this command
4944
// is called directly, e.g.:
50-
// installRuleCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
45+
// deleteCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
5146
}

cmd/deleteFalco.go

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
Copyright © 2019 Kris Nova <[email protected]>
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+
package cmd
17+
18+
import (
19+
"fmt"
20+
"os"
21+
22+
kubernetesfalc "github.com/kris-nova/falcoctl/kubernetes"
23+
"github.com/kubicorn/kubicorn/pkg/cli"
24+
"github.com/kubicorn/kubicorn/pkg/local"
25+
"github.com/kubicorn/kubicorn/pkg/logger"
26+
27+
"github.com/spf13/cobra"
28+
)
29+
30+
// deleteFalcoCmd represents the deleteFalco command
31+
var (
32+
deleteFalcoCmd = &cobra.Command{
33+
Use: "falco",
34+
Short: "Delete Falco from Kubernetes",
35+
Long: ``,
36+
Run: func(cmd *cobra.Command, args []string) {
37+
err, exitCode := DeleteFalcoEntry(i, kubeConfigPath)
38+
if err != nil {
39+
logger.Critical("Fatal error: %v", err)
40+
os.Exit(exitCode)
41+
}
42+
logger.Always("Success.")
43+
/// os.Exit(1) },
44+
},
45+
}
46+
)
47+
48+
var (
49+
// Global for all install methods
50+
i = &kubernetesfalc.FalcoInstaller{}
51+
kubeConfigPath string
52+
)
53+
54+
func init() {
55+
deleteCmd.AddCommand(deleteFalcoCmd)
56+
installFalcoCmd.Flags().StringVarP(&kubeConfigPath, "kube-config-path", "k",
57+
cli.StrEnvDef("FALCOCTL_KUBE_CONFIG_PATH", fmt.Sprintf("%s/.kube/config", local.Home())),
58+
"Set the path to the Kube config")
59+
installFalcoCmd.Flags().StringVarP(&i.NamespaceName, "namespace", "n",
60+
cli.StrEnvDef("FALCOCTL_KUBE_NAMESPACE", "falco"), "Set the namespace to install Falco in")
61+
}
62+
63+
func DeleteFalcoEntry(installer *kubernetesfalc.FalcoInstaller, kubeConfigPath string) (error, int) {
64+
k8s, err := kubernetesfalc.NewK8sFromKubeConfigPath(kubeConfigPath)
65+
if err != nil {
66+
return fmt.Errorf("unable to parse kube config: %v", err), 98
67+
}
68+
err = installer.Delete(k8s)
69+
if err != nil {
70+
return fmt.Errorf("unable to delete falco in Kubernetes: %v", err), 99
71+
}
72+
return nil, 0
73+
}

cmd/install.go

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,23 @@ limitations under the License.
1616
package cmd
1717

1818
import (
19-
"fmt"
20-
2119
"github.com/spf13/cobra"
2220
)
2321

2422
// installCmd represents the install command
2523
var installCmd = &cobra.Command{
2624
Use: "install",
2725
Short: "Install a component wih falcoctl",
28-
Long: ``,
29-
Run: func(cmd *cobra.Command, args []string) {
30-
fmt.Println("install called")
31-
},
26+
Long: ``,
27+
//Run: func(cmd *cobra.Command, args []string) {
28+
// fmt.Println("install called")
29+
//},
3230
}
3331

3432
func init() {
3533
rootCmd.AddCommand(installCmd)
3634

37-
// Here you will define your flags and configuration settings.
38-
39-
// Cobra supports Persistent Flags which will work for this command
40-
// and all subcommands, e.g.:
41-
// installCmd.PersistentFlags().String("foo", "", "A help for foo")
42-
43-
// Cobra supports local flags which will only run when this command
44-
// is called directly, e.g.:
45-
// installCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
35+
installCmd.AddCommand(installFalcoCmd)
36+
//installCmd.AddCommand(installOutputCmd)
37+
//installCmd.AddCommand(installRuleCmd)
4638
}

0 commit comments

Comments
 (0)