redhat-developer / opencompose

OpenCompose - A higher level abstraction for Kubernetes Resource
Apache License 2.0
64 stars 12 forks source link

Validate generated Kubernetes artifacts #139

Open concaf opened 7 years ago

concaf commented 7 years ago

It'd be great if we start validating the generated Kubernetes artifacts against https://github.com/kubernetes/kubernetes/blob/master/pkg/api/validation/validation.go

concaf commented 7 years ago

We can use this something like -

    validationErrors := kvalidation.ValidateSecret(&kapi.Secret{
        ObjectMeta: kapi.ObjectMeta{
            Name: sec.ObjectMeta.Name,
            // Putting namespace as default here because ValidateSecret errors
            // out if no namespace is provided
            Namespace: "default",
        },
        Data: sec.Data,
    })

    if len(validationErrors) != 0 {
        return nil, fmt.Errorf("failed to validate the generated secret object: %v", validationErrors)
    }
concaf commented 7 years ago

When we will do this, we will required the following -

commit message:

This commit updates glide.yaml to include pkg/api/validation from
k8s.io/kubernetes, which is being used to validate generated
Kubernets objects.

This also fixes the version of github.com/pelletier/go-buffruneio
to v0.1.0. This change is unrelated to the inclusion of
pkg/api/validation mentioned above. This has been done because
github.com/spf13/viper uses github.com/pelletier/go-toml(master)
github.com/pelletier/go-toml(master) uses github.com/pelletier/go-buffruneio(master)
k8s.io/kubernetes(v1.5.7) uses github.com/pelletier/go-buffruneio(v0.1.0)
This breaks our code.
Hence, pinning github.com/pelletier/go-buffruneio to v0.1.0 (same as in
Godeps.json for k8s.io/kubernetes) makes
github.com/pelletier/go-toml in github.com/spf13/viper use the
older version, which does not break our code.

After making the changes in glide.yaml, the vendor/ directory
was updated using the `glide update --strip-vendor` and
`glide-vc --only-code --no-tests --no-test-imports --no-legal-files`
commands.

glide.yaml -

package: github.com/redhat-developer/opencompose
import:
- package: github.com/ghodss/yaml
- package: github.com/spf13/cobra
- package: github.com/spf13/pflag
- package: github.com/spf13/viper
- package: k8s.io/client-go
  version: ^2.0.0
  subpackages:
  - pkg/api/v1
  - pkg/runtime
- package: gopkg.in/yaml.v2
  version: 4c78c975fe7c825c6d1466c42be594d1d6f3aba6
- package: k8s.io/kubernetes
  version: v1.5.7
  subpackages:
  - pkg/api/validation

# github.com/spf13/viper uses github.com/pelletier/go-toml(master)
# github.com/pelletier/go-toml(master) uses github.com/pelletier/go-buffruneio(master)
# k8s.io/kubernetes(v1.5.7) uses github.com/pelletier/go-buffruneio(v0.1.0)
# This breaks our code.
# Hence, pinning github.com/pelletier/go-buffruneio to v0.1.0 (same as in Godeps.json for k8s.io/kubernetes) makes github.com/pelletier/go-toml in github.com/spf13/viper use the older version, which does not break our code.
- package: github.com/pelletier/go-buffruneio
  version: v0.1.0