Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat (kubernetes-model-generator) : Add Model for Kubernetes Open Virtual Networking k8s.ovn.org/v1 used in OpenShift 4.12+ #5722

Merged
merged 1 commit into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#### Dependency Upgrade

#### New Features
* Fix #5636: Add model for Kubernetes Open Virtual Networking `k8s.ovn.org/v1`

#### _**Note**_: Breaking changes

Expand Down
2 changes: 2 additions & 0 deletions kubernetes-model-generator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
[![javadoc](https://javadoc.io/badge2/io.fabric8/kubernetes-model-storageclass/javadoc.svg)](https://javadoc.io/doc/io.fabric8/kubernetes-model-storageclass)
* kubernetes-model-node: [![Maven Central](https://img.shields.io/maven-central/v/io.fabric8/kubernetes-model-node.svg?maxAge=2592000)](http://search.maven.org/#search%7Cga%7C1%7Cg%3Aio.fabric8%20a%3Akubernetes-model-node)
[![javadoc](https://javadoc.io/badge2/io.fabric8/kubernetes-model-node/javadoc.svg)](https://javadoc.io/doc/io.fabric8/kubernetes-model-node)
* kubernetes-model-ovn: [![Maven Central](https://img.shields.io/maven-central/v/io.fabric8/kubernetes-model-ovn.svg?maxAge=2592000)](http://search.maven.org/#search%7Cga%7C1%7Cg%3Aio.fabric8%20a%3Akubernetes-model-ovn)
[![javadoc](https://javadoc.io/badge2/io.fabric8/kubernetes-model-ovn/javadoc.svg)](https://javadoc.io/doc/io.fabric8/kubernetes-model-ovn)
* openshift-model: [![Maven Central](https://img.shields.io/maven-central/v/io.fabric8/openshift-model.svg?maxAge=2592000)](http://search.maven.org/#search%7Cga%7C1%7Cg%3Aio.fabric8%20a%3Aopenshift-model)
[![javadoc](https://javadoc.io/badge2/io.fabric8/openshift-model/javadoc.svg)](https://javadoc.io/doc/io.fabric8/openshift-model)
* openshift-model-console: [![Maven Central](https://img.shields.io/maven-central/v/io.fabric8/openshift-model-console.svg?maxAge=2592000)](http://search.maven.org/#search%7Cga%7C1%7Cg%3Aio.fabric8%20a%3Aopenshift-model-console)
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 @@ -39,6 +39,7 @@ declare -a modules=(
"kubernetes-model-networking"
"kubernetes-model-metrics"
"kubernetes-model-node"
"kubernetes-model-ovn"
"kubernetes-model-policy"
"kubernetes-model-scheduling"
"kubernetes-model-storageclass"
Expand Down
3 changes: 2 additions & 1 deletion kubernetes-model-generator/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/fabric8io/kubernetes-client/kubernetes-model-generator
go 1.21

require (
github.com/k8snetworkplumbingwg/network-attachment-definition-client v1.2.0
github.com/k8snetworkplumbingwg/network-attachment-definition-client v1.4.0
github.com/k8snetworkplumbingwg/whereabouts v0.4.3-0.20211129155010-abd29e856f36
github.com/metal3-io/baremetal-operator/apis v0.2.0
github.com/metal3-io/cluster-api-provider-metal3/api v0.0.0-00010101000000-000000000000
Expand All @@ -17,6 +17,7 @@ require (
github.com/openshift/machine-config-operator v0.0.1-0.20230807154212-886c5c3fc7a9
github.com/operator-framework/api v0.17.7
github.com/operator-framework/operator-lifecycle-manager v0.22.0
github.com/ovn-org/ovn-kubernetes/go-controller v0.0.0-20240119130830-e7acee6595c6
github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.68.0
k8s.io/api v0.29.0
k8s.io/apiextensions-apiserver v0.29.0
Expand Down
10 changes: 6 additions & 4 deletions kubernetes-model-generator/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -714,8 +714,8 @@ github.com/cncf/xds/go v0.0.0-20230105202645-06c439db220b/go.mod h1:eXthEFrGJvWH
github.com/cncf/xds/go v0.0.0-20230310173818-32f1caf87195/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8=
github.com/cockroachdb/datadriven v1.0.2/go.mod h1:a9RdTaap04u637JoCzcUoIcDmvwSUtcUFtT/C3kJlTU=
github.com/containerd/cgroups v1.0.4 h1:jN/mbWBEaz+T1pi5OFtnkQ+8qnmEbAr1Oo1FRm5B0dA=
github.com/containerd/cgroups v1.0.4/go.mod h1:nLNQtsF7Sl2HxNebu77i1R0oDlhiTG+kO4JTrUzo6IA=
github.com/containerd/cgroups v1.1.0 h1:v8rEWFl6EoqHB+swVNjVoCJE8o3jX7e8nqBGPLaDFBM=
github.com/containerd/cgroups v1.1.0/go.mod h1:6ppBcbh/NOOUU+dMKrykgaBnK9lCIBxHqJDGwsa1mIw=
github.com/containerd/containerd v1.5.13 h1:XqvKw9i4P7/mFrC3TSM7yV5cwFZ9avXe6M3YANKnzEE=
github.com/containerd/containerd v1.5.13/go.mod h1:3AlCrzKROjIuP3JALsY14n8YtntaUDBu7vek+rPN5Vc=
github.com/containerd/continuity v0.3.0 h1:nisirsYROK15TAMVukJOUyGJjz4BNQJBVsNvAXZJ/eg=
Expand Down Expand Up @@ -1172,8 +1172,8 @@ github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8
github.com/jung-kurt/gofpdf v1.0.0/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+r32jIOes=
github.com/jung-kurt/gofpdf v1.0.3-0.20190309125859-24315acbbda5/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+r32jIOes=
github.com/k8snetworkplumbingwg/network-attachment-definition-client v0.0.0-20191119172530-79f836b90111/go.mod h1:MP2HbArq3QT+oVp8pmtHNZnSnkhdkHtDnc7h6nJXmBU=
github.com/k8snetworkplumbingwg/network-attachment-definition-client v1.2.0 h1:0kE7xeGPeCL+wIkQ+Q8w6YtyGVQzxL1YFMZ5Z6wvHVU=
github.com/k8snetworkplumbingwg/network-attachment-definition-client v1.2.0/go.mod h1:gnArGo7sgDTOvqcLpyLvmCWdbHz8BbM50yBIs0oVRKE=
github.com/k8snetworkplumbingwg/network-attachment-definition-client v1.4.0 h1:VzM3TYHDgqPkettiP6I6q2jOeQFL4nrJM+UcAc4f6Fs=
github.com/k8snetworkplumbingwg/network-attachment-definition-client v1.4.0/go.mod h1:nqCI7aelBJU61wiBeeZWJ6oi4bJy5nrjkM6lWIMA4j0=
github.com/k8snetworkplumbingwg/whereabouts v0.4.3-0.20211129155010-abd29e856f36 h1:gKllVBUoMG7MKBA/q4iTS1ryasJHTSsIkECo9l+971M=
github.com/k8snetworkplumbingwg/whereabouts v0.4.3-0.20211129155010-abd29e856f36/go.mod h1:lmp8CU5xmHfP0M9Ebf3ArKweAD2k3vcP4g+2O6myWuI=
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 h1:iQTw/8FWTuc7uiaSepXwyf3o52HaUYcV+Tu66S3F5GA=
Expand Down Expand Up @@ -1370,6 +1370,8 @@ github.com/operator-framework/operator-registry v1.29.0 h1:HMmVTiuOAGoHLzYqR9Lr2
github.com/operator-framework/operator-registry v1.29.0/go.mod h1:4rVQu/cOuCtVt3JzKsAmwyq2lsiu9uPaH9nYNfnqj9o=
github.com/otiai10/copy v1.2.0 h1:HvG945u96iNadPoG2/Ja2+AUJeW5YuFQMixq9yirC+k=
github.com/otiai10/copy v1.2.0/go.mod h1:rrF5dJ5F0t/EWSYODDu4j9/vEeYHMkc8jt0zJChqQWw=
github.com/ovn-org/ovn-kubernetes/go-controller v0.0.0-20240119130830-e7acee6595c6 h1:7938zkANpNhvTSRG/XQwQ7FKESZI4X65G9Ldh+OuJs0=
github.com/ovn-org/ovn-kubernetes/go-controller v0.0.0-20240119130830-e7acee6595c6/go.mod h1:ZE3wbxkzS8KT5QQG4JrpmqB35I99KN2CBEHPRw+7MFk=
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class Pluralize implements UnaryOperator<String> {
EXCEPTIONS.put("podmetrics", "pods");
EXCEPTIONS.put("nodemetrics", "nodes");
EXCEPTIONS.put("networkattachmentdefinition", "network-attachment-definitions");
EXCEPTIONS.put("egressqos", "egressqoses");
}

private static final List<UnaryOperator<String>> PLURALS = Arrays.asList(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ static Stream<Arguments> toPluralInput() {
arguments("nodes", "nodemetrics"),
arguments("women", "woman"),
arguments("men", "man"),
arguments("dnses", "dns"));
arguments("dnses", "dns"),
arguments("egressqoses", "egressqos"));
}

}
27 changes: 27 additions & 0 deletions kubernetes-model-generator/kubernetes-model-ovn/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,94 @@
/**
* 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"

v1adminpolicybasedroute "github.com/ovn-org/ovn-kubernetes/go-controller/pkg/crd/adminpolicybasedroute/v1"
v1egressfirewall "github.com/ovn-org/ovn-kubernetes/go-controller/pkg/crd/egressfirewall/v1"
v1egressip "github.com/ovn-org/ovn-kubernetes/go-controller/pkg/crd/egressip/v1"
v1egressqos "github.com/ovn-org/ovn-kubernetes/go-controller/pkg/crd/egressqos/v1"
v1egressservice "github.com/ovn-org/ovn-kubernetes/go-controller/pkg/crd/egressservice/v1"

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

"os"

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

type Schema struct {
V1AdminPolicyBasedExternalRoute v1adminpolicybasedroute.AdminPolicyBasedExternalRoute
V1AdminPolicyBasedExternalRouteList v1adminpolicybasedroute.AdminPolicyBasedExternalRouteList
V1EgressFirewall v1egressfirewall.EgressFirewall
V1EgressFirewallList v1egressfirewall.EgressFirewallList
V1EgressIP v1egressip.EgressIP
V1EgressIPList v1egressip.EgressIPList
V1EgressQoS v1egressqos.EgressQoS
V1EgressQoSList v1egressqos.EgressQoSList
V1EgressService v1egressservice.EgressService
V1EgressServiceList v1egressservice.EgressServiceList
}

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},
{"github.com/ovn-org/ovn-kubernetes/go-controller/pkg/crd/adminpolicybasedroute/v1", "k8s.ovn.org", "io.fabric8.kubernetes.api.model.ovn.v1", "kubernetes_ovn_v1_", true},
{"github.com/ovn-org/ovn-kubernetes/go-controller/pkg/crd/egressfirewall/v1", "k8s.ovn.org", "io.fabric8.kubernetes.api.model.ovn.v1", "kubernetes_ovn_v1_", true},
{"github.com/ovn-org/ovn-kubernetes/go-controller/pkg/crd/egressip/v1", "k8s.ovn.org", "io.fabric8.kubernetes.api.model.ovn.v1", "kubernetes_ovn_v1_", true},
{"github.com/ovn-org/ovn-kubernetes/go-controller/pkg/crd/egressqos/v1", "k8s.ovn.org", "io.fabric8.kubernetes.api.model.ovn.v1", "kubernetes_ovn_v1_", true},
{"github.com/ovn-org/ovn-kubernetes/go-controller/pkg/crd/egressservice/v1", "k8s.ovn.org", "io.fabric8.kubernetes.api.model.ovn.v1", "kubernetes_ovn_v1_", 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{},"ovn")
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())
}
87 changes: 87 additions & 0 deletions kubernetes-model-generator/kubernetes-model-ovn/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?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.11-SNAPSHOT</version>
</parent>

<artifactId>kubernetes-model-ovn</artifactId>
<packaging>bundle</packaging>
<name>Fabric8 :: Kubernetes Model :: Open Virtual Networking</name>

<properties>
<clone-kube>true</clone-kube>
<osgi.import>*</osgi.import>
<osgi.export>
io.fabric8.kubernetes.api.model.ovn**
</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
Loading