Skip to content

Commit

Permalink
Merge pull request fabric8io#2222 from Fabian-K/service-catalog-rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
fusesource-ci authored May 15, 2020
2 parents 1f1ab07 + b9bf14c commit cc916a2
Show file tree
Hide file tree
Showing 19 changed files with 1,396 additions and 5,691 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
@VelocityTransformation(value = "/resource-handler-services.vm", gather = true, outputPath = "META-INF/services/io.fabric8.kubernetes.client.ResourceHandler")
},
resources = {
@ResourceSelector("servicecatalog.properties")
@ResourceSelector("model.properties")
}

)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,60 +19,84 @@
import io.fabric8.kubernetes.client.dsl.FunctionCallable;
import io.fabric8.kubernetes.client.dsl.MixedOperation;
import io.fabric8.kubernetes.client.dsl.NonNamespaceOperation;
import io.fabric8.kubernetes.client.dsl.Resource;
import io.fabric8.servicecatalog.api.model.DoneableClusterServiceBroker;
import io.fabric8.servicecatalog.api.model.DoneableClusterServiceClass;
import io.fabric8.servicecatalog.api.model.DoneableClusterServicePlan;
import io.fabric8.servicecatalog.api.model.DoneableServiceBinding;
import io.fabric8.servicecatalog.api.model.DoneableServiceBroker;
import io.fabric8.servicecatalog.api.model.DoneableServiceClass;
import io.fabric8.servicecatalog.api.model.DoneableServiceInstance;
import io.fabric8.servicecatalog.api.model.DoneableServicePlan;
import io.fabric8.servicecatalog.client.internal.*;
import io.fabric8.servicecatalog.api.model.*;
import okhttp3.OkHttpClient;

public class DefaultServiceCatalogClient extends BaseClient implements NamespacedServiceCatalogClient {

public DefaultServiceCatalogClient() {
super();
}

public DefaultServiceCatalogClient(Config configuration) {
super(configuration);
}

public DefaultServiceCatalogClient(OkHttpClient httpClient, Config configuration) {
super(httpClient, configuration);
}

public NonNamespaceOperation<ClusterServiceBroker, ClusterServiceBrokerList, DoneableClusterServiceBroker, ClusterServiceBrokerResource> clusterServiceBrokers(){
return new ClusterServiceBrokerOperationsImpl(this.getHttpClient(), this.getConfiguration());
}
public NonNamespaceOperation<ClusterServiceClass, ClusterServiceClassList, DoneableClusterServiceClass, ClusterServiceClassResource> clusterServiceClasses() {
return new ClusterServiceClassOperationsImpl(this.getHttpClient(), this.getConfiguration());
}
public NonNamespaceOperation<ClusterServicePlan, ClusterServicePlanList, DoneableClusterServicePlan, ClusterServicePlanResource> clusterServicePlans() {
return new ClusterServicePlanOperationsImpl(this.getHttpClient(), this.getConfiguration());
}
public MixedOperation<ServiceInstance, ServiceInstanceList, DoneableServiceInstance, ServiceInstanceResource> serviceInstances() {
return new ServiceInstanceOperationsImpl(this.getHttpClient(), this.getConfiguration());
}
public MixedOperation<ServiceBinding, ServiceBindingList, DoneableServiceBinding, ServiceBindingResource> serviceBindings() {
return new ServiceBindingOperationsImpl(this.getHttpClient(), this.getConfiguration());
}

@Override
public NamespacedServiceCatalogClient inAnyNamespace() {
return inNamespace(null);
}

@Override
public NamespacedServiceCatalogClient inNamespace(String namespace) {
Config updated = new ConfigBuilder(getConfiguration())
.withNamespace(namespace)
.build();

return new DefaultServiceCatalogClient(getHttpClient(), updated);
}
public DefaultServiceCatalogClient() {
super();
}

public DefaultServiceCatalogClient(Config configuration) {
super(configuration);
}

public DefaultServiceCatalogClient(OkHttpClient httpClient, Config configuration) {
super(httpClient, configuration);
}

public NonNamespaceOperation<ClusterServiceBroker, ClusterServiceBrokerList, DoneableClusterServiceBroker, ClusterServiceBrokerResource> clusterServiceBrokers() {
return new ClusterServiceBrokerOperationsImpl(this.getHttpClient(), this.getConfiguration());
}

public NonNamespaceOperation<ClusterServiceClass, ClusterServiceClassList, DoneableClusterServiceClass, ClusterServiceClassResource> clusterServiceClasses() {
return new ClusterServiceClassOperationsImpl(this.getHttpClient(), this.getConfiguration());
}

public NonNamespaceOperation<ClusterServicePlan, ClusterServicePlanList, DoneableClusterServicePlan, ClusterServicePlanResource> clusterServicePlans() {
return new ClusterServicePlanOperationsImpl(this.getHttpClient(), this.getConfiguration());
}

public MixedOperation<ServiceInstance, ServiceInstanceList, DoneableServiceInstance, ServiceInstanceResource> serviceInstances() {
return new ServiceInstanceOperationsImpl(this.getHttpClient(), this.getConfiguration());
}

public MixedOperation<ServiceBinding, ServiceBindingList, DoneableServiceBinding, ServiceBindingResource> serviceBindings() {
return new ServiceBindingOperationsImpl(this.getHttpClient(), this.getConfiguration());
}

@Override
public MixedOperation<ServiceBroker, ServiceBrokerList, DoneableServiceBroker, Resource<ServiceBroker, DoneableServiceBroker>> serviceBrokers() {
return new ServiceBrokerOperationsImpl(this.getHttpClient(), this.getConfiguration());
}

@Override
public MixedOperation<ServiceClass, ServiceClassList, DoneableServiceClass, Resource<ServiceClass, DoneableServiceClass>> serviceClasses() {
return new ServiceClassOperationsImpl(this.getHttpClient(), this.getConfiguration());
}

@Override
public MixedOperation<ServicePlan, ServicePlanList, DoneableServicePlan, Resource<ServicePlan, DoneableServicePlan>> servicePlans() {
return new ServicePlanOperationsImpl(this.getHttpClient(), this.getConfiguration());
}

@Override
public NamespacedServiceCatalogClient inAnyNamespace() {
return inNamespace(null);
}

@Override
public NamespacedServiceCatalogClient inNamespace(String namespace) {
Config updated = new ConfigBuilder(getConfiguration())
.withNamespace(namespace)
.build();

return new DefaultServiceCatalogClient(getHttpClient(), updated);
}

@Override
public FunctionCallable<NamespacedServiceCatalogClient> withRequestConfig(RequestConfig requestConfig) {
return new WithRequestCallable<NamespacedServiceCatalogClient>(this, requestConfig);
return new WithRequestCallable<>(this, requestConfig);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@
import io.fabric8.kubernetes.client.Client;
import io.fabric8.kubernetes.client.dsl.MixedOperation;
import io.fabric8.kubernetes.client.dsl.NonNamespaceOperation;
import io.fabric8.kubernetes.client.dsl.Resource;
import io.fabric8.servicecatalog.api.model.DoneableClusterServiceBroker;
import io.fabric8.servicecatalog.api.model.DoneableClusterServiceClass;
import io.fabric8.servicecatalog.api.model.DoneableClusterServicePlan;
import io.fabric8.servicecatalog.api.model.DoneableServiceBinding;
import io.fabric8.servicecatalog.api.model.DoneableServiceBroker;
import io.fabric8.servicecatalog.api.model.DoneableServiceClass;
import io.fabric8.servicecatalog.api.model.DoneableServiceInstance;
import io.fabric8.servicecatalog.api.model.DoneableServicePlan;
import io.fabric8.servicecatalog.client.internal.*;
import io.fabric8.servicecatalog.api.model.*;

Expand All @@ -38,4 +42,11 @@ public interface ServiceCatalogClient extends Client {
MixedOperation<ServiceInstance, ServiceInstanceList, DoneableServiceInstance, ServiceInstanceResource> serviceInstances();

MixedOperation<ServiceBinding, ServiceBindingList, DoneableServiceBinding, ServiceBindingResource> serviceBindings();

MixedOperation<ServiceBroker, ServiceBrokerList, DoneableServiceBroker, Resource<ServiceBroker, DoneableServiceBroker>> serviceBrokers();

MixedOperation<ServiceClass, ServiceClassList, DoneableServiceClass, Resource<ServiceClass, DoneableServiceClass>> serviceClasses();

MixedOperation<ServicePlan, ServicePlanList, DoneableServicePlan, Resource<ServicePlan, DoneableServicePlan>> servicePlans();

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
#end
#end

#set ($isResourceNamespacedFlag = false)
#foreach ($impl in $model.getImplementsList())
#if ($impl.getFullyQualifiedName().equals("io.fabric8.kubernetes.api.model.Namespaced"))
#set ($isResourceNamespacedFlag = true)
#end
#end

package io.fabric8.servicecatalog.client.internal;

Expand Down Expand Up @@ -65,4 +71,9 @@ public class ${model.name}OperationsImpl extends HasMetadataOperation<${model.na
public ${model.name}OperationsImpl newInstance(OperationContext context) {
return new ${model.name}OperationsImpl(context);
}

@Override
public boolean isResourceNamespaced() {
return $isResourceNamespacedFlag;
}
}
1 change: 1 addition & 0 deletions extensions/service-catalog/generator/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/vendor/
28 changes: 28 additions & 0 deletions extensions/service-catalog/generator/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#
# 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
pushd ../model && \
mvn clean install -o && \
popd

gobuild:
go mod vendor
CGO_ENABLED=0 GO111MODULE=on GO15VENDOREXPERIMENT=1 go run -mod=vendor -a ./cmd/generate/generate.go > ../model/src/main/resources/schema/servicecatalog-schema.json
79 changes: 79 additions & 0 deletions extensions/service-catalog/generator/cmd/generate/generate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/**
* 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 (
"fmt"
"github.com/fabric8io/kubernetes-client/generator/pkg/schemagen"
"github.com/kubernetes-sigs/service-catalog/pkg/apis/servicecatalog/v1beta1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"reflect"
)

func main() {

// the CRD List types for which the model should be generated
// no other types need to be defined as they are auto discovered
crdLists := map[reflect.Type]schemagen.CrdScope{
reflect.TypeOf(v1beta1.ClusterServiceBrokerList{}): schemagen.Cluster,
reflect.TypeOf(v1beta1.ClusterServiceClassList{}): schemagen.Cluster,
reflect.TypeOf(v1beta1.ClusterServicePlanList{}): schemagen.Cluster,

reflect.TypeOf(v1beta1.ServiceInstanceList{}): schemagen.Namespaced,
reflect.TypeOf(v1beta1.ServiceBindingList{}): schemagen.Namespaced,
reflect.TypeOf(v1beta1.ServiceBrokerList{}): schemagen.Namespaced,
reflect.TypeOf(v1beta1.ServiceClassList{}): schemagen.Namespaced,
reflect.TypeOf(v1beta1.ServicePlanList{}): schemagen.Namespaced,
}

// constraints and patterns for fields
constraints := map[reflect.Type]map[string]*schemagen.Constraint{}

// types that are manually defined in the model
providedTypes := []schemagen.ProvidedType{}

// go packages that are provided and where no generation is required and their corresponding java package
providedPackages := map[string]string{
// external
"k8s.io/apimachinery/pkg/apis/meta/v1": "io.fabric8.kubernetes.api.model",
}

// mapping of go packages of this module to the resulting java package
// optional ApiGroup and ApiVersion for the go package (which is added to the generated java class)
packageMapping := map[string]schemagen.PackageInformation{
"github.com/kubernetes-sigs/service-catalog/pkg/apis/servicecatalog/v1beta1": {JavaPackage: "io.fabric8.servicecatalog.api.model", ApiGroup: "servicecatalog.k8s.io", ApiVersion: "v1beta1"},
}

// converts all packages starting with <key> to a java package using an automated scheme:
// - replace <key> with <value> aka "package prefix"
// - replace '/' with '.' for a valid java package name
// e.g. knative.dev/eventing/pkg/apis/messaging/v1beta1/ChannelTemplateSpec is mapped to "io.fabric8.knative.internal.eventing.pkg.apis.messaging.v1beta1.ChannelTemplateSpec"
mappingSchema := map[string]string{
"github.com/kubernetes-sigs": "io.fabric8.servicecatalog.internal",
}

// overwriting some times
manualTypeMap := map[reflect.Type]string{
reflect.TypeOf(v1.Time{}): "java.lang.String",
reflect.TypeOf(runtime.RawExtension{}): "Map<String, Object>",
reflect.TypeOf([]byte{}): "java.lang.String",
}

json := schemagen.GenerateSchema("http://fabric8.io/knative/ServiceCatalogSchema#", crdLists, providedPackages, manualTypeMap, packageMapping, mappingSchema, providedTypes, constraints)

fmt.Println(json)
}
11 changes: 11 additions & 0 deletions extensions/service-catalog/generator/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module github.com/fabric8io/kubernetes-client/extensions/knative/generator

require (
github.com/fabric8io/kubernetes-client/generator v0.0.0
github.com/kubernetes-sigs/service-catalog v0.2.2
k8s.io/apimachinery v0.18.2
)

replace github.com/fabric8io/kubernetes-client/generator v0.0.0 => ./../../../generator

go 1.13
Loading

0 comments on commit cc916a2

Please sign in to comment.