mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 14:37:00 +00:00
Clean up standalone conversion tool
Remove kube-version-change for all its functionalities are covered by kubectl convert command. Also changed the related docs.
This commit is contained in:
parent
56f72aeb45
commit
763edd3011
@ -1,25 +0,0 @@
|
||||
/*
|
||||
Copyright 2015 The Kubernetes Authors All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
// These imports are the API groups the kube-version-change tool will support.
|
||||
import (
|
||||
_ "k8s.io/kubernetes/pkg/api/install"
|
||||
_ "k8s.io/kubernetes/pkg/apis/componentconfig/install"
|
||||
_ "k8s.io/kubernetes/pkg/apis/extensions/install"
|
||||
_ "k8s.io/kubernetes/pkg/apis/metrics/install"
|
||||
)
|
@ -1,129 +0,0 @@
|
||||
/*
|
||||
Copyright 2014 The Kubernetes Authors All rights reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// kube-version-change is a simple utility for converting a
|
||||
// kubernetes object into a different api version.
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"runtime"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/latest"
|
||||
"k8s.io/kubernetes/pkg/util"
|
||||
|
||||
"github.com/ghodss/yaml"
|
||||
flag "github.com/spf13/pflag"
|
||||
)
|
||||
|
||||
var (
|
||||
inputSource = flag.StringP("input", "i", "-", "Input source; '-' means stdin")
|
||||
outputDest = flag.StringP("output", "o", "-", "Output destination; '-' means stdout")
|
||||
rewrite = flag.StringP("rewrite", "r", "", "If nonempty, use this as both input and output.")
|
||||
outputVersion = flag.StringP("out-version", "v", latest.GroupOrDie(api.GroupName).GroupVersion.Version, "Version to convert input to")
|
||||
)
|
||||
|
||||
// isYAML determines whether data is JSON or YAML formatted by seeing
|
||||
// if it will parse as json.
|
||||
func isYAML(data []byte) bool {
|
||||
var unused interface{}
|
||||
if err := json.Unmarshal(data, &unused); err != nil {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func main() {
|
||||
runtime.GOMAXPROCS(runtime.NumCPU())
|
||||
flag.CommandLine.SetNormalizeFunc(util.WordSepNormalizeFunc)
|
||||
flag.Parse()
|
||||
|
||||
if *rewrite != "" {
|
||||
*inputSource = *rewrite
|
||||
*outputDest = *rewrite
|
||||
}
|
||||
|
||||
var in io.Reader
|
||||
if *inputSource == "-" {
|
||||
in = os.Stdin
|
||||
} else {
|
||||
f, err := os.Open(*inputSource)
|
||||
if err != nil {
|
||||
log.Fatalf("Couldn't open %q: %q", *inputSource, err)
|
||||
}
|
||||
defer f.Close()
|
||||
in = f
|
||||
}
|
||||
|
||||
data, err := ioutil.ReadAll(in)
|
||||
if err != nil {
|
||||
log.Fatalf("Couldn't read from input: %q", err)
|
||||
}
|
||||
isYAML := isYAML(data)
|
||||
|
||||
if isYAML {
|
||||
data, err = yaml.YAMLToJSON(data)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to convert YAML to JSON: %q", err)
|
||||
}
|
||||
}
|
||||
obj, err := api.Scheme.Decode(data)
|
||||
if err != nil {
|
||||
log.Fatalf("Couldn't decode input: %q", err)
|
||||
}
|
||||
|
||||
outData, err := api.Scheme.EncodeToVersion(obj, *outputVersion)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to encode to version %q: %q", *outputVersion, err)
|
||||
}
|
||||
|
||||
if isYAML {
|
||||
outData, err = yaml.JSONToYAML(outData)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to convert to YAML: %q", err)
|
||||
}
|
||||
} else if true {
|
||||
// TODO: figure out if input JSON was pretty.
|
||||
var buf bytes.Buffer
|
||||
err = json.Indent(&buf, outData, "", " ")
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to indent JSON: %q", err)
|
||||
}
|
||||
outData = buf.Bytes()
|
||||
}
|
||||
|
||||
var out io.Writer
|
||||
if *outputDest == "-" {
|
||||
out = os.Stdout
|
||||
} else {
|
||||
f, err := os.Create(*outputDest)
|
||||
if err != nil {
|
||||
log.Fatalf("Couldn't open %q: %q", *outputDest, err)
|
||||
}
|
||||
defer f.Close()
|
||||
out = f
|
||||
}
|
||||
|
||||
if _, err = out.Write(outData); err != nil {
|
||||
log.Fatalf("Failed to write: %q", err)
|
||||
}
|
||||
}
|
@ -204,13 +204,13 @@ for changes to this variable to take effect.
|
||||
|
||||
### Switching your config files to a new API version
|
||||
|
||||
You can use the `kube-version-change` utility to convert config files between different API versions.
|
||||
You can use `kubectl convert` command to convert config files between different API versions.
|
||||
|
||||
```console
|
||||
$ hack/build-go.sh cmd/kube-version-change
|
||||
$ _output/local/go/bin/kube-version-change -i myPod.v1beta3.yaml -o myPod.v1.yaml
|
||||
$ kubectl convert -f pod.yaml --output-version v1
|
||||
```
|
||||
|
||||
For more options, please refer to the usage of [kubectl convert](../user-guide/kubectl/kubectl_convert.md) command.
|
||||
|
||||
<!-- BEGIN MUNGE: GENERATED_ANALYTICS -->
|
||||
[]()
|
||||
|
@ -121,7 +121,7 @@ As of June 4, 2015, the Kubernetes v1 API has been enabled by default. The v1bet
|
||||
|
||||
### v1 conversion tips (from v1beta3)
|
||||
|
||||
We're working to convert all documentation and examples to v1. A simple [API conversion tool](admin/cluster-management.md#switching-your-config-files-to-a-new-api-version) has been written to simplify the translation process. Use `kubectl create --validate` in order to validate your json or yaml against our Swagger spec.
|
||||
We're working to convert all documentation and examples to v1. Use `kubectl create --validate` in order to validate your json or yaml against our Swagger spec.
|
||||
|
||||
Changes to services are the most significant difference between v1beta3 and v1.
|
||||
|
||||
|
@ -42,7 +42,7 @@ We plan on improving the way the types are factored in the future; see [#16062](
|
||||
|
||||
2. Create pkg/apis/`<group>`/{register.go, `<version>`/register.go} to register this group's API objects to the encoding/decoding scheme (e.g., [pkg/apis/extensions/register.go](../../pkg/apis/extensions/register.go) and [pkg/apis/extensions/v1beta1/register.go](../../pkg/apis/extensions/v1beta1/register.go);
|
||||
|
||||
3. Add a pkg/apis/`<group>`/install/install.go, which is responsible for adding the group to the `latest` package, so that other packages can access the group's meta through `latest.Group`. You probably only need to change the name of group and version in the [example](../../pkg/apis/extensions/install/install.go)). You need to import this `install` package in {pkg/master, pkg/client/unversioned, cmd/kube-version-change}/import_known_versions.go, if you want to make your group accessible to other packages in the kube-apiserver binary, binaries that uses the client package, or the kube-version-change tool.
|
||||
3. Add a pkg/apis/`<group>`/install/install.go, which is responsible for adding the group to the `latest` package, so that other packages can access the group's meta through `latest.Group`. You probably only need to change the name of group and version in the [example](../../pkg/apis/extensions/install/install.go)). You need to import this `install` package in {pkg/master, pkg/client/unversioned}/import_known_versions.go, if you want to make your group accessible to other packages in the kube-apiserver binary, binaries that uses the client package.
|
||||
|
||||
Step 2 and 3 are mechanical, we plan on autogenerate these using the cmd/libs/go2idl/ tool.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user