Skip to content

Commit

Permalink
Fix fabric8io#2321: Add new objects to OpenShift model
Browse files Browse the repository at this point in the history
  • Loading branch information
rohanKanojia committed Aug 18, 2020
1 parent e8c47dc commit 341be94
Show file tree
Hide file tree
Showing 81 changed files with 177,488 additions and 6,377 deletions.
12 changes: 7 additions & 5 deletions kubernetes-model-generator/go.mod
Expand Up @@ -3,11 +3,13 @@ module github.com/fabric8io/kubernetes-client/kubernetes-model-generator
go 1.14

require (
github.com/openshift/api v0.0.0-20200413201024-c6e8c9b6eb9a
k8s.io/api v0.18.0
k8s.io/apiextensions-apiserver v0.18.0
k8s.io/apimachinery v0.18.0
k8s.io/client-go v0.18.0
github.com/coreos/prometheus-operator v0.41.1 // indirect
github.com/openshift/api v0.0.0-20200803131051-87466835fcc0
github.com/operator-framework/api v0.3.12
k8s.io/api v0.19.0-rc.2
k8s.io/apiextensions-apiserver v0.18.2
k8s.io/apimachinery v0.19.0-rc.2
k8s.io/client-go v0.18.3
k8s.io/kubernetes v1.18.0
k8s.io/metrics v0.18.0
)
Expand Down
822 changes: 820 additions & 2 deletions kubernetes-model-generator/go.sum

Large diffs are not rendered by default.

Expand Up @@ -157,6 +157,13 @@ static class Mapping {
"io.fabric8.kubernetes.api.model.scheduling.",
"io.fabric8.kubernetes.api.model.settings.",
"io.fabric8.openshift.api.model.",
"io.fabric8.openshift.api.model.monitoring.v1.",
"io.fabric8.openshift.api.model.operator.v1.",
"io.fabric8.openshift.api.model.operator.v1alpha1.",
"io.fabric8.openshift.api.model.imageregistry.v1.",
"io.fabric8.openshift.api.model.operatorhub.v1.",
"io.fabric8.openshift.api.model.operatorhub.v1alpha1.",
"io.fabric8.openshift.api.model.operatorhub.manifests.",
"io.fabric8.kubernetes.api.model.extensions."
};

Expand Down
27 changes: 27 additions & 0 deletions kubernetes-model-generator/openshift-console-model/Makefile
@@ -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 clean install

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
@@ -0,0 +1,100 @@
/**
* 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"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
apimachineryversion "k8s.io/apimachinery/pkg/version"
"log"
"reflect"
"strings"
"time"
consoleapi "github.com/openshift/api/console/v1"

"os"

"github.com/fabric8io/kubernetes-client/kubernetes-model-generator/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
Time metav1.Time
ConsoleCLIDownload consoleapi.ConsoleCLIDownload
ConsoleCLIDownloadList consoleapi.ConsoleCLIDownloadList
ConsoleExternalLogLink consoleapi.ConsoleExternalLogLink
ConsoleExternalLogLinkList consoleapi.ConsoleExternalLogLinkList
ConsoleLink consoleapi.ConsoleLink
ConsoleLinkList consoleapi.ConsoleLinkList
ConsoleNotification consoleapi.ConsoleNotification
ConsoleNotificationList consoleapi.ConsoleNotificationList
ConsoleYAMLSample consoleapi.ConsoleYAMLSample
ConsoleYAMLSampleList consoleapi.ConsoleYAMLSampleList
}

func main() {
packages := []schemagen.PackageDescriptor{
{"k8s.io/api/core/v1", "", "io.fabric8.kubernetes.api.model", "kubernetes_core_"},
{"k8s.io/apimachinery/pkg/api/resource", "", "io.fabric8.kubernetes.api.model", "kubernetes_resource_"},
{"k8s.io/apimachinery/pkg/util/intstr", "", "io.fabric8.kubernetes.api.model", "kubernetes_apimachinery_pkg_util_intstr_"},
{"k8s.io/apimachinery/pkg/runtime", "", "io.fabric8.openshift.api.model.runtime", "kubernetes_apimachinery_pkg_runtime_"},
{"k8s.io/apimachinery/pkg/version", "", "io.fabric8.kubernetes.api.model.version", "kubernetes_apimachinery_pkg_version_"},
{"k8s.io/kubernetes/pkg/util", "", "io.fabric8.kubernetes.api.model", "kubernetes_util_"},
{"k8s.io/kubernetes/pkg/api/errors", "", "io.fabric8.kubernetes.api.model", "kubernetes_errors_"},
{"k8s.io/kubernetes/pkg/api/unversioned", "", "io.fabric8.kubernetes.api.model", "api_"},
{"k8s.io/apimachinery/pkg/apis/meta/v1", "", "io.fabric8.kubernetes.api.model", "kubernetes_apimachinery_"},
{"github.com/openshift/api/console/v1", "", "io.fabric8.openshift.api.model.console.v1", "os_console_v1_"},
}

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{},"console")
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())
}
120 changes: 120 additions & 0 deletions kubernetes-model-generator/openshift-console-model/pom.xml
@@ -0,0 +1,120 @@
<?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>4.10-SNAPSHOT</version>
</parent>

<artifactId>openshift-console-model</artifactId>
<packaging>bundle</packaging>
<name>Fabric8 :: OpenShift Console Model</name>

<properties>
<clone-kube>true</clone-kube>
</properties>

<dependencies>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-model-core</artifactId>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-model-common</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.jsonschema2pojo</groupId>
<artifactId>jsonschema2pojo-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>generate-sources</phase>
<configuration>
<target>
<echo>removing the duplicate generated class</echo>
<delete verbose="true">
<fileset dir="${project.build.directory}/generated-sources">
<include name="*.java" />
</fileset>
</delete>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>${maven.bundle.plugin.version}</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
<Import-Package>*</Import-Package>
<Export-Package>
io.fabric8.openshift.api.model.console**,
</Export-Package>
<Include-Resource>
{maven-resources},
/META-INF/jandex.idx=target/classes/META-INF/jandex.idx,
/console.properties=target/classes/console.properties
</Include-Resource>
</instructions>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>${maven.buildhelper.plugin.version}</version>
<executions>
<execution>
<id>attach-artifacts</id>
<phase>package</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>${project.build.outputDirectory}/schema/kube-schema.json</file>
<type>json</type>
<classifier>schema</classifier>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
@@ -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.
#

io.fabric8.kubernetes.api.model.NotNull.message = is required
io.fabric8.kubernetes.api.model.Pattern.message = must match "{regexp}"
io.fabric8.kubernetes.api.model.MaxLength.message = must be less than {max} characters
@@ -0,0 +1,18 @@
#*
* 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.
*#
#foreach ($key in ${model.keySet()})
$key
#end

0 comments on commit 341be94

Please sign in to comment.