diff --git a/extensions/tekton/client/src/main/resources/resource-operation.vm b/extensions/tekton/client/src/main/resources/resource-operation.vm index b992aba790b..7139a92310b 100644 --- a/extensions/tekton/client/src/main/resources/resource-operation.vm +++ b/extensions/tekton/client/src/main/resources/resource-operation.vm @@ -24,11 +24,14 @@ #if ($annotation.getClassRef().getName().equals("ApiGroup")) #set ($apiGroupName = $annotation.getParameters().get("value")) #end - #if ($annotation.getClassRef().getName().equals("Namespaced")) - #set ($isResourceNamespacedFlag = $annotation.getParameters().get("value")) - #end #end +#set ($isResourceNamespacedFlag = false) +#foreach ($impl in $model.getImplementsList()) + #if ($impl.getFullyQualifiedName().equals("io.fabric8.kubernetes.api.model.Namespaced")) + #set ($isResourceNamespacedFlag = true) + #end +#end package io.fabric8.tekton.client.internal.$apiGroupVersion; diff --git a/extensions/tekton/generateModel.sh b/extensions/tekton/generateModel.sh new file mode 100755 index 00000000000..c5857d95966 --- /dev/null +++ b/extensions/tekton/generateModel.sh @@ -0,0 +1,26 @@ +# +# 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. +# + +declare -a modules=("generator-v1alpha1" "generator-v1beta1" +) + +for module in ${modules[*]} +do + echo "Compiling ${module}" + cd $module + make + cd .. +done diff --git a/extensions/tekton/generator-v1alpha1/cmd/generate/generate.go b/extensions/tekton/generator-v1alpha1/cmd/generate/generate.go index 583542011f8..35a1b79d87d 100644 --- a/extensions/tekton/generator-v1alpha1/cmd/generate/generate.go +++ b/extensions/tekton/generator-v1alpha1/cmd/generate/generate.go @@ -28,16 +28,16 @@ func main() { // the CRD List types for which the model should be generated // no other types need to be defined as they are auto discovered - crdLists := []reflect.Type{ + crdLists := map[reflect.Type]schemagen.CrdScope{ // v1alpha1 - reflect.TypeOf(v1alpha1.ConditionList{}), - reflect.TypeOf(v1alpha1.PipelineList{}), - reflect.TypeOf(v1alpha1.PipelineRunList{}), - reflect.TypeOf(v1alpha1.TaskList{}), - reflect.TypeOf(v1alpha1.TaskRunList{}), - reflect.TypeOf(v1alpha1.ClusterTaskList{}), + reflect.TypeOf(v1alpha1.ConditionList{}): schemagen.Namespaced, + reflect.TypeOf(v1alpha1.PipelineList{}): schemagen.Namespaced, + reflect.TypeOf(v1alpha1.PipelineRunList{}): schemagen.Namespaced, + reflect.TypeOf(v1alpha1.TaskList{}): schemagen.Namespaced, + reflect.TypeOf(v1alpha1.TaskRunList{}): schemagen.Namespaced, + reflect.TypeOf(v1alpha1.ClusterTaskList{}): schemagen.Cluster, - reflect.TypeOf(resource.PipelineResourceList{}), + reflect.TypeOf(resource.PipelineResourceList{}): schemagen.Namespaced, } // constraints and patterns for fields diff --git a/extensions/tekton/generator-v1beta1/cmd/generate/generate.go b/extensions/tekton/generator-v1beta1/cmd/generate/generate.go index 3e9fb4cce97..e9014efe5cb 100644 --- a/extensions/tekton/generator-v1beta1/cmd/generate/generate.go +++ b/extensions/tekton/generator-v1beta1/cmd/generate/generate.go @@ -27,13 +27,13 @@ func main() { // the CRD List types for which the model should be generated // no other types need to be defined as they are auto discovered - crdLists := []reflect.Type{ + crdLists := map[reflect.Type]schemagen.CrdScope{ // v1beta1 - reflect.TypeOf(v1beta1.PipelineList{}), - reflect.TypeOf(v1beta1.PipelineRunList{}), - reflect.TypeOf(v1beta1.TaskList{}), - reflect.TypeOf(v1beta1.TaskRunList{}), - reflect.TypeOf(v1beta1.ClusterTaskList{}), + reflect.TypeOf(v1beta1.PipelineList{}): schemagen.Namespaced, + reflect.TypeOf(v1beta1.PipelineRunList{}): schemagen.Namespaced, + reflect.TypeOf(v1beta1.TaskList{}): schemagen.Namespaced, + reflect.TypeOf(v1beta1.TaskRunList{}): schemagen.Namespaced, + reflect.TypeOf(v1beta1.ClusterTaskList{}): schemagen.Cluster, } // constraints and patterns for fields diff --git a/extensions/tekton/model-v1alpha1/src/main/resources/schema/tekton-schema-v1alpha1.json b/extensions/tekton/model-v1alpha1/src/main/resources/schema/tekton-schema-v1alpha1.json index 726088d0487..093b3f08f39 100644 --- a/extensions/tekton/model-v1alpha1/src/main/resources/schema/tekton-schema-v1alpha1.json +++ b/extensions/tekton/model-v1alpha1/src/main/resources/schema/tekton-schema-v1alpha1.json @@ -199,7 +199,8 @@ }, "javaType": "io.fabric8.tekton.pipeline.v1alpha1.Condition", "javaInterfaces": [ - "io.fabric8.kubernetes.api.model.HasMetadata" + "io.fabric8.kubernetes.api.model.HasMetadata", + "io.fabric8.kubernetes.api.model.Namespaced" ] }, "github_com_tektoncd_pipeline_pkg_apis_pipeline_v1alpha1_ConditionCheckStatus": { @@ -390,7 +391,8 @@ }, "javaType": "io.fabric8.tekton.pipeline.v1alpha1.Pipeline", "javaInterfaces": [ - "io.fabric8.kubernetes.api.model.HasMetadata" + "io.fabric8.kubernetes.api.model.HasMetadata", + "io.fabric8.kubernetes.api.model.Namespaced" ] }, "github_com_tektoncd_pipeline_pkg_apis_pipeline_v1alpha1_PipelineList": { @@ -549,7 +551,8 @@ }, "javaType": "io.fabric8.tekton.pipeline.v1alpha1.PipelineRun", "javaInterfaces": [ - "io.fabric8.kubernetes.api.model.HasMetadata" + "io.fabric8.kubernetes.api.model.HasMetadata", + "io.fabric8.kubernetes.api.model.Namespaced" ] }, "github_com_tektoncd_pipeline_pkg_apis_pipeline_v1alpha1_PipelineRunConditionCheckStatus": { @@ -944,7 +947,8 @@ }, "javaType": "io.fabric8.tekton.pipeline.v1alpha1.Task", "javaInterfaces": [ - "io.fabric8.kubernetes.api.model.HasMetadata" + "io.fabric8.kubernetes.api.model.HasMetadata", + "io.fabric8.kubernetes.api.model.Namespaced" ] }, "github_com_tektoncd_pipeline_pkg_apis_pipeline_v1alpha1_TaskList": { @@ -1090,7 +1094,8 @@ }, "javaType": "io.fabric8.tekton.pipeline.v1alpha1.TaskRun", "javaInterfaces": [ - "io.fabric8.kubernetes.api.model.HasMetadata" + "io.fabric8.kubernetes.api.model.HasMetadata", + "io.fabric8.kubernetes.api.model.Namespaced" ] }, "github_com_tektoncd_pipeline_pkg_apis_pipeline_v1alpha1_TaskRunInputs": { @@ -1821,7 +1826,8 @@ }, "javaType": "io.fabric8.tekton.resource.v1alpha1.PipelineResource", "javaInterfaces": [ - "io.fabric8.kubernetes.api.model.HasMetadata" + "io.fabric8.kubernetes.api.model.HasMetadata", + "io.fabric8.kubernetes.api.model.Namespaced" ] }, "github_com_tektoncd_pipeline_pkg_apis_resource_v1alpha1_PipelineResourceList": { diff --git a/extensions/tekton/model-v1beta1/src/main/resources/schema/tekton-schema-v1beta1.json b/extensions/tekton/model-v1beta1/src/main/resources/schema/tekton-schema-v1beta1.json index 2678fd950f7..fcb55ff4af6 100644 --- a/extensions/tekton/model-v1beta1/src/main/resources/schema/tekton-schema-v1beta1.json +++ b/extensions/tekton/model-v1beta1/src/main/resources/schema/tekton-schema-v1beta1.json @@ -281,7 +281,8 @@ }, "javaType": "io.fabric8.tekton.pipeline.v1beta1.Pipeline", "javaInterfaces": [ - "io.fabric8.kubernetes.api.model.HasMetadata" + "io.fabric8.kubernetes.api.model.HasMetadata", + "io.fabric8.kubernetes.api.model.Namespaced" ] }, "github_com_tektoncd_pipeline_pkg_apis_pipeline_v1beta1_PipelineDeclaredResource": { @@ -454,7 +455,8 @@ }, "javaType": "io.fabric8.tekton.pipeline.v1beta1.PipelineRun", "javaInterfaces": [ - "io.fabric8.kubernetes.api.model.HasMetadata" + "io.fabric8.kubernetes.api.model.HasMetadata", + "io.fabric8.kubernetes.api.model.Namespaced" ] }, "github_com_tektoncd_pipeline_pkg_apis_pipeline_v1beta1_PipelineRunConditionCheckStatus": { @@ -1094,7 +1096,8 @@ }, "javaType": "io.fabric8.tekton.pipeline.v1beta1.Task", "javaInterfaces": [ - "io.fabric8.kubernetes.api.model.HasMetadata" + "io.fabric8.kubernetes.api.model.HasMetadata", + "io.fabric8.kubernetes.api.model.Namespaced" ] }, "github_com_tektoncd_pipeline_pkg_apis_pipeline_v1beta1_TaskList": { @@ -1290,7 +1293,8 @@ }, "javaType": "io.fabric8.tekton.pipeline.v1beta1.TaskRun", "javaInterfaces": [ - "io.fabric8.kubernetes.api.model.HasMetadata" + "io.fabric8.kubernetes.api.model.HasMetadata", + "io.fabric8.kubernetes.api.model.Namespaced" ] }, "github_com_tektoncd_pipeline_pkg_apis_pipeline_v1beta1_TaskRunList": { diff --git a/generator/pkg/schemagen/generate.go b/generator/pkg/schemagen/generate.go index cd1f86ec03f..c71c56c9e1b 100644 --- a/generator/pkg/schemagen/generate.go +++ b/generator/pkg/schemagen/generate.go @@ -35,7 +35,7 @@ type PackageInformation struct { } type schemaGenerator struct { - crdLists []reflect.Type + crdLists map[reflect.Type]CrdScope types map[reflect.Type]*JSONObjectDescriptor providedPackages map[string]string manualTypeMap map[reflect.Type]string @@ -50,7 +50,14 @@ type Constraint struct { Pattern string } -func GenerateSchema(crdLists []reflect.Type, providedPackages map[string]string, manualTypeMap map[reflect.Type]string, packageMapping map[string]PackageInformation, mappingSchema map[string]string, providedTypes []ProvidedType, constraints map[reflect.Type]map[string]*Constraint) string { +type CrdScope int32 + +const ( + Namespaced CrdScope = 0 + Cluster CrdScope = 1 +) + +func GenerateSchema(crdLists map[reflect.Type]CrdScope, providedPackages map[string]string, manualTypeMap map[reflect.Type]string, packageMapping map[string]PackageInformation, mappingSchema map[string]string, providedTypes []ProvidedType, constraints map[reflect.Type]map[string]*Constraint) string { g := newSchemaGenerator(crdLists, providedPackages, manualTypeMap, packageMapping, mappingSchema, providedTypes, constraints) schema, err := g.generate(crdLists) @@ -72,7 +79,7 @@ func GenerateSchema(crdLists []reflect.Type, providedPackages map[string]string, return out.String() } -func newSchemaGenerator(crdLists []reflect.Type, providedPackages map[string]string, manualTypeMap map[reflect.Type]string, packageMapping map[string]PackageInformation, mappingSchema map[string]string, providedTypes []ProvidedType, constraints map[reflect.Type]map[string]*Constraint) *schemaGenerator { +func newSchemaGenerator(crdLists map[reflect.Type]CrdScope, providedPackages map[string]string, manualTypeMap map[reflect.Type]string, packageMapping map[string]PackageInformation, mappingSchema map[string]string, providedTypes []ProvidedType, constraints map[reflect.Type]map[string]*Constraint) *schemaGenerator { g := schemaGenerator{ crdLists: crdLists, types: make(map[reflect.Type]*JSONObjectDescriptor), @@ -212,6 +219,13 @@ func (g *schemaGenerator) javaType(t reflect.Type) string { func (g *schemaGenerator) javaInterfaces(t reflect.Type) []string { if g.isCRD(t) { + + scope := g.crdScope(t) + + if scope == Namespaced { + return []string{"io.fabric8.kubernetes.api.model.HasMetadata", "io.fabric8.kubernetes.api.model.Namespaced"} + } + return []string{"io.fabric8.kubernetes.api.model.HasMetadata"} } @@ -228,7 +242,7 @@ func (g *schemaGenerator) resourceListInterface(listType reflect.Type) string { return "io.fabric8.kubernetes.api.model.KubernetesResourceList<" + g.javaType(itemType) + ">" } -func (g *schemaGenerator) generate(crdLists []reflect.Type) (*JSONSchema, error) { +func (g *schemaGenerator) generate(crdLists map[reflect.Type]CrdScope) (*JSONSchema, error) { s := JSONSchema{ ID: "http://fabric8.io/tekton/v1alpha1/TektonSchema#", @@ -243,7 +257,7 @@ func (g *schemaGenerator) generate(crdLists []reflect.Type) (*JSONSchema, error) }, } - for _, crd := range crdLists { + for crd, _ := range crdLists { g.handleType(crd) } @@ -650,7 +664,7 @@ func (g *schemaGenerator) isCRD(t reflect.Type) bool { typeName := t.PkgPath() + "." + t.Name() + "List" - for _, crd := range g.crdLists { + for crd, _ := range g.crdLists { // provided are CRDList as an entry point crdListName := crd.PkgPath() + "." + crd.Name() @@ -663,11 +677,29 @@ func (g *schemaGenerator) isCRD(t reflect.Type) bool { return false } +func (g *schemaGenerator) crdScope(t reflect.Type) CrdScope { + + typeName := t.PkgPath() + "." + t.Name() + "List" + + for crd, scope := range g.crdLists { + // provided are CRDList as an entry point + crdListName := crd.PkgPath() + "." + crd.Name() + + if typeName == crdListName { + return scope + } + + } + + panic("No CRD scope information for " + t.Name()) + +} + func (g *schemaGenerator) isCRDList(t reflect.Type) bool { typeName := t.PkgPath() + "." + t.Name() - for _, crd := range g.crdLists { + for crd, _ := range g.crdLists { // provided are CRDList as an entry point crdListName := crd.PkgPath() + "." + crd.Name() diff --git a/kubernetes-model/kubernetes-model-core/src/main/java/io/fabric8/kubernetes/api/model/Namespaced.java b/kubernetes-model/kubernetes-model-core/src/main/java/io/fabric8/kubernetes/api/model/Namespaced.java new file mode 100644 index 00000000000..ee3a565bfe3 --- /dev/null +++ b/kubernetes-model/kubernetes-model-core/src/main/java/io/fabric8/kubernetes/api/model/Namespaced.java @@ -0,0 +1,19 @@ +/** + * 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 io.fabric8.kubernetes.api.model; + +public interface Namespaced { +}