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

Add support for migration.k8s.io/v1alpha1 resources in OpenShiftClient #3224

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 @@ -34,6 +34,7 @@
* Add DSL support for ConsolePlugin and ConsoleQuickStart in `console.openshift.io` apiGroup
* Add DSL support for `user.openshift.io/v1` Identity in OpenShiftClient DSL
* Add DSL support for OpenShift Whereabouts CNI Model `whereabouts.cni.cncf.io` to OpenShiftClient DSL
* Add DSL support for OpenShift Kube Storage Version Migrator resources in OpenShiftClient DSL

#### _**Note**_: Breaking changes in the API
##### DSL 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 @@ -56,6 +56,8 @@
[![javadoc](https://javadoc.io/badge2/io.fabric8/openshift-model-tuned/javadoc.svg)](https://javadoc.io/doc/io.fabric8/openshift-model-tuned)
* openshift-model-whereabouts: [![Maven Central](https://img.shields.io/maven-central/v/io.fabric8/openshift-model-whereabouts.svg?maxAge=2592000)](http://search.maven.org/#search%7Cga%7C1%7Cg%3Aio.fabric8%20a%3Aopenshift-model-whereabouts)
[![javadoc](https://javadoc.io/badge2/io.fabric8/openshift-model-whereabouts/javadoc.svg)](https://javadoc.io/doc/io.fabric8/openshift-model-whereabouts)
* openshift-model-storageversionmigrator: [![Maven Central](https://img.shields.io/maven-central/v/io.fabric8/openshift-model-storageversionmigrator.svg?maxAge=2592000)](http://search.maven.org/#search%7Cga%7C1%7Cg%3Aio.fabric8%20a%3Aopenshift-model-storageversionmigrator)
[![javadoc](https://javadoc.io/badge2/io.fabric8/openshift-model-storageversionmigrator/javadoc.svg)](https://javadoc.io/doc/io.fabric8/openshift-model-storageversionmigrator)

Uses [Go reflection](https://blog.golang.org/laws-of-reflection) to generate a JSON schema that describes one or more
API resources in Kubernetes and OpenShift.
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 @@ -50,6 +50,7 @@ declare -a modules=(
"openshift-model-monitoring"
"openshift-model-tuned"
"openshift-model-whereabouts"
"openshift-model-storageversionmigrator"
)
generateAll() {
for module in ${modules[*]}
Expand Down
1 change: 1 addition & 0 deletions kubernetes-model-generator/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1987,6 +1987,7 @@ sigs.k8s.io/controller-tools v0.3.0/go.mod h1:enhtKGfxZD1GFEoMgP8Fdbu+uKQ/cq1/WG
sigs.k8s.io/controller-tools v0.4.0/go.mod h1:G9rHdZMVlBDocIxGkK3jHLWqcTMNvveypYJwrvYKjWU=
sigs.k8s.io/controller-tools v0.4.1/go.mod h1:G9rHdZMVlBDocIxGkK3jHLWqcTMNvveypYJwrvYKjWU=
sigs.k8s.io/kind v0.10.0/go.mod h1:fb32zUw7ewC47bPwLnwhf47wd/vADtv3c38KP7sjIlo=
sigs.k8s.io/kube-storage-version-migrator v0.0.3 h1:IclhkKtl1zwS7awsqsQuxrvXrP2VamhcWeZDzsEz6/Q=
sigs.k8s.io/kube-storage-version-migrator v0.0.3/go.mod h1:mXfSLkx9xbJHQsgNDDUZK/iQTs2tMbx/hsJlWe6Fthw=
sigs.k8s.io/kustomize v2.0.3+incompatible/go.mod h1:MkjgH3RdOWrievjo6c9T245dYlB5QeXV4WCbnt/PEpU=
sigs.k8s.io/kustomize/api v0.8.5/go.mod h1:M377apnKT5ZHJS++6H4rQoCHmWtt6qTpp3mbe7p6OLY=
Expand Down
1 change: 1 addition & 0 deletions kubernetes-model-generator/kubernetes-model-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
io.fabric8.openshift.api.model.machine.v1beta1;resolution:=optional,
io.fabric8.openshift.api.model.tuned.v1;resolution:=optional,
io.fabric8.openshift.api.model.whereabouts.v1alpha1;resolution:=optional,
io.fabric8.openshift.api.model.storageversionmigrator.v1alpha1;resolution:=optional,
</Import-Package>
<Private-Package>io.fabric8.kubernetes.internal</Private-Package>
<Export-Package>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ static class Mapping {
"io.fabric8.openshift.api.model.machineconfig.v1.",
"io.fabric8.openshift.api.model.tuned.v1.",
"io.fabric8.openshift.api.model.whereabouts.v1alpha1.",
"io.fabric8.openshift.api.model.storageversionmigrator.v1alpha1.",
"io.fabric8.kubernetes.api.model.extensions."
};

Expand Down
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"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
apimachineryversion "k8s.io/apimachinery/pkg/version"
runtime "k8s.io/apimachinery/pkg/runtime"
"log"
"reflect"
"strings"
"time"
kubestorageversionmigrator "sigs.k8s.io/kube-storage-version-migrator/pkg/apis/migration/v1alpha1"

"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
StorageState kubestorageversionmigrator.StorageState
StorageStateList kubestorageversionmigrator.StorageStateList
StorageVersionMigration kubestorageversionmigrator.StorageVersionMigration
StorageVersionMigrationList kubestorageversionmigrator.StorageVersionMigrationList
}

func main() {
packages := []schemagen.PackageDescriptor{
{"k8s.io/api/core/v1", "", "io.fabric8.kubernetes.api.model", "kubernetes_core_", false},
{"k8s.io/apimachinery/pkg/api/resource", "", "io.fabric8.kubernetes.api.model", "kubernetes_resource_", false},
{"k8s.io/apimachinery/pkg/util/intstr", "", "io.fabric8.kubernetes.api.model", "kubernetes_apimachinery_pkg_util_intstr_", false},
{"k8s.io/apimachinery/pkg/runtime", "", "io.fabric8.openshift.api.model.runtime", "kubernetes_apimachinery_pkg_runtime_", false},
{"k8s.io/apimachinery/pkg/version", "", "io.fabric8.kubernetes.api.model.version", "kubernetes_apimachinery_pkg_version_", false},
{"k8s.io/kubernetes/pkg/util", "", "io.fabric8.kubernetes.api.model", "kubernetes_util_", false},
{"k8s.io/kubernetes/pkg/api/errors", "", "io.fabric8.kubernetes.api.model", "kubernetes_errors_", false},
{"k8s.io/kubernetes/pkg/api/unversioned", "", "io.fabric8.kubernetes.api.model", "api_", false},
{"k8s.io/apimachinery/pkg/apis/meta/v1", "", "io.fabric8.kubernetes.api.model", "kubernetes_apimachinery_", false},
{"github.com/openshift/api/config/v1", "", "io.fabric8.openshift.api.model", "os_config_v1_", false},
{"sigs.k8s.io/kube-storage-version-migrator/pkg/apis/migration/v1alpha1", "migration.k8s.io", "io.fabric8.openshift.api.model.storageversionmigrator.v1alpha1", "os_storageversionmigrator_v1alpha1_", true},
}

typeMap := map[reflect.Type]reflect.Type{
reflect.TypeOf(time.Time{}): reflect.TypeOf(""),
reflect.TypeOf(struct{}{}): reflect.TypeOf(""),
}
manualTypeMap := map[reflect.Type]string {
reflect.TypeOf(runtime.RawExtension{}): "java.util.Map<String, Object>",
}
schema, err := schemagen.GenerateSchema(reflect.TypeOf(Schema{}), packages, typeMap, manualTypeMap,"storageversionmigrator")
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())
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?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>5.5-SNAPSHOT</version>
</parent>

<artifactId>openshift-model-storageversionmigrator</artifactId>
<packaging>bundle</packaging>
<name>Fabric8 :: OpenShift Kube Storage Version Migrator 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>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>openshift-model</artifactId>
</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>
<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.storageversionmigrator**,
</Export-Package>
<Include-Resource>
{maven-resources},
/META-INF/jandex.idx=target/classes/META-INF/jandex.idx,
/storageversionmigrator.properties=target/classes/storageversionmigrator.properties
</Include-Resource>
</instructions>
</configuration>
</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