This is an automated email from the ASF dual-hosted git repository.

lburgazzoli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit 8e99a72daca4e2b8f64a0bec01a5290689a87d06
Author: nferraro <ni.ferr...@gmail.com>
AuthorDate: Thu Nov 15 13:02:22 2018 +0100

    Fix CRD serialization
---
 cmd/camel-k/main.go             |  1 -
 cmd/kamel/main.go               |  1 -
 pkg/install/cluster.go          |  2 +-
 pkg/util/kubernetes/loader.go   | 23 ++++++++++++++++++++---
 pkg/util/kubernetes/register.go | 41 -----------------------------------------
 5 files changed, 21 insertions(+), 47 deletions(-)

diff --git a/cmd/camel-k/main.go b/cmd/camel-k/main.go
index dc30229..e5d71f3 100644
--- a/cmd/camel-k/main.go
+++ b/cmd/camel-k/main.go
@@ -29,7 +29,6 @@ import (
        sdkVersion "github.com/operator-framework/operator-sdk/version"
 
        _ "github.com/apache/camel-k/pkg/util/knative"
-       _ "github.com/apache/camel-k/pkg/util/kubernetes"
        _ "github.com/apache/camel-k/pkg/util/openshift"
 
        "github.com/sirupsen/logrus"
diff --git a/cmd/kamel/main.go b/cmd/kamel/main.go
index 9ffeec1..e711d0d 100644
--- a/cmd/kamel/main.go
+++ b/cmd/kamel/main.go
@@ -27,7 +27,6 @@ import (
        "github.com/apache/camel-k/pkg/client/cmd"
 
        _ "github.com/apache/camel-k/pkg/util/knative"
-       _ "github.com/apache/camel-k/pkg/util/kubernetes"
        _ "github.com/apache/camel-k/pkg/util/openshift"
        _ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
 )
diff --git a/pkg/install/cluster.go b/pkg/install/cluster.go
index ba9ea50..314de5e 100644
--- a/pkg/install/cluster.go
+++ b/pkg/install/cluster.go
@@ -86,7 +86,7 @@ func IsCRDInstalled(kind string) (bool, error) {
 func installCRD(kind string, resourceName string, collection 
*kubernetes.Collection) error {
        crd := []byte(deploy.Resources[resourceName])
        if collection != nil {
-               unstr, err := kubernetes.LoadResourceFromYaml(string(crd))
+               unstr, err := kubernetes.LoadRawResourceFromYaml(string(crd))
                if err != nil {
                        return err
                }
diff --git a/pkg/util/kubernetes/loader.go b/pkg/util/kubernetes/loader.go
index fdc1fb8..cd830da 100644
--- a/pkg/util/kubernetes/loader.go
+++ b/pkg/util/kubernetes/loader.go
@@ -18,6 +18,7 @@ limitations under the License.
 package kubernetes
 
 import (
+       "encoding/json"
        "github.com/operator-framework/operator-sdk/pkg/util/k8sutil"
        "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
        "k8s.io/apimachinery/pkg/runtime"
@@ -26,16 +27,32 @@ import (
 
 // LoadResourceFromYaml loads a k8s resource from a yaml definition
 func LoadResourceFromYaml(data string) (runtime.Object, error) {
-       role := []byte(data)
-       roleJSON, err := yaml.ToJSON(role)
+       source := []byte(data)
+       jsonSource, err := yaml.ToJSON(source)
        if err != nil {
                return nil, err
        }
        u := unstructured.Unstructured{}
-       err = u.UnmarshalJSON(roleJSON)
+       err = u.UnmarshalJSON(jsonSource)
        if err != nil {
                return nil, err
        }
 
        return k8sutil.RuntimeObjectFromUnstructured(&u)
 }
+
+// LoadRawResourceFromYaml loads a k8s resource from a yaml definition without 
making assumptions on the underlying type
+func LoadRawResourceFromYaml(data string) (runtime.Object, error) {
+       source := []byte(data)
+       jsonSource, err := yaml.ToJSON(source)
+       if err != nil {
+               return nil, err
+       }
+       var objmap map[string]interface{}
+       if err = json.Unmarshal(jsonSource, &objmap); err != nil {
+               return nil, err
+       }
+       return &unstructured.Unstructured{
+               Object: objmap,
+       }, nil
+}
diff --git a/pkg/util/kubernetes/register.go b/pkg/util/kubernetes/register.go
deleted file mode 100644
index c043a4d..0000000
--- a/pkg/util/kubernetes/register.go
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
-Licensed to the Apache Software Foundation (ASF) under one or more
-contributor license agreements.  See the NOTICE file distributed with
-this work for additional information regarding copyright ownership.
-The ASF licenses this file to You 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 kubernetes
-
-import (
-       "github.com/operator-framework/operator-sdk/pkg/util/k8sutil"
-       "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions"
-       "k8s.io/apimachinery/pkg/runtime"
-       "k8s.io/apimachinery/pkg/runtime/schema"
-)
-
-// Register all OpenShift types that we want to manage.
-func init() {
-       k8sutil.AddToSDKScheme(addKnownTypes)
-}
-
-type registerFunction func(*runtime.Scheme) error
-
-func addKnownTypes(scheme *runtime.Scheme) error {
-       gv := schema.GroupVersion{
-               Group:   "apiextensions.k8s.io",
-               Version: "v1beta1",
-       }
-       scheme.AddKnownTypes(gv, &apiextensions.CustomResourceDefinition{}, 
&apiextensions.CustomResourceDefinitionList{})
-       return nil
-}

Reply via email to