aboutsummaryrefslogtreecommitdiffstats
path: root/src/k8splugin/internal
diff options
context:
space:
mode:
Diffstat (limited to 'src/k8splugin/internal')
-rw-r--r--src/k8splugin/internal/app/client.go57
-rw-r--r--src/k8splugin/internal/app/config_backend.go11
-rw-r--r--src/k8splugin/internal/plugin/helpers.go3
3 files changed, 69 insertions, 2 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,
diff --git a/src/k8splugin/internal/app/config_backend.go b/src/k8splugin/internal/app/config_backend.go
index 6bc145ee..4cbe1da3 100644
--- a/src/k8splugin/internal/app/config_backend.go
+++ b/src/k8splugin/internal/app/config_backend.go
@@ -360,10 +360,17 @@ func scheduleResources(c chan configResourceList) {
//Move onto the next cloud region
continue
}
+ //assuming - the resource is not exist already
data.createdResources, err = k8sClient.createResources(data.resourceTemplates, inst.Namespace)
+ errCreate := err
if err != nil {
- log.Printf("Error Creating resources: %s", err.Error())
- continue
+ // assuming - the err represent the resource is already exist, so going for update
+ data.createdResources, err = k8sClient.updateResources(data.resourceTemplates, inst.Namespace)
+ if err != nil {
+ log.Printf("Error Creating resources: %s", errCreate.Error())
+ log.Printf("Error Updating resources: %s", err.Error())
+ continue
+ }
}
}
//TODO: Needs to add code to call Kubectl create
diff --git a/src/k8splugin/internal/plugin/helpers.go b/src/k8splugin/internal/plugin/helpers.go
index ad785ab7..19ff03ab 100644
--- a/src/k8splugin/internal/plugin/helpers.go
+++ b/src/k8splugin/internal/plugin/helpers.go
@@ -68,6 +68,9 @@ type Reference interface {
//Delete a kubernetes resource described in the provided namespace
Delete(resource helm.KubernetesResource, namespace string, client KubernetesConnector) error
+
+ //Update kubernetes resource based on the groupVersionKind and resourceName provided in resource
+ Update(yamlFilePath string, namespace string, client KubernetesConnector) (string, error)
}
// GetPluginByKind returns a plugin by the kind name