summaryrefslogtreecommitdiffstats
path: root/src/k8splugin/internal/app/client.go
diff options
context:
space:
mode:
authorvamshi.nemalikonda <vn00480215@techmahindra.com>2020-07-24 12:05:51 +0000
committerRitu Sood <Ritu.Sood@intel.com>2020-08-26 15:59:47 +0000
commit9c942a11c14836630ba528b75bdcb2790045b91f (patch)
tree55404d7b7d8a4189c0eed99de39cb42e3a630341 /src/k8splugin/internal/app/client.go
parent16ca82713faf6678d4b7055130768541f86ea20c (diff)
Improve configure API to support k8s resource updations
Code fore review. Issue-ID: MULTICLOUD-1124 Change-Id: I6bb9786660f6760c15008132f1c254e7f9b39561 Signed-off-by: vamshi.nemalikonda <vn00480215@techmahindra.com> Improve configure API to support k8s resource updations create resource enabled. Issue-ID: MULTICLOUD-1124 Change-Id: I6bb9786660f6760c15008132f1c254e7f9b39561 Signed-off-by: vamshi.nemalikonda <vn00480215@techmahindra.com> Improve configure API to support k8s resource updations code improvements. Issue-ID: MULTICLOUD-1124 Change-Id: I6bb9786660f6760c15008132f1c254e7f9b39561 Signed-off-by: vamshi.nemalikonda <vn00480215@techmahindra.com> Improve configure API to support k8s resource updations fixing unit test failures. Issue-ID: MULTICLOUD-1124 Change-Id: I6bb9786660f6760c15008132f1c254e7f9b39561 Signed-off-by: vamshi.nemalikonda <vn00480215@techmahindra.com>
Diffstat (limited to 'src/k8splugin/internal/app/client.go')
-rw-r--r--src/k8splugin/internal/app/client.go57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/k8splugin/internal/app/client.go b/src/k8splugin/internal/app/client.go
index d3e5081a..ed606444 100644
--- a/src/k8splugin/internal/app/client.go
+++ b/src/k8splugin/internal/app/client.go
@@ -181,6 +181,43 @@ func (k *KubernetesClient) createKind(resTempl helm.KubernetesResourceTemplate,
}, nil
}
+func (k *KubernetesClient) updateKind(resTempl helm.KubernetesResourceTemplate,
+ namespace string) (helm.KubernetesResource, error) {
+
+ if _, err := os.Stat(resTempl.FilePath); os.IsNotExist(err) {
+ return helm.KubernetesResource{}, pkgerrors.New("File " + resTempl.FilePath + "does not exists")
+ }
+
+ log.Info("Processing Kubernetes Resource", log.Fields{
+ "filepath": resTempl.FilePath,
+ })
+
+ pluginImpl, err := plugin.GetPluginByKind(resTempl.GVK.Kind)
+ if err != nil {
+ return helm.KubernetesResource{}, pkgerrors.Wrap(err, "Error loading plugin")
+ }
+
+ updatedResourceName, err := pluginImpl.Update(resTempl.FilePath, namespace, k)
+ if err != nil {
+ log.Error("Error Updating Resource", log.Fields{
+ "error": err,
+ "gvk": resTempl.GVK,
+ "filepath": resTempl.FilePath,
+ })
+ return helm.KubernetesResource{}, pkgerrors.Wrap(err, "Error in plugin "+resTempl.GVK.Kind+" plugin")
+ }
+
+ log.Info("Updated Kubernetes Resource", log.Fields{
+ "resource": updatedResourceName,
+ "gvk": resTempl.GVK,
+ })
+
+ return helm.KubernetesResource{
+ GVK: resTempl.GVK,
+ Name: updatedResourceName,
+ }, nil
+}
+
func (k *KubernetesClient) createResources(sortedTemplates []helm.KubernetesResourceTemplate,
namespace string) ([]helm.KubernetesResource, error) {
@@ -201,6 +238,26 @@ func (k *KubernetesClient) createResources(sortedTemplates []helm.KubernetesReso
return createdResources, nil
}
+func (k *KubernetesClient) updateResources(sortedTemplates []helm.KubernetesResourceTemplate,
+ namespace string) ([]helm.KubernetesResource, error) {
+
+ err := k.ensureNamespace(namespace)
+ if err != nil {
+ return nil, pkgerrors.Wrap(err, "Creating Namespace")
+ }
+
+ var updatedResources []helm.KubernetesResource
+ for _, resTempl := range sortedTemplates {
+ resUpdated, err := k.updateKind(resTempl, namespace)
+ if err != nil {
+ return nil, pkgerrors.Wrapf(err, "Error updating kind: %+v", resTempl.GVK)
+ }
+ updatedResources = append(updatedResources, resUpdated)
+ }
+
+ return updatedResources, nil
+}
+
func (k *KubernetesClient) deleteKind(resource helm.KubernetesResource, namespace string) error {
log.Warn("Deleting Resource", log.Fields{
"gvk": resource.GVK,