Improve memory performance of clusterctl KRM

Switching components type from []byte to string significantly
improves memory effiency of config function.

Change-Id: I81ddf469bf5abd214ff3785915d82ab494af6268
Signed-off-by: Ruslan Aliev <raliev@mirantis.com>
This commit is contained in:
Ruslan Aliev 2021-10-13 13:19:56 -05:00
parent 4bce04c86b
commit 136aa06117
4 changed files with 9 additions and 17 deletions

View File

@ -41,7 +41,7 @@ const (
type ClusterctlOptions struct {
CmdOptions []string `json:"cmd-options,omitempty"`
Config []byte `json:"config,omitempty"`
Components map[string][]byte `json:"components,omitempty"`
Components map[string]string `json:"components,omitempty"`
}
// Run prepares config, repo tree and executes clusterctl with appropriate options
@ -65,7 +65,7 @@ func (c *ClusterctlOptions) buildRepoTree() error {
return err
}
}
if err := ioutil.WriteFile(f, component, filePerm); err != nil {
if err := ioutil.WriteFile(f, []byte(component), filePerm); err != nil {
return err
}
}

View File

@ -115,7 +115,7 @@ func DefaultClusterctl() *Clusterctl {
type ClusterctlOptions struct {
CmdOptions []string `json:"cmd-options,omitempty"`
Config []byte `json:"config,omitempty"`
Components map[string][]byte `json:"components,omitempty"`
Components map[string]string `json:"components,omitempty"`
}
// GetKubeconfigOptions carries all the options to retrieve kubeconfig from parent cluster

View File

@ -511,17 +511,9 @@ func (in *ClusterctlOptions) DeepCopyInto(out *ClusterctlOptions) {
}
if in.Components != nil {
in, out := &in.Components, &out.Components
*out = make(map[string][]byte, len(*in))
*out = make(map[string]string, len(*in))
for key, val := range *in {
var outVal []byte
if val == nil {
(*out)[key] = nil
} else {
in, out := &val, &outVal
*out = make([]byte, len(*in))
copy(*out, *in)
}
(*out)[key] = outVal
(*out)[key] = val
}
}
}

View File

@ -69,7 +69,7 @@ func NewClusterctlExecutor(cfg ifc.ExecutorConfig) (ifc.Executor, error) {
return nil, err
}
cctlOpts := &airshipv1.ClusterctlOptions{
Components: map[string][]byte{},
Components: map[string]string{},
}
if err := initRepoData(options, cctlOpts, cfg.TargetPath); err != nil {
return nil, err
@ -134,7 +134,7 @@ func initRepoData(c *airshipv1.Clusterctl, o *airshipv1.ClusterctlOptions, targe
return err
}
o.Components[filepath.Join(componentDir, "metadata.yaml")] = metadata
o.Components[filepath.Join(componentDir, "metadata.yaml")] = string(metadata)
filteredBundle, err := bundle.SelectBundle(document.NewDeployToK8sSelector())
if err != nil {
@ -146,7 +146,7 @@ func initRepoData(c *airshipv1.Clusterctl, o *airshipv1.ClusterctlOptions, targe
return err
}
prv.URL = filepath.Join(componentDir, fmt.Sprintf("%s-components.yaml", typeMap[prv.Type]))
o.Components[prv.URL] = buffer.Bytes()
o.Components[prv.URL] = string(buffer.Bytes())
}
return nil
}
@ -330,7 +330,7 @@ func (c *ClusterctlExecutor) Render(w io.Writer, ro ifc.RenderOptions) error {
dataAll := &bytes.Buffer{}
for path, data := range c.cctlOpts.Components {
if strings.Contains(path, "components.yaml") {
dataAll.Write(append(data, []byte("\n---\n")...))
dataAll.Write(append([]byte(data), []byte("\n---\n")...))
}
}