MCPcopy
hub / github.com/kubernetes-sigs/kwok / Scale

Function Scale

pkg/kwokctl/scale/scale.go:56–318  ·  view source on GitHub ↗

Scale scales a resource in a cluster.

(ctx context.Context, clientset client.Clientset, conf Config)

Source from the content-addressed store, hash-verified

54
55// Scale scales a resource in a cluster.
56func Scale(ctx context.Context, clientset client.Clientset, conf Config) error {
57 if conf.SerialLength == 0 && conf.Replicas > 1 {
58 return fmt.Errorf("serial length must be greater than 0 when replicas is greater than 1")
59 }
60
61 param := conf.Parameters
62
63 name := conf.Name
64 namespace := conf.Namespace
65 index := 0
66 renderer := gotpl.NewRenderer(gotpl.FuncMap{
67 "Name": func() string {
68 return name
69 },
70 "Namespace": func() string {
71 return namespace
72 },
73 "Index": func() int {
74 return index
75 },
76 "AddCIDR": utilsnet.AddCIDRStr,
77 "AddIP": utilsnet.AddIPStr,
78 })
79 data, err := renderer.ToJSON(conf.Template, param)
80 if err != nil {
81 return err
82 }
83
84 if conf.DryRun {
85 dryrun.PrintMessagef("# Scale resource %s to %d replicas", conf.Name, conf.Replicas)
86 dryrun.PrintMessagef("# Resource example: %s", string(data))
87 return nil
88 }
89
90 var u *unstructured.Unstructured
91 err = json.Unmarshal(data, &u)
92 if err != nil {
93 return err
94 }
95 gv, err := schema.ParseGroupVersion(u.GetAPIVersion())
96 if err != nil {
97 return err
98 }
99
100 dynamicClient, err := clientset.ToDynamicClient()
101 if err != nil {
102 return err
103 }
104
105 restMapper, err := clientset.ToRESTMapper()
106 if err != nil {
107 return err
108 }
109 gvr, err := restMapper.ResourceFor(schema.GroupVersionResource{
110 Group: gv.Group,
111 Version: gv.Version,
112 Resource: u.GetKind(),
113 })

Callers 1

runEFunction · 0.92

Calls 15

ToJSONMethod · 0.95
EncodeMethod · 0.95
LoadMethod · 0.95
NewRendererFunction · 0.92
PrintMessagefFunction · 0.92
FromContextFunction · 0.92
NewEncoderFunction · 0.92
NewContextFunction · 0.92
NewLoaderFunction · 0.92
NewDecoderFunction · 0.92
newResourceGeneratorFunction · 0.85
generateSerialNumberFunction · 0.85

Tested by

no test coverage detected