Skip to content

Commit

Permalink
Add Support for OpenShift MachineConfig Operator Model in DSL
Browse files Browse the repository at this point in the history
Add Model+DSL Support for OpenShift MachineConfig Operator Model
resources in OpenShiftClient DSL. Introduced a DSL entrypoint called
`openshiftClient.machineConfigurations()` which would provide all
available resources

Related to #2949
  • Loading branch information
rohanKanojia authored and manusa committed May 26, 2021
1 parent d1ab437 commit 646384f
Show file tree
Hide file tree
Showing 57 changed files with 11,566 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#### New Features
* Fix #3133: Add DSL Support for `authorization.openshift.io/v1` resources in OpenShiftClient
* Fix #3166: Add DSL Support for `machineconfiguration.openshift.io/v1` resources in OpenShiftClient
* Fix #3142: Add DSL support for missing resources in `operator.openshift.io` and `monitoring.coreos.com` apiGroups
* Add DSL support for missing resources in `template.openshift.io`, `helm.openshift.io`, `network.openshift.io`, `user.openshift.io` apigroups

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 @@ -46,6 +46,8 @@
[![javadoc](https://javadoc.io/badge2/io.fabric8/openshift-model-operator/javadoc.svg)](https://javadoc.io/doc/io.fabric8/openshift-model-operator)
* openshift-model-operatorhub: [![Maven Central](https://img.shields.io/maven-central/v/io.fabric8/openshift-model-operatorhub.svg?maxAge=2592000)](http://search.maven.org/#search%7Cga%7C1%7Cg%3Aio.fabric8%20a%3Aopenshift-model-operatorhub)
[![javadoc](https://javadoc.io/badge2/io.fabric8/openshift-model-operatorhub/javadoc.svg)](https://javadoc.io/doc/io.fabric8/openshift-model-operatorhub)
* openshift-model-machineconfig: [![Maven Central](https://img.shields.io/maven-central/v/io.fabric8/openshift-model-machineconfig.svg?maxAge=2592000)](http://search.maven.org/#search%7Cga%7C1%7Cg%3Aio.fabric8%20a%3Aopenshift-model-machineconfig)
[![javadoc](https://javadoc.io/badge2/io.fabric8/openshift-model-machineconfig/javadoc.svg)](https://javadoc.io/doc/io.fabric8/openshift-model-machineconfig)

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 @@ -44,6 +44,7 @@ declare -a modules=(
"openshift-model-operator"
"openshift-model-operatorhub"
"openshift-model-console"
"openshift-model-machineconfig"
"openshift-model-monitoring"
)
generateAll() {
Expand Down
5 changes: 4 additions & 1 deletion kubernetes-model-generator/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ module github.com/fabric8io/kubernetes-client/kubernetes-model-generator
go 1.14

require (
github.com/openshift/api v0.0.0-20200803131051-87466835fcc0
github.com/coreos/prometheus-operator v0.41.1
github.com/openshift/api v0.0.0-20210409143810-a99ffa1cac67
github.com/openshift/machine-config-operator v0.0.1-0.20210522071823-15494d85812c // indirect
github.com/operator-framework/api v0.3.12
github.com/prometheus-operator/prometheus-operator v0.47.1
k8s.io/api v0.21.0
Expand All @@ -22,6 +23,8 @@ replace (
k8s.io/controller-manager => k8s.io/controller-manager v0.21.0
k8s.io/mount-utils => k8s.io/mount-utils v0.21.0
k8s.io/client-go => k8s.io/client-go v0.21.0
bitbucket.org/ww/goautoneg => github.com/munnerz/goautoneg v0.0.0-20120707110453-a547fc61f48d
github.com/openshift/api => github.com/openshift/api v0.0.0-20200803131051-87466835fcc0
)

exclude (
Expand Down
277 changes: 277 additions & 0 deletions kubernetes-model-generator/go.sum

Large diffs are not rendered by default.

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 @@ -119,6 +119,7 @@
io.fabric8.openshift.api.model.operatorhub.manifests;resolution:=optional,
io.fabric8.openshift.api.model.operatorhub.v1;resolution:=optional,
io.fabric8.openshift.api.model.operatorhub.v1alpha1;resolution:=optional,
io.fabric8.openshift.api.model.machineconfig.v1;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 @@ -180,6 +180,7 @@ static class Mapping {
"io.fabric8.openshift.api.model.operatorhub.manifests.",
"io.fabric8.openshift.api.model.operatorhub.v1.",
"io.fabric8.openshift.api.model.operatorhub.v1alpha1.",
"io.fabric8.openshift.api.model.machineconfig.v1.",
"io.fabric8.kubernetes.api.model.extensions."
};

Expand Down
27 changes: 27 additions & 0 deletions kubernetes-model-generator/openshift-model-machineconfig/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,105 @@
/**
* 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"
machineconfig "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/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
ContainerRuntimeConfig machineconfig.ContainerRuntimeConfig
ContainerRuntimeConfigList machineconfig.ContainerRuntimeConfigList
ControllerConfig machineconfig.ControllerConfig
ControllerConfigList machineconfig.ControllerConfigList
KubeletConfig machineconfig.KubeletConfig
KubeletConfigList machineconfig.KubeletConfigList
MachineConfigPool machineconfig.MachineConfigPool
MachineConfigPoolList machineconfig.MachineConfigPoolList
MachineConfig machineconfig.MachineConfig
MachineConfigList machineconfig.MachineConfigList
}

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},
{"github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1", "machineconfiguration", "io.fabric8.openshift.api.model.machineconfig.v1", "os_machineconfig_v1_", 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,"machineconfig")
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())
}
102 changes: 102 additions & 0 deletions kubernetes-model-generator/openshift-model-machineconfig/pom.xml
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-machineconfig</artifactId>
<packaging>bundle</packaging>
<name>Fabric8 :: OpenShift Machine Config Operator 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.machineconfig**,
</Export-Package>
<Include-Resource>
{maven-resources},
/META-INF/jandex.idx=target/classes/META-INF/jandex.idx,
/machineconfig.properties=target/classes/machineconfig.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

0 comments on commit 646384f

Please sign in to comment.