feat: kubesphere 4.0 (#6115)
* feat: kubesphere 4.0 Signed-off-by: ci-bot <ci-bot@kubesphere.io> * feat: kubesphere 4.0 Signed-off-by: ci-bot <ci-bot@kubesphere.io> --------- Signed-off-by: ci-bot <ci-bot@kubesphere.io> Co-authored-by: ks-ci-bot <ks-ci-bot@example.com> Co-authored-by: joyceliu <joyceliu@yunify.com>
This commit is contained in:
committed by
GitHub
parent
b5015ec7b9
commit
447a51f08b
18
vendor/sigs.k8s.io/kustomize/kyaml/openapi/Makefile
generated
vendored
18
vendor/sigs.k8s.io/kustomize/kyaml/openapi/Makefile
generated
vendored
@@ -5,8 +5,8 @@ MYGOBIN = $(shell go env GOBIN)
|
||||
ifeq ($(MYGOBIN),)
|
||||
MYGOBIN = $(shell go env GOPATH)/bin
|
||||
endif
|
||||
API_VERSION := "v1.21.2"
|
||||
KIND_VERSION := "v0.11.1"
|
||||
API_VERSION ?= "v1.21.2"
|
||||
|
||||
.PHONY: all
|
||||
all: \
|
||||
@@ -28,7 +28,7 @@ nuke: clean
|
||||
rm -r kubernetesapi/*
|
||||
|
||||
$(MYGOBIN)/go-bindata:
|
||||
go install github.com/go-bindata/go-bindata/v3/go-bindata
|
||||
go install github.com/go-bindata/go-bindata/v3/go-bindata@latest
|
||||
|
||||
$(MYGOBIN)/kind:
|
||||
( \
|
||||
@@ -40,22 +40,22 @@ $(MYGOBIN)/kind:
|
||||
rm -rf $$d; \
|
||||
)
|
||||
|
||||
.PHONY: kubernetesapi/openapiinfo.go
|
||||
kubernetesapi/openapiinfo.go:
|
||||
./scripts/makeOpenApiInfoDotGo.sh
|
||||
|
||||
kustomizationapi/swagger.go: $(MYGOBIN)/go-bindata kustomizationapi/swagger.json
|
||||
$(MYGOBIN)/go-bindata \
|
||||
--pkg kustomizationapi \
|
||||
-o kustomizationapi/swagger.go \
|
||||
kustomizationapi/swagger.json
|
||||
|
||||
.PHONY: kubernetesapi/openapiinfo.go
|
||||
kubernetesapi/openapiinfo.go:
|
||||
./scripts/makeOpenApiInfoDotGo.sh
|
||||
|
||||
.PHONY: kubernetesapi/swagger.json
|
||||
kubernetesapi/swagger.json: $(MYGOBIN)/kind $(MYGOBIN)/kustomize
|
||||
.PHONY: kubernetesapi/swagger.pb
|
||||
kubernetesapi/swagger.pb: $(MYGOBIN)/kind $(MYGOBIN)/kustomize
|
||||
./scripts/fetchSchemaFromCluster.sh $(API_VERSION)
|
||||
|
||||
.PHONY: kubernetesapi/swagger.go
|
||||
kubernetesapi/swagger.go: $(MYGOBIN)/go-bindata kubernetesapi/swagger.json
|
||||
kubernetesapi/swagger.go: $(MYGOBIN)/go-bindata kubernetesapi/swagger.pb
|
||||
./scripts/generateSwaggerDotGo.sh $(API_VERSION)
|
||||
|
||||
$(MYGOBIN)/kustomize:
|
||||
|
||||
46
vendor/sigs.k8s.io/kustomize/kyaml/openapi/README.md
generated
vendored
46
vendor/sigs.k8s.io/kustomize/kyaml/openapi/README.md
generated
vendored
@@ -22,22 +22,31 @@ make nuke
|
||||
|
||||
The compiled-in schema version should maximize API availability with respect to all actively supported Kubernetes versions. For example, while 1.20, 1.21 and 1.22 are the actively supported versions, 1.21 is the best choice. This is because 1.21 introduces at least one new API and does not remove any, while 1.22 removes a large set of long-deprecated APIs that are still supported in 1.20/1.21.
|
||||
|
||||
### Update the built-in schema to a new version
|
||||
### Generating additional schema
|
||||
|
||||
In the Makefile in this directory, update the `API_VERSION` to your desired version.
|
||||
If you'd like to change the default schema version, then in the Makefile in this directory, update the `API_VERSION` to your desired version.
|
||||
|
||||
You may need to update the version of Kind these scripts use by changing `KIND_VERSION` in the Makefile in this directory. You can find compatibility information in the [kind release notes](https://github.com/kubernetes-sigs/kind/releases).
|
||||
|
||||
In this directory, fetch the openapi schema and generate the
|
||||
corresponding swagger.go for the kubernetes api:
|
||||
In this directory, fetch the openapi schema, generate the
|
||||
corresponding swagger.go for the kubernetes api, and update `kubernetesapi/openapiinfo.go`:
|
||||
|
||||
```
|
||||
make all
|
||||
```
|
||||
|
||||
The above command will update the [OpenAPI schema] and the [Kustomization schema]. It will
|
||||
create a directory kubernetesapi/v1212 and store the resulting
|
||||
swagger.json and swagger.go files there.
|
||||
If you want to run the steps individually instead of using `make all`, you can run
|
||||
the following commands:
|
||||
|
||||
```
|
||||
make kustomizationapi/swagger.go
|
||||
make kubernetesapi/swagger.go
|
||||
make kubernetesapi/openapiinfo.go
|
||||
```
|
||||
|
||||
You can optionally delete the old `swagger.pb` and `swagger.go` files if we no longer need to support that kubernetes version of
|
||||
openapi data. Make sure you rerun `make kubernetesapi/openapiinfo.go` after deleting any old schemas.
|
||||
|
||||
|
||||
#### Precomputations
|
||||
|
||||
@@ -55,25 +64,6 @@ make prow-presubmit-check >& /tmp/k.txt; echo $?
|
||||
|
||||
The exit code should be zero; if not, examine `/tmp/k.txt`.
|
||||
|
||||
## Generating additional schemas
|
||||
|
||||
Instead of replacing the default version, you can specify a desired version as part of the make invocation:
|
||||
|
||||
```
|
||||
rm kubernetesapi/swagger.go
|
||||
make kubernetesapi/swagger.go API_VERSION=v1.21.2
|
||||
```
|
||||
|
||||
While the above commands generate the swagger.go files, they
|
||||
do not make them available for use nor do they update the
|
||||
info field reported by `kustomize openapi info`. To make the
|
||||
newly fetched schema and swagger.go available:
|
||||
|
||||
```
|
||||
rm kubernetesapi/openapiinfo.go
|
||||
make kubernetesapi/openapiinfo.go
|
||||
```
|
||||
|
||||
## Partial regeneration
|
||||
|
||||
You can also regenerate the kubernetes api schemas specifically with:
|
||||
@@ -87,8 +77,8 @@ To fetch the schema without generating the swagger.go, you can
|
||||
run:
|
||||
|
||||
```
|
||||
rm kubernetesapi/swagger.json
|
||||
make kubernetesapi/swagger.json
|
||||
rm kubernetesapi/swagger.pb
|
||||
make kubernetesapi/swagger.pb
|
||||
```
|
||||
|
||||
Note that generating the swagger.go will re-fetch the schema.
|
||||
|
||||
6
vendor/sigs.k8s.io/kustomize/kyaml/openapi/kubernetesapi/openapiinfo.go
generated
vendored
6
vendor/sigs.k8s.io/kustomize/kyaml/openapi/kubernetesapi/openapiinfo.go
generated
vendored
@@ -6,13 +6,13 @@
|
||||
package kubernetesapi
|
||||
|
||||
import (
|
||||
"sigs.k8s.io/kustomize/kyaml/openapi/kubernetesapi/v1212"
|
||||
"sigs.k8s.io/kustomize/kyaml/openapi/kubernetesapi/v1_21_2"
|
||||
)
|
||||
|
||||
const Info = "{title:Kubernetes,version:v1.21.2}"
|
||||
|
||||
var OpenAPIMustAsset = map[string]func(string) []byte{
|
||||
"v1212": v1212.MustAsset,
|
||||
"v1.21.2": v1_21_2.MustAsset,
|
||||
}
|
||||
|
||||
const DefaultOpenAPI = "v1212"
|
||||
const DefaultOpenAPI = "v1.21.2"
|
||||
|
||||
249
vendor/sigs.k8s.io/kustomize/kyaml/openapi/kubernetesapi/v1212/swagger.go
generated
vendored
249
vendor/sigs.k8s.io/kustomize/kyaml/openapi/kubernetesapi/v1212/swagger.go
generated
vendored
File diff suppressed because one or more lines are too long
249
vendor/sigs.k8s.io/kustomize/kyaml/openapi/kubernetesapi/v1_21_2/swagger.go
generated
vendored
Normal file
249
vendor/sigs.k8s.io/kustomize/kyaml/openapi/kubernetesapi/v1_21_2/swagger.go
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
3
vendor/sigs.k8s.io/kustomize/kyaml/openapi/kustomizationapi/swagger.go
generated
vendored
3
vendor/sigs.k8s.io/kustomize/kyaml/openapi/kustomizationapi/swagger.go
generated
vendored
@@ -11,7 +11,6 @@ import (
|
||||
"compress/gzip"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@@ -215,7 +214,7 @@ func RestoreAsset(dir, name string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = ioutil.WriteFile(_filePath(dir, name), data, info.Mode())
|
||||
err = os.WriteFile(_filePath(dir, name), data, info.Mode())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
75
vendor/sigs.k8s.io/kustomize/kyaml/openapi/openapi.go
generated
vendored
75
vendor/sigs.k8s.io/kustomize/kyaml/openapi/openapi.go
generated
vendored
@@ -6,12 +6,13 @@ package openapi
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
openapi_v2 "github.com/google/gnostic/openapiv2"
|
||||
openapi_v2 "github.com/google/gnostic-models/openapiv2"
|
||||
"google.golang.org/protobuf/proto"
|
||||
"k8s.io/kube-openapi/pkg/validation/spec"
|
||||
"sigs.k8s.io/kustomize/kyaml/errors"
|
||||
@@ -21,14 +22,27 @@ import (
|
||||
k8syaml "sigs.k8s.io/yaml"
|
||||
)
|
||||
|
||||
// globalSchema contains global state information about the openapi
|
||||
var globalSchema openapiData
|
||||
var (
|
||||
// schemaLock is the lock for schema related globals.
|
||||
//
|
||||
// NOTE: This lock helps with preventing panics that might occur due to the data
|
||||
// race that concurrent access on this variable might cause but it doesn't
|
||||
// fully fix the issue described in https://github.com/kubernetes-sigs/kustomize/issues/4824.
|
||||
// For instance concurrently running goroutines where each of them calls SetSchema()
|
||||
// and/or GetSchemaVersion might end up received nil errors (success) whereas the
|
||||
// seconds one would overwrite the global variable that has been written by the
|
||||
// first one.
|
||||
schemaLock sync.RWMutex //nolint:gochecknoglobals
|
||||
|
||||
// kubernetesOpenAPIVersion specifies which builtin kubernetes schema to use
|
||||
var kubernetesOpenAPIVersion string
|
||||
// kubernetesOpenAPIVersion specifies which builtin kubernetes schema to use.
|
||||
kubernetesOpenAPIVersion string //nolint:gochecknoglobals
|
||||
|
||||
// customSchemaFile stores the custom OpenApi schema if it is provided
|
||||
var customSchema []byte
|
||||
// globalSchema contains global state information about the openapi
|
||||
globalSchema openapiData //nolint:gochecknoglobals
|
||||
|
||||
// customSchemaFile stores the custom OpenApi schema if it is provided
|
||||
customSchema []byte //nolint:gochecknoglobals
|
||||
)
|
||||
|
||||
// openapiData contains the parsed openapi state. this is in a struct rather than
|
||||
// a list of vars so that it can be reset from tests.
|
||||
@@ -104,7 +118,7 @@ var precomputedIsNamespaceScoped = map[yaml.TypeMeta]bool{
|
||||
{APIVersion: "node.k8s.io/v1beta1", Kind: "RuntimeClass"}: false,
|
||||
{APIVersion: "policy/v1", Kind: "PodDisruptionBudget"}: true,
|
||||
{APIVersion: "policy/v1beta1", Kind: "PodDisruptionBudget"}: true,
|
||||
{APIVersion: "policy/v1beta1", Kind: "PodSecurityPolicy"}: false,
|
||||
{APIVersion: "policy/v1beta1", Kind: "PodSecurityPolicy"}: false, // remove after openapi upgrades to v1.25.
|
||||
{APIVersion: "rbac.authorization.k8s.io/v1", Kind: "ClusterRole"}: false,
|
||||
{APIVersion: "rbac.authorization.k8s.io/v1", Kind: "ClusterRoleBinding"}: false,
|
||||
{APIVersion: "rbac.authorization.k8s.io/v1", Kind: "Role"}: true,
|
||||
@@ -220,7 +234,7 @@ func definitionRefsFromRNode(object *yaml.RNode) ([]string, error) {
|
||||
|
||||
// parseOpenAPI reads openAPIPath yaml and converts it to RNode
|
||||
func parseOpenAPI(openAPIPath string) (*yaml.RNode, error) {
|
||||
b, err := ioutil.ReadFile(openAPIPath)
|
||||
b, err := os.ReadFile(openAPIPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -278,9 +292,12 @@ func AddSchema(s []byte) error {
|
||||
|
||||
// ResetOpenAPI resets the openapi data to empty
|
||||
func ResetOpenAPI() {
|
||||
schemaLock.Lock()
|
||||
defer schemaLock.Unlock()
|
||||
|
||||
globalSchema = openapiData{}
|
||||
kubernetesOpenAPIVersion = ""
|
||||
customSchema = nil
|
||||
kubernetesOpenAPIVersion = ""
|
||||
}
|
||||
|
||||
// AddDefinitions adds the definitions to the global schema.
|
||||
@@ -400,7 +417,7 @@ func SuppressBuiltInSchemaUse() {
|
||||
|
||||
// Elements returns the Schema for the elements of an array.
|
||||
func (rs *ResourceSchema) Elements() *ResourceSchema {
|
||||
// load the schema from swagger.json
|
||||
// load the schema from swagger files
|
||||
initSchema()
|
||||
|
||||
if len(rs.Schema.Type) != 1 || rs.Schema.Type[0] != "array" {
|
||||
@@ -446,7 +463,7 @@ func (rs *ResourceSchema) Lookup(path ...string) *ResourceSchema {
|
||||
|
||||
// Field returns the Schema for a field.
|
||||
func (rs *ResourceSchema) Field(field string) *ResourceSchema {
|
||||
// load the schema from swagger.json
|
||||
// load the schema from swagger files
|
||||
initSchema()
|
||||
|
||||
// locate the Schema
|
||||
@@ -459,7 +476,7 @@ func (rs *ResourceSchema) Field(field string) *ResourceSchema {
|
||||
// (the key doesn't matter, they all have the same value type)
|
||||
s = *rs.Schema.AdditionalProperties.Schema
|
||||
default:
|
||||
// no Schema found from either swagger.json or line comments
|
||||
// no Schema found from either swagger files or line comments
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -545,24 +562,28 @@ const (
|
||||
groupKey = "group"
|
||||
// versionKey is the key to lookup the version from the GVK extension
|
||||
versionKey = "version"
|
||||
// kindKey is the the to lookup the kind from the GVK extension
|
||||
// kindKey is the to lookup the kind from the GVK extension
|
||||
kindKey = "kind"
|
||||
)
|
||||
|
||||
// SetSchema sets the kubernetes OpenAPI schema version to use
|
||||
func SetSchema(openAPIField map[string]string, schema []byte, reset bool) error {
|
||||
schemaLock.Lock()
|
||||
defer schemaLock.Unlock()
|
||||
|
||||
// this should only be set once
|
||||
schemaIsSet := (kubernetesOpenAPIVersion != "") || customSchema != nil
|
||||
if schemaIsSet && !reset {
|
||||
return nil
|
||||
}
|
||||
|
||||
version, exists := openAPIField["version"]
|
||||
if exists && schema != nil {
|
||||
return fmt.Errorf("builtin version and custom schema provided, cannot use both")
|
||||
}
|
||||
version, versionProvided := openAPIField["version"]
|
||||
|
||||
if schema != nil { // use custom schema
|
||||
// use custom schema
|
||||
if schema != nil {
|
||||
if versionProvided {
|
||||
return fmt.Errorf("builtin version and custom schema provided, cannot use both")
|
||||
}
|
||||
customSchema = schema
|
||||
kubernetesOpenAPIVersion = "custom"
|
||||
// if the schema is changed, initSchema should parse the new schema
|
||||
@@ -571,13 +592,14 @@ func SetSchema(openAPIField map[string]string, schema []byte, reset bool) error
|
||||
}
|
||||
|
||||
// use builtin version
|
||||
kubernetesOpenAPIVersion = strings.ReplaceAll(version, ".", "")
|
||||
kubernetesOpenAPIVersion = version
|
||||
if kubernetesOpenAPIVersion == "" {
|
||||
return nil
|
||||
}
|
||||
if _, ok := kubernetesapi.OpenAPIMustAsset[kubernetesOpenAPIVersion]; !ok {
|
||||
return fmt.Errorf("the specified OpenAPI version is not built in")
|
||||
}
|
||||
|
||||
customSchema = nil
|
||||
// if the schema is changed, initSchema should parse the new schema
|
||||
globalSchema.schemaInit = false
|
||||
@@ -586,6 +608,9 @@ func SetSchema(openAPIField map[string]string, schema []byte, reset bool) error
|
||||
|
||||
// GetSchemaVersion returns what kubernetes OpenAPI version is being used
|
||||
func GetSchemaVersion() string {
|
||||
schemaLock.RLock()
|
||||
defer schemaLock.RUnlock()
|
||||
|
||||
switch {
|
||||
case kubernetesOpenAPIVersion == "" && customSchema == nil:
|
||||
return kubernetesOpenAPIDefaultVersion
|
||||
@@ -598,6 +623,9 @@ func GetSchemaVersion() string {
|
||||
|
||||
// initSchema parses the json schema
|
||||
func initSchema() {
|
||||
schemaLock.Lock()
|
||||
defer schemaLock.Unlock()
|
||||
|
||||
if globalSchema.schemaInit {
|
||||
return
|
||||
}
|
||||
@@ -607,7 +635,7 @@ func initSchema() {
|
||||
if customSchema != nil {
|
||||
err := parse(customSchema, JsonOrYaml)
|
||||
if err != nil {
|
||||
panic("invalid schema file")
|
||||
panic(fmt.Errorf("invalid schema file: %w", err))
|
||||
}
|
||||
} else {
|
||||
if kubernetesOpenAPIVersion == "" {
|
||||
@@ -629,11 +657,10 @@ func parseBuiltinSchema(version string) {
|
||||
// don't parse the built in schema
|
||||
return
|
||||
}
|
||||
|
||||
// parse the swagger, this should never fail
|
||||
assetName := filepath.Join(
|
||||
"kubernetesapi",
|
||||
version,
|
||||
strings.ReplaceAll(version, ".", "_"),
|
||||
"swagger.pb")
|
||||
|
||||
if err := parse(kubernetesapi.OpenAPIMustAsset[version](assetName), Proto); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user