policy-generator/cmd/policygen/main.go

68 lines
1.2 KiB
Go

package main
import (
"fmt"
"github.com/goccy/go-yaml"
"github.com/spf13/cobra"
"log"
"os"
)
type Options struct {
cni string
policyType string
}
func execute(files []string, options *Options) error {
if len(files) == 0 {
return fmt.Errorf("File expected")
}
for _, file := range files {
config, err := LoadConfig(file)
if err != nil {
return err
}
policyTemplates, err := NewPolicyTemplates()
if err != nil {
return err
}
var generator Generator
generator = NetworkPolicyGenerrator{
config: config,
policyTemplates: policyTemplates,
}
Generate(os.Stdout, generator, config)
}
return nil
}
func main() {
val := map[string]string{
"abc": "1",
}
data, err := yaml.Marshal(val)
if err != nil {
panic(err)
}
log.Printf("val %s", string(data))
//os.Exit(1)
options := Options{
cni: "cilium",
policyType: "netpol",
}
cmd := &cobra.Command{
Use: "policygen",
Short: "Generate network policies",
Long: "Generated policies based on a more compact representation of topology",
RunE: func(cmd *cobra.Command, args []string) error {
return execute(args, &options)
},
}
cmd.Execute()
}