mirror of
https://github.com/kubernetes/kubernetes.git
synced 2026-02-18 18:28:18 -05:00
Replace cmd/yamlfmt with k-sigs/yaml/yamlfmt
And run it.
This commit is contained in:
parent
2cb955d8cc
commit
7adcd21148
10 changed files with 24 additions and 150 deletions
|
|
@ -1,10 +0,0 @@
|
|||
# See the OWNERS docs at https://go.k8s.io/owners
|
||||
|
||||
reviewers:
|
||||
- bentheelder
|
||||
- dims
|
||||
approvers:
|
||||
- dims
|
||||
labels:
|
||||
- sig/testing
|
||||
- sig/contributor-experience
|
||||
|
|
@ -1,72 +0,0 @@
|
|||
/*
|
||||
Copyright 2021 The Kubernetes Authors.
|
||||
|
||||
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
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
|
||||
yaml "go.yaml.in/yaml/v3"
|
||||
)
|
||||
|
||||
func main() {
|
||||
indent := flag.Int("indent", 2, "default indent")
|
||||
flag.Parse()
|
||||
for _, path := range flag.Args() {
|
||||
sourceYaml, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "%s: %v\n", path, err)
|
||||
continue
|
||||
}
|
||||
rootNode, err := fetchYaml(sourceYaml)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "%s: %v\n", path, err)
|
||||
continue
|
||||
}
|
||||
writer, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "%s: %v\n", path, err)
|
||||
continue
|
||||
}
|
||||
err = streamYaml(writer, indent, rootNode)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "%s: %v\n", path, err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func fetchYaml(sourceYaml []byte) (*yaml.Node, error) {
|
||||
rootNode := yaml.Node{}
|
||||
err := yaml.Unmarshal(sourceYaml, &rootNode)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &rootNode, nil
|
||||
}
|
||||
|
||||
func streamYaml(writer io.Writer, indent *int, in *yaml.Node) error {
|
||||
encoder := yaml.NewEncoder(writer)
|
||||
encoder.SetIndent(*indent)
|
||||
err := encoder.Encode(in)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return encoder.Close()
|
||||
}
|
||||
|
|
@ -1,53 +0,0 @@
|
|||
/*
|
||||
Copyright 2021 The Kubernetes Authors.
|
||||
|
||||
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
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestFetchYaml(t *testing.T) {
|
||||
sourceYaml := ` # See the OWNERS docs at https://go.k8s.io/owners
|
||||
approvers:
|
||||
- dep-approvers
|
||||
- thockin # Network
|
||||
- liggitt
|
||||
|
||||
labels:
|
||||
- sig/architecture
|
||||
`
|
||||
|
||||
outputYaml := `# See the OWNERS docs at https://go.k8s.io/owners
|
||||
approvers:
|
||||
- dep-approvers
|
||||
- thockin # Network
|
||||
- liggitt
|
||||
labels:
|
||||
- sig/architecture
|
||||
`
|
||||
node, _ := fetchYaml([]byte(sourceYaml))
|
||||
var output bytes.Buffer
|
||||
indent := 2
|
||||
writer := bufio.NewWriter(&output)
|
||||
_ = streamYaml(writer, &indent, node)
|
||||
_ = writer.Flush()
|
||||
assert.Equal(t, outputYaml, output.String(), "yaml was not formatted correctly")
|
||||
}
|
||||
2
go.mod
2
go.mod
|
|
@ -72,7 +72,6 @@ require (
|
|||
go.uber.org/goleak v1.3.0
|
||||
go.uber.org/zap v1.27.0
|
||||
go.yaml.in/yaml/v2 v2.4.2
|
||||
go.yaml.in/yaml/v3 v3.0.4
|
||||
golang.org/x/crypto v0.36.0
|
||||
golang.org/x/net v0.38.0
|
||||
golang.org/x/oauth2 v0.27.0
|
||||
|
|
@ -208,6 +207,7 @@ require (
|
|||
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.60.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.34.0 // indirect
|
||||
go.uber.org/multierr v1.11.0 // indirect
|
||||
go.yaml.in/yaml/v3 v3.0.4 // indirect
|
||||
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect
|
||||
golang.org/x/mod v0.21.0 // indirect
|
||||
golang.org/x/text v0.23.0 // indirect
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ require (
|
|||
gotest.tools/gotestsum v1.12.0
|
||||
honnef.co/go/tools v0.6.1
|
||||
k8s.io/publishing-bot v0.5.0
|
||||
sigs.k8s.io/yaml v1.6.0
|
||||
)
|
||||
|
||||
require (
|
||||
|
|
@ -51,6 +52,7 @@ require (
|
|||
github.com/spf13/viper v1.20.0 // indirect
|
||||
github.com/subosito/gotenv v1.6.0 // indirect
|
||||
go.uber.org/multierr v1.11.0 // indirect
|
||||
go.yaml.in/yaml/v3 v3.0.3 // indirect
|
||||
golang.org/x/exp/typeparams v0.0.0-20250210185358-939b2ce775ac // indirect
|
||||
golang.org/x/sync v0.13.0 // indirect
|
||||
golang.org/x/sys v0.32.0 // indirect
|
||||
|
|
|
|||
|
|
@ -115,6 +115,10 @@ go.uber.org/automaxprocs v1.6.0 h1:O3y2/QNTOdbF+e/dpXNNW7Rx2hZ4sTIPyybbxyNqTUs=
|
|||
go.uber.org/automaxprocs v1.6.0/go.mod h1:ifeIMSnPZuznNm6jmdzmU3/bfk01Fe2fotchwEFJ8r8=
|
||||
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
|
||||
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
|
||||
go.yaml.in/yaml/v2 v2.4.2 h1:DzmwEr2rDGHl7lsFgAHxmNz/1NlQ7xLIrlN2h5d1eGI=
|
||||
go.yaml.in/yaml/v2 v2.4.2/go.mod h1:081UH+NErpNdqlCXm3TtEran0rJZGxAYx9hb/ELlsPU=
|
||||
go.yaml.in/yaml/v3 v3.0.3 h1:bXOww4E/J3f66rav3pX3m8w6jDE4knZjGOw8b5Y6iNE=
|
||||
go.yaml.in/yaml/v3 v3.0.3/go.mod h1:tBHosrYAkRZjRAOREWbDnBXUf08JOwYq++0QNwQiWzI=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
|
|
@ -242,3 +246,7 @@ k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE=
|
|||
k8s.io/publishing-bot v0.5.0 h1:Hfnhltr+khEcqvoK4GBYrtaA8dHJ50Xjyi+0KGUfU3I=
|
||||
k8s.io/publishing-bot v0.5.0/go.mod h1:S5+zQQhsVUEqdcaohbYf8O+2BeeWRtuYzp4tQLr5An8=
|
||||
k8s.io/utils v0.0.0-20210802155522-efc7438f0176/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
|
||||
sigs.k8s.io/randfill v1.0.0 h1:JfjMILfT8A6RbawdsK2JXGBR5AQVfd+9TbzrlneTyrU=
|
||||
sigs.k8s.io/randfill v1.0.0/go.mod h1:XeLlZ/jmk4i1HRopwe7/aU3H5n1zNUcX6TM94b3QxOY=
|
||||
sigs.k8s.io/yaml v1.6.0 h1:G8fkbMSAFqgEFgh4b1wmtzDnioxFCUgTZhlbj5P9QYs=
|
||||
sigs.k8s.io/yaml v1.6.0/go.mod h1:796bPqUfzR/0jLAl6XjHl3Ck7MiyVv8dbTdyT3/pMf4=
|
||||
|
|
|
|||
|
|
@ -45,4 +45,7 @@ import (
|
|||
// protobuf generation
|
||||
_ "google.golang.org/grpc/cmd/protoc-gen-go-grpc"
|
||||
_ "google.golang.org/protobuf/cmd/protoc-gen-go"
|
||||
|
||||
// yamlfmt
|
||||
_ "sigs.k8s.io/yaml/yamlfmt"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -314,9 +314,9 @@ options:
|
|||
# make root approval non-recursive
|
||||
no_parent_owners: true
|
||||
approvers:
|
||||
- dep-approvers
|
||||
- dep-approvers
|
||||
reviewers:
|
||||
- dep-reviewers
|
||||
- dep-reviewers
|
||||
__EOF__
|
||||
|
||||
# === Disallow transitive dependencies on k8s.io/kubernetes
|
||||
|
|
|
|||
|
|
@ -26,15 +26,11 @@ kube::golang::setup_env
|
|||
cd "${KUBE_ROOT}"
|
||||
|
||||
find_files() {
|
||||
find . -not \( \
|
||||
\( \
|
||||
-wholename './.git' \
|
||||
-o -wholename './_output' \
|
||||
-o -wholename './release' \
|
||||
-o -wholename './target' \
|
||||
-o -wholename '*/vendor/*' \
|
||||
\) -prune \
|
||||
\) -name 'OWNERS*'
|
||||
git ls-files \
|
||||
'OWNERS*' \
|
||||
'**/OWNERS*' \
|
||||
':!:vendor/*/OWNERS*'
|
||||
}
|
||||
|
||||
find_files | xargs go run cmd/yamlfmt/yamlfmt.go
|
||||
go -C "${KUBE_ROOT}/hack/tools" install sigs.k8s.io/yaml/yamlfmt
|
||||
find_files | xargs yamlfmt -o yaml -w
|
||||
|
|
|
|||
4
vendor/OWNERS
vendored
4
vendor/OWNERS
vendored
|
|
@ -4,6 +4,6 @@ options:
|
|||
# make root approval non-recursive
|
||||
no_parent_owners: true
|
||||
approvers:
|
||||
- dep-approvers
|
||||
- dep-approvers
|
||||
reviewers:
|
||||
- dep-reviewers
|
||||
- dep-reviewers
|
||||
|
|
|
|||
Loading…
Reference in a new issue