Skip to content

Commit

Permalink
Merge pull request #3133 from sedefsavas/unstructured
Browse files Browse the repository at this point in the history
🌱 Move clusterctl internal yaml functions under `util/yaml`
  • Loading branch information
k8s-ci-robot authored Jun 4, 2020
2 parents 0e88a40 + 574f13b commit 037eced
Show file tree
Hide file tree
Showing 10 changed files with 257 additions and 286 deletions.
3 changes: 2 additions & 1 deletion cmd/clusterctl/client/cluster/cert_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
manifests "sigs.k8s.io/cluster-api/cmd/clusterctl/config"
"sigs.k8s.io/cluster-api/cmd/clusterctl/internal/util"
logf "sigs.k8s.io/cluster-api/cmd/clusterctl/log"
utilyaml "sigs.k8s.io/cluster-api/util/yaml"
"sigs.k8s.io/controller-runtime/pkg/client"
)

Expand Down Expand Up @@ -180,7 +181,7 @@ func (cm *certManagerClient) getManifestObjs() ([]unstructured.Unstructured, err
return nil, err
}

objs, err := util.ToUnstructured(yaml)
objs, err := utilyaml.ToUnstructured(yaml)
if err != nil {
return nil, errors.Wrap(err, "failed to parse yaml for cert-manager manifest")
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/clusterctl/client/cluster/inventory.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import (
"k8s.io/apimachinery/pkg/util/sets"
clusterctlv1 "sigs.k8s.io/cluster-api/cmd/clusterctl/api/v1alpha3"
"sigs.k8s.io/cluster-api/cmd/clusterctl/config"
"sigs.k8s.io/cluster-api/cmd/clusterctl/internal/util"
logf "sigs.k8s.io/cluster-api/cmd/clusterctl/log"
utilyaml "sigs.k8s.io/cluster-api/util/yaml"
"sigs.k8s.io/controller-runtime/pkg/client"
)

Expand Down Expand Up @@ -129,7 +129,7 @@ func (p *inventoryClient) EnsureCustomResourceDefinitions() error {
}

// Transform the yaml in a list of objects.
objs, err := util.ToUnstructured(yaml)
objs, err := utilyaml.ToUnstructured(yaml)
if err != nil {
return errors.Wrap(err, "failed to parse yaml for clusterctl inventory CRDs")
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/clusterctl/client/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"sigs.k8s.io/cluster-api/cmd/clusterctl/client/cluster"
"sigs.k8s.io/cluster-api/cmd/clusterctl/client/config"
"sigs.k8s.io/cluster-api/cmd/clusterctl/internal/test"
"sigs.k8s.io/cluster-api/cmd/clusterctl/internal/util"
utilyaml "sigs.k8s.io/cluster-api/util/yaml"
)

func Test_clusterctlClient_InitImages(t *testing.T) {
Expand Down Expand Up @@ -618,7 +618,7 @@ func componentsYAML(ns string) []byte {
"metadata:\n" +
" name: manager")

return util.JoinYaml(namespaceYaml, podYaml)
return utilyaml.JoinYaml(namespaceYaml, podYaml)
}

func templateYAML(ns string, clusterName string) []byte {
Expand Down
5 changes: 3 additions & 2 deletions cmd/clusterctl/client/repository/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"sigs.k8s.io/cluster-api/cmd/clusterctl/client/config"
"sigs.k8s.io/cluster-api/cmd/clusterctl/internal/scheme"
"sigs.k8s.io/cluster-api/cmd/clusterctl/internal/util"
utilyaml "sigs.k8s.io/cluster-api/util/yaml"
)

const (
Expand Down Expand Up @@ -171,7 +172,7 @@ func (c *components) Yaml() ([]byte, error) {
objs = append(objs, c.sharedObjs...)
objs = append(objs, c.instanceObjs...)

return util.FromUnstructured(objs)
return utilyaml.FromUnstructured(objs)
}

// ComponentsOptions is the inputs needed by the NewComponents
Expand Down Expand Up @@ -204,7 +205,7 @@ func NewComponents(provider config.Provider, configClient config.Client, rawyaml
}

// Transform the yaml in a list of objects, so following transformation can work on typed objects (instead of working on a string/slice of bytes)
objs, err := util.ToUnstructured(yaml)
objs, err := utilyaml.ToUnstructured(yaml)
if err != nil {
return nil, errors.Wrap(err, "failed to parse yaml")
}
Expand Down
14 changes: 7 additions & 7 deletions cmd/clusterctl/client/repository/components_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
clusterctlv1 "sigs.k8s.io/cluster-api/cmd/clusterctl/api/v1alpha3"
"sigs.k8s.io/cluster-api/cmd/clusterctl/client/config"
"sigs.k8s.io/cluster-api/cmd/clusterctl/internal/test"
"sigs.k8s.io/cluster-api/cmd/clusterctl/internal/util"
utilyaml "sigs.k8s.io/cluster-api/util/yaml"
)

const (
Expand Down Expand Up @@ -96,7 +96,7 @@ func Test_componentsClient_Get(t *testing.T) {
repository: test.NewFakeRepository().
WithPaths("root", "components.yaml").
WithDefaultVersion("v1.0.0").
WithFile("v1.0.0", "components.yaml", util.JoinYaml(namespaceYaml, controllerYaml, configMapYaml)),
WithFile("v1.0.0", "components.yaml", utilyaml.JoinYaml(namespaceYaml, controllerYaml, configMapYaml)),
},
args: args{
version: "v1.0.0",
Expand All @@ -119,7 +119,7 @@ func Test_componentsClient_Get(t *testing.T) {
repository: test.NewFakeRepository().
WithPaths("root", "components.yaml").
WithDefaultVersion("v1.0.0").
WithFile("v1.0.0", "components.yaml", util.JoinYaml(namespaceYaml, controllerYaml, configMapYaml)),
WithFile("v1.0.0", "components.yaml", utilyaml.JoinYaml(namespaceYaml, controllerYaml, configMapYaml)),
},
args: args{
version: "v1.0.0",
Expand All @@ -142,7 +142,7 @@ func Test_componentsClient_Get(t *testing.T) {
repository: test.NewFakeRepository().
WithPaths("root", "components.yaml").
WithDefaultVersion("v1.0.0").
WithFile("v1.0.0", "components.yaml", util.JoinYaml(namespaceYaml, controllerYaml, configMapYaml)),
WithFile("v1.0.0", "components.yaml", utilyaml.JoinYaml(namespaceYaml, controllerYaml, configMapYaml)),
},
args: args{
version: "v1.0.0",
Expand Down Expand Up @@ -180,7 +180,7 @@ func Test_componentsClient_Get(t *testing.T) {
repository: test.NewFakeRepository().
WithPaths("root", "components.yaml").
WithDefaultVersion("v1.0.0").
WithFile("v1.0.0", "components.yaml", util.JoinYaml(controllerYaml, configMapYaml)),
WithFile("v1.0.0", "components.yaml", utilyaml.JoinYaml(controllerYaml, configMapYaml)),
},
args: args{
version: "v1.0.0",
Expand All @@ -196,7 +196,7 @@ func Test_componentsClient_Get(t *testing.T) {
repository: test.NewFakeRepository().
WithPaths("root", "components.yaml").
WithDefaultVersion("v1.0.0").
WithFile("v1.0.0", "components.yaml", util.JoinYaml(controllerYaml, configMapYaml)),
WithFile("v1.0.0", "components.yaml", utilyaml.JoinYaml(controllerYaml, configMapYaml)),
},
args: args{
version: "v1.0.0",
Expand All @@ -219,7 +219,7 @@ func Test_componentsClient_Get(t *testing.T) {
repository: test.NewFakeRepository().
WithPaths("root", "components.yaml").
WithDefaultVersion("v1.0.0").
WithFile("v1.0.0", "components.yaml", util.JoinYaml(controllerYaml, configMapYaml)),
WithFile("v1.0.0", "components.yaml", utilyaml.JoinYaml(controllerYaml, configMapYaml)),
},
args: args{
version: "v2.0.0",
Expand Down
6 changes: 3 additions & 3 deletions cmd/clusterctl/client/repository/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/pkg/errors"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"sigs.k8s.io/cluster-api/cmd/clusterctl/client/config"
"sigs.k8s.io/cluster-api/cmd/clusterctl/internal/util"
utilyaml "sigs.k8s.io/cluster-api/util/yaml"
)

// Template wraps a YAML file that defines the cluster objects (Cluster, Machines etc.).
Expand Down Expand Up @@ -66,7 +66,7 @@ func (t *template) Objs() []unstructured.Unstructured {
}

func (t *template) Yaml() ([]byte, error) {
return util.FromUnstructured(t.objs)
return utilyaml.FromUnstructured(t.objs)
}

// NewTemplate returns a new objects embedding a cluster template YAML file.
Expand All @@ -86,7 +86,7 @@ func NewTemplate(rawYaml []byte, configVariablesClient config.VariablesClient, t
}

// Transform the yaml in a list of objects, so following transformation can work on typed objects (instead of working on a string/slice of bytes).
objs, err := util.ToUnstructured(yaml)
objs, err := utilyaml.ToUnstructured(yaml)
if err != nil {
return nil, errors.Wrap(err, "failed to parse yaml")
}
Expand Down
108 changes: 0 additions & 108 deletions cmd/clusterctl/internal/util/yaml.go

This file was deleted.

Loading

0 comments on commit 037eced

Please sign in to comment.