Skip to content

Commit

Permalink
certmanager add all api versions
Browse files Browse the repository at this point in the history
  • Loading branch information
matthyx committed Mar 19, 2021
1 parent cf50243 commit 23f064e
Show file tree
Hide file tree
Showing 32 changed files with 9,197 additions and 6 deletions.
2 changes: 1 addition & 1 deletion extensions/certmanager/client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
<dependencies>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>certmanager-model</artifactId>
<artifactId>certmanager-model-v1</artifactId>
<version>${project.version}</version>
</dependency>

Expand Down
26 changes: 26 additions & 0 deletions extensions/certmanager/generateModel.sh
Original file line number Diff line number Diff line change
@@ -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-v1alpha2" "generator-v1alpha3" "generator-v1beta1" "generator-v1")
)

for module in ${modules[*]}
do
echo "Compiling ${module}"
cd $module
make
cd ..
done
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ SHELL := /bin/bash
all: build

build: gobuild
pushd ../model && \
pushd ../model-v1 && \
mvn clean install -o && \
popd

gobuild:
go mod vendor
CGO_ENABLED=0 GO111MODULE=on GO15VENDOREXPERIMENT=1 go run -mod=vendor -a ./cmd/generate/generate.go > ../model/src/main/resources/schema/certmanager-schema.json
CGO_ENABLED=0 GO111MODULE=on GO15VENDOREXPERIMENT=1 go run -mod=vendor -a ./cmd/generate/generate.go > ../model-v1/src/main/resources/schema/certmanager-schema.json
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions extensions/certmanager/generator-v1alpha2/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/vendor/
28 changes: 28 additions & 0 deletions extensions/certmanager/generator-v1alpha2/Makefile
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
pushd ../model-v1alpha2 && \
mvn clean install -o && \
popd

gobuild:
go mod vendor
CGO_ENABLED=0 GO111MODULE=on GO15VENDOREXPERIMENT=1 go run -mod=vendor -a ./cmd/generate/generate.go > ../model-v1alpha2/src/main/resources/schema/certmanager-schema.json
79 changes: 79 additions & 0 deletions extensions/certmanager/generator-v1alpha2/cmd/generate/generate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/**
* 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 (
"fmt"
"github.com/fabric8io/kubernetes-client/generator/pkg/schemagen"
certmanageracme "github.com/jetstack/cert-manager/pkg/apis/acme/v1alpha2"
certmanager "github.com/jetstack/cert-manager/pkg/apis/certmanager/v1alpha2"
apiextensions "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"reflect"
)

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 := map[reflect.Type]schemagen.CrdScope{
reflect.TypeOf(certmanager.CertificateList{}): schemagen.Namespaced,
reflect.TypeOf(certmanager.CertificateRequestList{}): schemagen.Namespaced,
reflect.TypeOf(certmanager.IssuerList{}): schemagen.Namespaced,
reflect.TypeOf(certmanager.ClusterIssuerList{}): schemagen.Cluster,
reflect.TypeOf(certmanageracme.ChallengeList{}): schemagen.Namespaced,
reflect.TypeOf(certmanageracme.OrderList{}): schemagen.Namespaced,
}

// constraints and patterns for fields
constraints := map[reflect.Type]map[string]*schemagen.Constraint{}

// types that are manually defined in the model
providedTypes := []schemagen.ProvidedType{}

// go packages that are provided and where no generation is required and their corresponding java package
providedPackages := map[string]string{
// external
"k8s.io/api/core/v1": "io.fabric8.kubernetes.api.model",
"k8s.io/apimachinery/pkg/apis/meta/v1": "io.fabric8.kubernetes.api.model",
"k8s.io/apimachinery/pkg/api/resource": "io.fabric8.kubernetes.api.model",
"k8s.io/apimachinery/pkg/runtime": "io.fabric8.kubernetes.api.model.runtime",
}

// mapping of go packages of this module to the resulting java package
// optional ApiGroup and ApiVersion for the go package (which is added to the generated java class)
packageMapping := map[string]schemagen.PackageInformation{
"github.com/jetstack/cert-manager/pkg/apis/certmanager/v1alpha2": {JavaPackage: "io.fabric8.certmanager.api.model.v1alpha2", ApiGroup: "cert-manager.io", ApiVersion: "v1alpha2"},
"github.com/jetstack/cert-manager/pkg/apis/acme/v1alpha2": {JavaPackage: "io.fabric8.certmanager.api.model.acme.v1alpha2", ApiGroup: "cert-manager.io", ApiVersion: "v1alpha2"},
"github.com/jetstack/cert-manager/pkg/apis/meta/v1": {JavaPackage: "io.fabric8.certmanager.api.model.meta.v1", ApiGroup: "cert-manager.io", ApiVersion: "v1"},
}

// converts all packages starting with <key> to a java package using an automated scheme:
// - replace <key> with <value> aka "package prefix"
// - replace '/' with '.' for a valid java package name
// e.g. knative.dev/eventing/pkg/apis/messaging/v1beta1/ChannelTemplateSpec is mapped to "io.fabric8.knative.internal.eventing.pkg.apis.messaging.v1beta1.ChannelTemplateSpec"
mappingSchema := map[string]string{}

// overwriting some times
manualTypeMap := map[reflect.Type]string{
reflect.TypeOf(v1.Time{}): "java.lang.String",
reflect.TypeOf(apiextensions.JSON{}): "com.fasterxml.jackson.databind.JsonNode",
}

json := schemagen.GenerateSchema("http://fabric8.io/jetstack/CertManagerSchema#", crdLists, providedPackages, manualTypeMap, packageMapping, mappingSchema, providedTypes, constraints)

fmt.Println(json)
}
12 changes: 12 additions & 0 deletions extensions/certmanager/generator-v1alpha2/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module github.com/fabric8io/kubernetes-client/extensions/jetstack/generator

require (
github.com/fabric8io/kubernetes-client/generator v0.0.0
github.com/jetstack/cert-manager v1.1.1
k8s.io/apiextensions-apiserver v0.19.0
k8s.io/apimachinery v0.19.0
)

replace github.com/fabric8io/kubernetes-client/generator v0.0.0 => ./../../../generator

go 1.15
Loading

0 comments on commit 23f064e

Please sign in to comment.