aboutsummaryrefslogtreecommitdiffstats
path: root/src/k8splugin/plugins/generic
diff options
context:
space:
mode:
authorLukasz Rajewski <lukasz.rajewski@orange.com>2021-10-04 21:56:02 +0200
committerRitu Sood <ritu.sood@intel.com>2021-10-04 22:37:57 +0000
commit3766e380c40dc1e4c839372dcdc0c71a972ffa70 (patch)
tree411e06da7f3bc9ed999b02007a91fc3e114d8b63 /src/k8splugin/plugins/generic
parent2dde920d0f80d7c7fc3f2ed7ff41675ae6c28733 (diff)
Fixed installation of CRD resources
Issue-ID: MULTICLOUD-1397 Signed-off-by: Lukasz Rajewski <lukasz.rajewski@orange.com> Change-Id: Id8e653f1b5c61278ee2d64da409ac5b0685b36b8
Diffstat (limited to 'src/k8splugin/plugins/generic')
-rw-r--r--src/k8splugin/plugins/generic/plugin.go31
1 files changed, 30 insertions, 1 deletions
diff --git a/src/k8splugin/plugins/generic/plugin.go b/src/k8splugin/plugins/generic/plugin.go
index 5815b74f..a210f6d6 100644
--- a/src/k8splugin/plugins/generic/plugin.go
+++ b/src/k8splugin/plugins/generic/plugin.go
@@ -31,6 +31,7 @@ import (
"k8s.io/apimachinery/pkg/util/intstr"
pkgerrors "github.com/pkg/errors"
+ "github.com/prometheus/common/log"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
@@ -305,7 +306,18 @@ func (g genericPlugin) Create(yamlFilePath string, namespace string, client plug
if err != nil {
return "", pkgerrors.Wrap(err, "Mapping kind to resource error")
}
-
+ if gvk.Kind == "CustomResourceDefinition" {
+ //according the helm spec, CRD is created only once, and we raise only warn if we try to do it once more
+ resource := helm.KubernetesResource{}
+ resource.GVK = gvk
+ resource.Name = unstruct.GetName()
+ name, err := g.Get(resource, namespace, client)
+ if err == nil && name == resource.Name {
+ //CRD update is not supported according to Helm spec
+ log.Warn(fmt.Sprintf("CRD %s create will be skipped. It already exists", name))
+ return name, nil
+ }
+ }
//Add the tracking label to all resources created here
labels := unstruct.GetLabels()
//Check if labels exist for this object
@@ -362,6 +374,18 @@ func (g genericPlugin) Update(yamlFilePath string, namespace string, client plug
return "", pkgerrors.Wrap(err, "Mapping kind to resource error")
}
+ if gvk.Kind == "CustomResourceDefinition" {
+ resource := helm.KubernetesResource{}
+ resource.GVK = gvk
+ resource.Name = unstruct.GetName()
+ name, err := g.Get(resource, namespace, client)
+ if err == nil && name == resource.Name {
+ //CRD update is not supported according to Helm spec
+ log.Warn(fmt.Sprintf("CRD %s update will be skipped", name))
+ return name, nil
+ }
+ }
+
//Add the tracking label to all resources created here
labels := unstruct.GetLabels()
//Check if labels exist for this object
@@ -463,6 +487,11 @@ func (g genericPlugin) Delete(resource helm.KubernetesResource, namespace string
opts := metav1.DeleteOptions{
PropagationPolicy: &deletePolicy,
}
+ if resource.GVK.Kind == "CustomResourceDefinition" {
+ //CRD deletion is not supported according to Helm spec
+ log.Warn(fmt.Sprintf("CRD %s deletion will be skipped", resource.Name))
+ return nil
+ }
switch mapping.Scope.Name() {
case meta.RESTScopeNameNamespace: