/
create-deployment.go
71 lines (62 loc) · 3.61 KB
/
create-deployment.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package cmd
import (
"fmt"
"os"
"github.com/laetho/metagraf/internal/pkg/params"
"github.com/laetho/metagraf/pkg/metagraf"
"github.com/laetho/metagraf/pkg/modules"
"github.com/spf13/cobra"
"github.com/spf13/viper"
log "k8s.io/klog"
)
func init() {
RootCmd.AddCommand(createCmd)
createCmd.AddCommand(createDeploymentCmd)
createDeploymentCmd.Flags().StringVarP(&Namespace, "namespace", "n", "", "namespace to work on, if not supplied it will use current working namespace")
createDeploymentCmd.Flags().StringVar(&OName, "name", "", "Overrides name of deployment.")
createDeploymentCmd.Flags().StringSliceVar(&CVars, "cvars", []string{}, "Slice of key=value pairs, seperated by ,")
createDeploymentCmd.Flags().StringVar(¶ms.PropertiesFile, "cvfile", "", "File with component configuration values. (key=value pairs)")
createDeploymentCmd.Flags().BoolVar(&BaseEnvs, "baseenv", false, "Hydrate deploymentconfig with baseimage environment variables")
createDeploymentCmd.Flags().BoolVar(&Defaults, "defaults", false, "Populate Environment variables with default values from metaGraf")
createDeploymentCmd.Flags().StringVarP(&ImageNS, "imagens", "i", "", "Image Namespace, used to override default namespace")
createDeploymentCmd.Flags().StringVar(¶ms.ImageName, "imagename", "", "Set image artifact name. Overrides imagename from metaGraf spec parsing behaviour.")
createDeploymentCmd.Flags().StringVarP(&Registry, "registry", "r", viper.GetString("registry"), "Specify container registry host")
createDeploymentCmd.Flags().StringVarP(&Tag, "tag", "t", "latest", "specify custom tag")
createDeploymentCmd.Flags().Int32Var(¶ms.Replicas, "replicas", params.DefaultReplicas, "Number of replicas.")
createDeploymentCmd.Flags().BoolVar(¶ms.DisableDeploymentImageAliasing, "disable-aliasing", false, "Only applies to .spec.image references. Aliasing will use mg conventions for image references. Setting this to true will disable that behavior.")
createDeploymentCmd.Flags().BoolVar(¶ms.WithAffinityRules, "with-affinity-rules", params.WithPodAffinityRulesDefault, "Enable generation of pod affinity or anti-affinity rules.")
createDeploymentCmd.Flags().StringVar(¶ms.PodAntiAffinityTopologyKey, "anti-affinity-topology-key", "", "Define which node label to use as a topologyKey (describing a datacenter, zone or a rack as an example)")
createDeploymentCmd.Flags().Int32Var(¶ms.PodAntiAffinityWeight, "pod-anti-affinity-weight", params.PodAntiAffinityWeightDefault, "Weight for WeightedPodAffinityTerm.")
createDeploymentCmd.Flags().BoolVar(¶ms.DownwardAPIEnvVars,"downward-api-envvars",false,"Enables generation of environment variables from Downward API. An opinionated selection.")
}
var createDeploymentCmd = &cobra.Command{
Use: "deployment <metagraf>",
Short: "create Deployment from metaGraf file",
Long: MGBanner + `create Deployment`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) < 1 {
log.Info(StrActiveProject, viper.Get("namespace"))
log.Error(StrMissingMetaGraf)
os.Exit(1)
}
if len(Namespace) == 0 {
Namespace = viper.GetString("namespace")
if len(Namespace) == 0 {
log.Error(StrMissingNamespace)
os.Exit(1)
}
}
params.NameSpace = Namespace
if params.WithAffinityRules && len(params.PodAntiAffinityTopologyKey) == 0 {
fmt.Println("ERROR: --affinity-topology-key cannot be empty when --with-affinity-rules is active!")
os.Exit(1)
}
mg := metagraf.Parse(args[0])
FlagPassingHack()
modules.Variables = GetCmdProperties(mg.GetProperties())
if len(modules.NameSpace) == 0 {
modules.NameSpace = Namespace
}
modules.GenDeployment(&mg, Namespace)
},
}