Skip to content

Commit

Permalink
feat (kubernetes-model-generator) : Add Kubernetes Model Gateway API …
Browse files Browse the repository at this point in the history
…module

Add java model for Kubernetes Model Sigs Gateway API : https://github.com/kubernetes-sigs/gateway-api
This seems to be required by Cert Manager Extension

Signed-off-by: Rohan Kumar <[email protected]>
  • Loading branch information
rohanKanojia committed Aug 30, 2022
1 parent 22f0dcb commit 02f7244
Show file tree
Hide file tree
Showing 120 changed files with 24,544 additions and 13 deletions.
2 changes: 2 additions & 0 deletions kubernetes-model-generator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
[![javadoc](https://javadoc.io/badge2/io.fabric8/kubernetes-model-events/javadoc.svg)](https://javadoc.io/doc/io.fabric8/kubernetes-model-events)
* kubernetes-model-extensions: [![Maven Central](https://img.shields.io/maven-central/v/io.fabric8/kubernetes-model-extensions.svg?maxAge=2592000)](http://search.maven.org/#search%7Cga%7C1%7Cg%3Aio.fabric8%20a%3Akubernetes-model-extensions)
[![javadoc](https://javadoc.io/badge2/io.fabric8/kubernetes-model-extensions/javadoc.svg)](https://javadoc.io/doc/io.fabric8/kubernetes-model-extensions)
* kubernetes-model-gatewayapi: [![Maven Central](https://img.shields.io/maven-central/v/io.fabric8/kubernetes-model-gatewayapi.svg?maxAge=2592000)](http://search.maven.org/#search%7Cga%7C1%7Cg%3Aio.fabric8%20a%3Akubernetes-model-gatewayapi)
[![javadoc](https://javadoc.io/badge2/io.fabric8/kubernetes-model-gatewayapi/javadoc.svg)](https://javadoc.io/doc/io.fabric8/kubernetes-model-gatewayapi)
* kubernetes-model-metrics: [![Maven Central](https://img.shields.io/maven-central/v/io.fabric8/kubernetes-model-metrics.svg?maxAge=2592000)](http://search.maven.org/#search%7Cga%7C1%7Cg%3Aio.fabric8%20a%3Akubernetes-model-metrics)
[![javadoc](https://javadoc.io/badge2/io.fabric8/kubernetes-model-metrics/javadoc.svg)](https://javadoc.io/doc/io.fabric8/kubernetes-model-metrics)
* kubernetes-model-networking: [![Maven Central](https://img.shields.io/maven-central/v/io.fabric8/kubernetes-model-networking.svg?maxAge=2592000)](http://search.maven.org/#search%7Cga%7C1%7Cg%3Aio.fabric8%20a%3Akubernetes-model-networking)
Expand Down
1 change: 1 addition & 0 deletions kubernetes-model-generator/generateModel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ declare -a modules=(
"kubernetes-model-events"
"kubernetes-model-extensions"
"kubernetes-model-flowcontrol"
"kubernetes-model-gatewayapi"
"kubernetes-model-networking"
"kubernetes-model-metrics"
"kubernetes-model-node"
Expand Down
15 changes: 8 additions & 7 deletions kubernetes-model-generator/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/fabric8io/kubernetes-client/kubernetes-model-generator
go 1.17

require (
github.com/docker/docker v20.10.2+incompatible // indirect
github.com/k8snetworkplumbingwg/network-attachment-definition-client v1.2.0
github.com/k8snetworkplumbingwg/whereabouts v0.4.3-0.20211129155010-abd29e856f36
github.com/metal3-io/baremetal-operator/apis v0.0.0
Expand All @@ -18,12 +19,13 @@ require (
github.com/operator-framework/api v0.10.7
github.com/operator-framework/operator-lifecycle-manager v0.19.1
github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.52.1
k8s.io/api v0.24.0
k8s.io/apiextensions-apiserver v0.24.0
k8s.io/apimachinery v0.24.0
k8s.io/api v0.24.1
k8s.io/apiextensions-apiserver v0.24.1
k8s.io/apimachinery v0.24.1
k8s.io/client-go v12.0.0+incompatible
k8s.io/kube-aggregator v0.24.0
k8s.io/metrics v0.24.0
sigs.k8s.io/gateway-api v0.5.0
sigs.k8s.io/kube-storage-version-migrator v0.0.5
)

Expand All @@ -35,8 +37,7 @@ require (
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/docker/docker v20.10.2+incompatible // indirect
github.com/emicklei/go-restful v2.10.0+incompatible // indirect
github.com/emicklei/go-restful v2.14.2+incompatible // indirect
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
github.com/fsnotify/fsnotify v1.5.1 // indirect
github.com/go-logr/logr v1.2.0 // indirect
Expand Down Expand Up @@ -84,11 +85,11 @@ require (
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
k8s.io/component-base v0.24.0 // indirect
k8s.io/component-base v0.24.1 // indirect
k8s.io/klog/v2 v2.60.1 // indirect
k8s.io/kube-openapi v0.0.0-20220328201542-3ee0da9b0b42 // indirect
k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9 // indirect
sigs.k8s.io/controller-runtime v0.10.0 // indirect
sigs.k8s.io/controller-runtime v0.12.1 // indirect
sigs.k8s.io/json v0.0.0-20211208200746-9f7c6b3444d2 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
Expand Down
1,368 changes: 1,362 additions & 6 deletions kubernetes-model-generator/go.sum

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions kubernetes-model-generator/kubernetes-model-gatewayapi/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#
# 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 -Pgenerate clean install -DskipTests

gobuild:
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/**
* 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"
v1alpha2gwapi "sigs.k8s.io/gateway-api/apis/v1alpha2"
v1beta1gwapi "sigs.k8s.io/gateway-api/apis/v1beta1"

"log"
"reflect"
"strings"
"time"

"os"

"github.com/fabric8io/kubernetes-client/kubernetes-model-generator/pkg/schemagen"
)

type Schema struct {
Gateway v1alpha2gwapi.Gateway
GatewayList v1alpha2gwapi.GatewayList
GatewayClass v1alpha2gwapi.GatewayClass
GatewayClassList v1alpha2gwapi.GatewayClassList
HTTPRoute v1alpha2gwapi.HTTPRoute
HTTPRouteList v1alpha2gwapi.HTTPRouteList
ReferenceGrant v1alpha2gwapi.ReferenceGrant
ReferenceGrantList v1alpha2gwapi.ReferenceGrantList
ReferencePolicy v1alpha2gwapi.ReferencePolicy
ReferencePolicyList v1alpha2gwapi.ReferencePolicyList
TCPRoute v1alpha2gwapi.TCPRoute
TCPRouteList v1alpha2gwapi.TCPRouteList
TLSRoute v1alpha2gwapi.TLSRoute
TLSRouteList v1alpha2gwapi.TLSRouteList
UDPRoute v1alpha2gwapi.UDPRoute
UDPRouteList v1alpha2gwapi.UDPRouteList
V1Beta1Gateway v1beta1gwapi.Gateway
V1Beta1GatewayList v1beta1gwapi.GatewayList
V1Beta1GatewayClass v1beta1gwapi.GatewayClass
V1Beta1GatewayClassList v1beta1gwapi.GatewayClassList
V1Beta1HTTPRoute v1beta1gwapi.HTTPRoute
V1Beta1HTTPRouteList v1beta1gwapi.HTTPRouteList
}

func main() {
packages := []schemagen.PackageDescriptor{
{"k8s.io/apimachinery/pkg/api/resource", "", "io.fabric8.kubernetes.api.model", "kubernetes_resource_", false},
{"k8s.io/apimachinery/pkg/version", "", "io.fabric8.kubernetes.api.model.version", "kubernetes_apimachinery_pkg_version_", false},
{"k8s.io/apimachinery/pkg/apis/meta/v1", "", "io.fabric8.kubernetes.api.model", "kubernetes_apimachinery_", false},
{"k8s.io/api/core/v1", "", "io.fabric8.kubernetes.api.model", "kubernetes_core_", false},
{"sigs.k8s.io/gateway-api/apis/v1alpha2", "gateway.networking.k8s.io", "io.fabric8.kubernetes.api.model.gatewayapi.v1alpha2", "kubernetes_sigs_gatewayapi_v1alpha2_", true},
{"sigs.k8s.io/gateway-api/apis/v1beta1", "gateway.networking.k8s.io", "io.fabric8.kubernetes.api.model.gatewayapi.v1beta1", "kubernetes_sigs_gatewayapi_v1beta1_", true},
}

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, map[reflect.Type]string{}, "gatewayapi")
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)

var out bytes.Buffer
err = json.Indent(&out, []byte(result), "", " ")
if err != nil {
log.Fatal(err)
}

fmt.Println(out.String())
}
91 changes: 91 additions & 0 deletions kubernetes-model-generator/kubernetes-model-gatewayapi/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-model-generator</artifactId>
<version>6.1-SNAPSHOT</version>
</parent>

<artifactId>kubernetes-model-gatewayapi</artifactId>
<packaging>bundle</packaging>
<name>Fabric8 :: Kubernetes Model :: Sigs :: Gateway API</name>

<properties>
<clone-kube>true</clone-kube>
<osgi.include.resources>
${osgi.include.resources.default},
/gatewayapi.properties=target/classes/gatewayapi.properties,
</osgi.include.resources>
<osgi.import>*</osgi.import>
<osgi.export>
io.fabric8.kubernetes.api.model.gatewayapi**
</osgi.export>
</properties>

<dependencies>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-model-core</artifactId>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-model-common</artifactId>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>attach-artifacts</id>
<configuration>
<skipAttach>false</skipAttach>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>generate</id>
<build>
<plugins>
<plugin>
<groupId>org.jsonschema2pojo</groupId>
<artifactId>jsonschema2pojo-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Loading

0 comments on commit 02f7244

Please sign in to comment.