forked from fabric8io/kubernetes-client
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix fabric8io#2108: Split Kubernetes Model into smaller Jars
- Loading branch information
1 parent
555c379
commit 78ddf50
Showing
373 changed files
with
511,815 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# | ||
# Copyright (C) 2015 Red Hat, Inc. | ||
# | ||
# 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. | ||
# | ||
|
||
SHELL := /bin/bash | ||
|
||
all: build | ||
|
||
build: gobuild | ||
mvn clean install | ||
|
||
gobuild: | ||
dep ensure -v | ||
CGO_ENABLED=0 GO15VENDOREXPERIMENT=1 go build -a ./cmd/generate/generate.go | ||
./generate > src/main/resources/schema/kube-schema.json | ||
./generate validation > src/main/resources/schema/validation-schema.json |
121 changes: 121 additions & 0 deletions
121
kubernetes-model/kubernetes-model-admission/cmd/generate/generate.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
/** | ||
* Copyright (C) 2015 Red Hat, Inc. | ||
* | ||
* 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 ( | ||
"bytes" | ||
"encoding/json" | ||
"fmt" | ||
// Dependencies | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/api/resource" | ||
apimachineryversion "k8s.io/apimachinery/pkg/version" | ||
|
||
admission "k8s.io/api/admission/v1beta1" | ||
|
||
"log" | ||
"reflect" | ||
"strings" | ||
"time" | ||
|
||
"os" | ||
|
||
"github.com/fabric8io/kubernetes-client/kubernetes-model/pkg/schemagen" | ||
) | ||
|
||
type Schema struct { | ||
Info apimachineryversion.Info | ||
APIGroup metav1.APIGroup | ||
APIGroupList metav1.APIGroupList | ||
BaseKubernetesList metav1.List | ||
ObjectMeta metav1.ObjectMeta | ||
TypeMeta metav1.TypeMeta | ||
Status metav1.Status | ||
Patch metav1.Patch | ||
ListOptions metav1.ListOptions | ||
DeleteOptions metav1.DeleteOptions | ||
CreateOptions metav1.CreateOptions | ||
UpdateOptions metav1.UpdateOptions | ||
GetOptions metav1.GetOptions | ||
PatchOptions metav1.PatchOptions | ||
Time metav1.Time | ||
RootPaths metav1.RootPaths | ||
Quantity resource.Quantity | ||
|
||
AdmissionReview admission.AdmissionReview | ||
AdmissionRequest admission.AdmissionRequest | ||
AdmissionResponse admission.AdmissionResponse | ||
PatchType admission.PatchType | ||
Operation admission.Operation | ||
} | ||
|
||
func main() { | ||
customTypeNames := map[string]string{ | ||
"K8sSubjectAccessReview": "SubjectAccessReview", | ||
"K8sLocalSubjectAccessReview": "LocalSubjectAccessReview", | ||
"JSONSchemaPropsorStringArray": "JSONSchemaPropsOrStringArray", | ||
} | ||
packages := []schemagen.PackageDescriptor{ | ||
{"k8s.io/api/admission/v1beta1", "admission.k8s.io", "io.fabric8.kubernetes.api.model.admission", "kubernetes_admission_"}, | ||
{"k8s.io/apimachinery/pkg/util/intstr", "", "io.fabric8.kubernetes.api.model", "kubernetes_apimachinery_pkg_util_intstr_"}, | ||
{"k8s.io/apimachinery/pkg/runtime", "", "io.fabric8.kubernetes.api.model.runtime", "kubernetes_apimachinery_pkg_runtime_"}, | ||
{"k8s.io/apimachinery/pkg/version", "", "io.fabric8.kubernetes.api.model.version", "kubernetes_apimachinery_pkg_version_"}, | ||
{"k8s.io/apimachinery/pkg/apis/meta/v1", "", "io.fabric8.kubernetes.api.model", "kubernetes_apimachinery_"}, | ||
} | ||
|
||
typeMap := map[reflect.Type]reflect.Type{ | ||
reflect.TypeOf(time.Time{}): reflect.TypeOf(""), | ||
reflect.TypeOf(struct{}{}): reflect.TypeOf(""), | ||
} | ||
schema, err := schemagen.GenerateSchema(reflect.TypeOf(Schema{}), packages, typeMap, customTypeNames) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "An error occurred: %v", err) | ||
return | ||
} | ||
|
||
args := os.Args[1:] | ||
if len(args) < 1 || args[0] != "validation" { | ||
schema.Resources = nil | ||
} | ||
|
||
b, err := json.Marshal(&schema) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
result := string(b) | ||
result = strings.Replace(result, "\"additionalProperty\":", "\"additionalProperties\":", -1) | ||
|
||
/** | ||
* Hack to fix https://github.com/fabric8io/kubernetes-client/issues/1565 | ||
* | ||
* Right now enums are having body as array of jsons rather than being array of strings. | ||
* (See https://user-images.githubusercontent.com/13834498/59852204-00d25680-938c-11e9-91b6-74f6bc3ae65b.png) | ||
* | ||
* I could not find any other way of fixing this since I'm not sure where it's coming from. | ||
* So doing this search and replace of whole enum json object block hence converting it to an array of plain | ||
* strings rather than of json objects. | ||
*/ | ||
result = strings.Replace(result, "\"enum\":{\"type\":\"array\",\"description\":\"\",\"javaOmitEmpty\":true,\"items\":{\"$ref\":\"#/definitions/kubernetes_apiextensions_JSON\",\"javaType\":\"io.fabric8.kubernetes.api.model.apiextensions.JSON\"}},", | ||
"\"enum\":{\"type\":\"array\",\"description\":\"\",\"javaOmitEmpty\":true,\"items\":{\"type\": \"string\"}},", -1) | ||
|
||
var out bytes.Buffer | ||
err = json.Indent(&out, []byte(result), "", " ") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
fmt.Println(out.String()) | ||
} |
Binary file not shown.
Oops, something went wrong.