RIC-208 - KA Decision: ask K8S to restart E2T instance

Change-Id: I8dc3bfec43404937152b897a15b1c31b19d6b3f2
Signed-off-by: Irina <ib565x@intl.att.com>
diff --git a/E2Manager/Dockerfile b/E2Manager/Dockerfile
index 1679468..c6b943b 100755
--- a/E2Manager/Dockerfile
+++ b/E2Manager/Dockerfile
@@ -39,6 +39,7 @@
   tcpdump
 
 COPY --from=ubuntu /opt/E2Manager/router.txt /opt/E2Manager/router.txt
+COPY --from=ubuntu /opt/E2Manager/kube_config.yml /opt/E2Manager/kube_config.yml
 COPY --from=ubuntu /opt/E2Manager/main /opt/E2Manager/main
 COPY --from=ubuntu /opt/E2Manager/resources/configuration.yaml /opt/E2Manager/resources/configuration.yaml
 COPY --from=ubuntu /opt/E2Manager/resources/rmr.verbose /tmp/rmr.verbose
diff --git a/E2Manager/configuration/configuration.go b/E2Manager/configuration/configuration.go
index 43beee0..4e8883e 100644
--- a/E2Manager/configuration/configuration.go
+++ b/E2Manager/configuration/configuration.go
@@ -38,10 +38,10 @@
 	RoutingManager struct {
 		BaseUrl string
 	}
-/*	Kubernetes struct {
+	Kubernetes struct {
 		ConfigPath string
-		Namespace  string
-	}*/
+		KubeNamespace  string
+	}
 	NotificationResponseBuffer   int
 	BigRedButtonTimeoutSec       int
 	MaxRnibConnectionAttempts    int
@@ -72,7 +72,7 @@
 	config.populateHttpConfig(viper.Sub("http"))
 	config.populateLoggingConfig(viper.Sub("logging"))
 	config.populateRoutingManagerConfig(viper.Sub("routingManager"))
-	//config.populateKubernetesConfig(viper.Sub("kubernetes"))
+	config.populateKubernetesConfig(viper.Sub("kubernetes"))
 	config.NotificationResponseBuffer = viper.GetInt("notificationResponseBuffer")
 	config.BigRedButtonTimeoutSec = viper.GetInt("bigRedButtonTimeoutSec")
 	config.MaxRnibConnectionAttempts = viper.GetInt("maxRnibConnectionAttempts")
@@ -113,13 +113,13 @@
 	c.RoutingManager.BaseUrl = rmConfig.GetString("baseUrl")
 }
 
-/*func (c *Configuration) populateKubernetesConfig(rmConfig *viper.Viper) {
+func (c *Configuration) populateKubernetesConfig(rmConfig *viper.Viper) {
 	if rmConfig == nil {
 		panic(fmt.Sprintf("#configuration.populateKubernetesConfig - failed to populate Kubernetes configuration: The entry 'kubernetes' not found\n"))
 	}
 	c.Kubernetes.ConfigPath = rmConfig.GetString("configPath")
-	c.Kubernetes.Namespace = rmConfig.GetString("namespace")
-}*/
+	c.Kubernetes.KubeNamespace = rmConfig.GetString("kubeNamespace")
+}
 
 func (c *Configuration) populateGlobalRicIdConfig(globalRicIdConfig *viper.Viper) {
 	if globalRicIdConfig == nil {
@@ -133,7 +133,7 @@
 	return fmt.Sprintf("{logging.logLevel: %s, http.port: %d, rmr: { port: %d, maxMsgSize: %d}, routingManager.baseUrl: %s, "+
 		"notificationResponseBuffer: %d, bigRedButtonTimeoutSec: %d, maxRnibConnectionAttempts: %d, "+
 		"rnibRetryIntervalMs: %d, keepAliveResponseTimeoutMs: %d, keepAliveDelayMs: %d, e2tInstanceDeletionTimeoutMs: %d, "+
-		"globalRicId: { plmnId: %s, ricNearRtId: %s}}",//, kubernetes: {configPath: %s, namespace: %s}}",
+		"globalRicId: { plmnId: %s, ricNearRtId: %s, kubernetes: {configPath: %s, kubeNamespace: %s}}",
 		c.Logging.LogLevel,
 		c.Http.Port,
 		c.Rmr.Port,
@@ -148,7 +148,7 @@
 		c.E2TInstanceDeletionTimeoutMs,
 		c.GlobalRicId.PlmnId,
 		c.GlobalRicId.RicNearRtId,
-	//	c.Kubernetes.ConfigPath,
-		//c.Kubernetes.Namespace,
+		c.Kubernetes.ConfigPath,
+		c.Kubernetes.KubeNamespace,
 	)
 }
diff --git a/E2Manager/configuration/configuration_test.go b/E2Manager/configuration/configuration_test.go
index cdbf338..cad2254 100644
--- a/E2Manager/configuration/configuration_test.go
+++ b/E2Manager/configuration/configuration_test.go
@@ -42,8 +42,8 @@
 	assert.NotNil(t, config.GlobalRicId)
 	assert.NotEmpty(t, config.GlobalRicId.PlmnId)
 	assert.NotEmpty(t, config.GlobalRicId.RicNearRtId)
-	/*assert.NotEmpty(t, config.Kubernetes.Namespace)
-	assert.NotEmpty(t, config.Kubernetes.ConfigPath)*/
+	assert.NotEmpty(t, config.Kubernetes.KubeNamespace)
+	assert.NotEmpty(t, config.Kubernetes.ConfigPath)
 }
 
 func TestStringer(t *testing.T) {
@@ -208,7 +208,7 @@
 		"logging": map[string]interface{}{"logLevel": "info"},
 		"http": map[string]interface{}{"port": 3800},
 		"routingManager":    map[string]interface{}{"baseUrl": "http://iltlv740.intl.att.com:8080/ric/v1/handles/"},
-		//"kubernetes":    map[string]interface{}{"namespace": "test", "ConfigPath": "test"},
+		"kubernetes":    map[string]interface{}{"kubeNamespace": "test", "ConfigPath": "test"},
 	}
 	buf, err := yaml.Marshal(yamlMap)
 	if err != nil {
@@ -222,7 +222,7 @@
 		func() { ParseConfiguration() })
 }
 
-/*func TestKubernetesConfigNotFoundFailure(t *testing.T) {
+func TestKubernetesConfigNotFoundFailure(t *testing.T) {
 	configPath := "../resources/configuration.yaml"
 	configPathTmp := "../resources/configuration.yaml_tmp"
 	err := os.Rename(configPath, configPathTmp)
@@ -252,4 +252,4 @@
 	}
 	assert.PanicsWithValue(t, "#configuration.populateKubernetesConfig - failed to populate Kubernetes configuration: The entry 'kubernetes' not found\n",
 		func() { ParseConfiguration() })
-}*/
+}
diff --git a/E2Manager/container-tag.yaml b/E2Manager/container-tag.yaml
index 85beee9..5ea99c4 100644
--- a/E2Manager/container-tag.yaml
+++ b/E2Manager/container-tag.yaml
@@ -1,4 +1,4 @@
 # The Jenkins job requires a tag to build the Docker image.
 # Global-JJB script assumes this file is in the repo root.
 ---
-tag: 4.4.6
+tag: 4.4.7
diff --git a/E2Manager/go.sum b/E2Manager/go.sum
index 193bed0..4bb1c2a 100644
--- a/E2Manager/go.sum
+++ b/E2Manager/go.sum
@@ -113,6 +113,7 @@
 github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
 github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
 github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
+github.com/imdario/mergo v0.3.5 h1:JboBksRwiiAJWvIYJVo46AfV+IAIKZpfrSzVKj42R4Q=
 github.com/imdario/mergo v0.3.5/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
 github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
 github.com/json-iterator/go v0.0.0-20180612202835-f2b4162afba3/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
diff --git a/E2Manager/kub_config.yml b/E2Manager/kube_config.yml
similarity index 100%
rename from E2Manager/kub_config.yml
rename to E2Manager/kube_config.yml
diff --git a/E2Manager/managers/e2t_shutdown_manager.go b/E2Manager/managers/e2t_shutdown_manager.go
index 6287547..bb89e3b 100644
--- a/E2Manager/managers/e2t_shutdown_manager.go
+++ b/E2Manager/managers/e2t_shutdown_manager.go
@@ -62,7 +62,7 @@
 		return nil
 	}
 
-	//go m.kubernetesManager.DeletePod(e2tInstance.PodName)
+	go m.kubernetesManager.DeletePod(e2tInstance.PodName)
 
 	err := m.markE2tInstanceToBeDeleted(e2tInstance)
 	if err != nil {
diff --git a/E2Manager/managers/e2t_shutdown_manager_test.go b/E2Manager/managers/e2t_shutdown_manager_test.go
index 499f067..7490c42 100644
--- a/E2Manager/managers/e2t_shutdown_manager_test.go
+++ b/E2Manager/managers/e2t_shutdown_manager_test.go
@@ -35,8 +35,8 @@
 	"github.com/stretchr/testify/assert"
 	"github.com/stretchr/testify/mock"
 	"io/ioutil"
-	//"k8s.io/apimachinery/pkg/runtime"
-	//"k8s.io/client-go/kubernetes/fake"
+	"k8s.io/apimachinery/pkg/runtime"
+	"k8s.io/client-go/kubernetes/fake"
 	"net/http"
 	"testing"
 	"time"
@@ -56,14 +56,11 @@
 	httpClientMock := &mocks.HttpClientMock{}
 	rmClient := clients.NewRoutingManagerClient(log, config, httpClientMock)
 	associationManager := NewE2TAssociationManager(log, rnibDataService, e2tInstancesManager, rmClient)
-	//kubernetesManager := initKubernetesManagerTest(t)
+	kubernetesManager := initKubernetesManagerTest(t)
 
-	/*shutdownManager := NewE2TShutdownManager(log, config, rnibDataService, e2tInstancesManager, associationManager, kubernetesManager)
+	shutdownManager := NewE2TShutdownManager(log, config, rnibDataService, e2tInstancesManager, associationManager, kubernetesManager)
 
-	return shutdownManager, readerMock, writerMock, httpClientMock, kubernetesManager*/
-	shutdownManager := NewE2TShutdownManager(log, config, rnibDataService, e2tInstancesManager, associationManager, nil)
-
-	return shutdownManager, readerMock, writerMock, httpClientMock, nil
+	return shutdownManager, readerMock, writerMock, httpClientMock, kubernetesManager
 }
 
 func TestShutdownSuccess1OutOf3Instances(t *testing.T) {
@@ -184,7 +181,7 @@
 	readerMock.AssertExpectations(t)
 	writerMock.AssertExpectations(t)
 	httpClientMock.AssertExpectations(t)
-	
+
 }
 
 func TestShutdownE2tInstanceAlreadyBeingDeleted(t *testing.T) {
@@ -201,7 +198,7 @@
 	readerMock.AssertExpectations(t)
 	writerMock.AssertExpectations(t)
 	httpClientMock.AssertExpectations(t)
-	
+
 }
 
 func TestShutdownFailureMarkInstanceAsToBeDeleted(t *testing.T) {
@@ -218,7 +215,7 @@
 	readerMock.AssertExpectations(t)
 	writerMock.AssertExpectations(t)
 	httpClientMock.AssertExpectations(t)
-	
+
 }
 
 func TestShutdownFailureRoutingManagerError(t *testing.T) {
@@ -273,7 +270,7 @@
 	readerMock.AssertExpectations(t)
 	writerMock.AssertExpectations(t)
 	httpClientMock.AssertExpectations(t)
-	
+
 }
 
 func TestShutdownFailureInClearNodebsAssociation(t *testing.T) {
@@ -412,7 +409,7 @@
 	writerMock.AssertExpectations(t)
 	httpClientMock.AssertExpectations(t)
 }
-/*
+
 func TestShutdownSuccess2Instance2Rans(t *testing.T) {
 	shutdownManager, readerMock, writerMock, httpClientMock,kubernetesManager  := initE2TShutdownManagerTest(t)
 
@@ -507,4 +504,4 @@
 		writerMock.AssertExpectations(t)
 		httpClientMock.AssertExpectations(t)
 	})
-}*/
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/E2Manager/managers/kubernetes_manager.go b/E2Manager/managers/kubernetes_manager.go
index ef36c28..09a64b7 100644
--- a/E2Manager/managers/kubernetes_manager.go
+++ b/E2Manager/managers/kubernetes_manager.go
@@ -22,8 +22,12 @@
 
 import (
 	"e2mgr/configuration"
+	"e2mgr/e2managererrors"
 	"e2mgr/logger"
+	metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 	"k8s.io/client-go/kubernetes"
+	"k8s.io/client-go/tools/clientcmd"
+	"path/filepath"
 )
 
 type KubernetesManager struct {
@@ -35,32 +39,12 @@
 func NewKubernetesManager(logger *logger.Logger, config *configuration.Configuration) *KubernetesManager {
 	return &KubernetesManager{
 		Logger:    logger,
-	//	ClientSet: createClientSet(logger, config),
+		ClientSet: createClientSet(logger, config),
 		Config:    config,
 	}
 }
 
-/*func (km KubernetesManager) GetAndDeletePod(namespace string, podName string) {
-	km.logger.Infof("#KubernetesManager.GetAndDeletePod - namespace: %s, POD name: %s ", namespace, podName)
-
-	config, err := clientcmd.BuildConfigFromFlags("", "kubeConfigPath")
-	if err != nil {
-		log.Fatal(err)
-	}
-
-	clientSet, _ := kubernetesManager.NewForConfig(config)
-
-	podInterface := km.GetPodInterface(clientSet.CoreV1(), namespace, podName)
-
-	if podInterface == nil{
-		return
-	}
-
-	km.DeletePod(podInterface, podName)
-}*/
-
-/*func createClientSet(logger *logger.Logger, config *configuration.Configuration) kubernetes.Interface {
-	////path := os.Getenv("HOME") + "/.kube/config"
+func createClientSet(logger *logger.Logger, config *configuration.Configuration) kubernetes.Interface {
 
 	absConfigPath,err := filepath.Abs(config.Kubernetes.ConfigPath)
 	if err != nil {
@@ -80,22 +64,10 @@
 		return nil
 	}
 	return clientSet
-}*/
-
-/*func (km KubernetesManager) DeletePod(podInterface v1.PodInterface, podName string) {
-	km.logger.Infof("#KubernetesManager.DeletePod - POD name %s ", podName)
-
-	err := podInterface.Delete(podName, &metaV1.DeleteOptions{})
-
-	if err != nil{
-		km.logger.Warnf("#KubernetesManager.DeletePod - POD %s can't be deleted", podName)
-		return
-	}
-	km.logger.Infof("#KubernetesManager.DeletePod - POD %s was deleted", podName)
 }
-*/
+
 func (km KubernetesManager) DeletePod(podName string) error {
-/*	km.Logger.Infof("#KubernetesManager.DeletePod - POD name: %s ", podName)
+	km.Logger.Infof("#KubernetesManager.DeletePod - POD name: %s ", podName)
 
 	if km.ClientSet == nil {
 		km.Logger.Errorf("#KubernetesManager.DeletePod - no kubernetesManager connection")
@@ -107,30 +79,13 @@
 		return e2managererrors.NewInternalError()
 	}
 
-	err := km.ClientSet.CoreV1().Pods(km.Config.Kubernetes.Namespace).Delete(podName, &metaV1.DeleteOptions{})
+	err := km.ClientSet.CoreV1().Pods(km.Config.Kubernetes.KubeNamespace).Delete(podName, &metaV1.DeleteOptions{})
 
 	if err != nil {
 		km.Logger.Errorf("#KubernetesManager.DeletePod - POD %s can't be deleted, error: %s", podName, err)
 		return err
 	}
 
-	km.Logger.Infof("#KubernetesManager.DeletePod - POD %s was deleted", podName)*/
+	km.Logger.Infof("#KubernetesManager.DeletePod - POD %s was deleted", podName)
 	return nil
-}
-
-/*func (km KubernetesManager) GetPodInterface(client v1.CoreV1Interface, namespace string, podName string) v1.PodInterface{
-	km.logger.Infof("#KubernetesManager.GetPodInterface - namespace: %s, POD name: %s ", namespace, podName)
-
-
-	podInterface := client.Pods(namespace)
-	pod, err := podInterface.Get(podName, metaV1.GetOptions{})
-
-	if err != nil{
-		km.logger.Warnf("#KubernetesManager.GetPodInterface - POD name: %s not found", podName)
-		return nil
-	}
-
-	km.logger.Infof("#KubernetesManager.GetPodInterface - POD status: %s ", pod.Status.String())
-
-	return podInterface
-}*/
+}
\ No newline at end of file
diff --git a/E2Manager/managers/kubernetes_manager_test.go b/E2Manager/managers/kubernetes_manager_test.go
index dab5943..0b6a568 100644
--- a/E2Manager/managers/kubernetes_manager_test.go
+++ b/E2Manager/managers/kubernetes_manager_test.go
@@ -20,7 +20,7 @@
 
 package managers
 
-/*
+
 import (
 	"e2mgr/configuration"
 	"e2mgr/logger"
@@ -45,7 +45,7 @@
 		t.Errorf("#... - failed to initialize logger, error: %s", err)
 	}
 	config := &configuration.Configuration{}
-	config.Kubernetes.Namespace = "oran"
+	config.Kubernetes.KubeNamespace = "oran"
 	config.Kubernetes.ConfigPath = "somePath"
 
 	kubernetesManager := NewKubernetesManager(logger, config)
@@ -148,5 +148,4 @@
 			Annotations: map[string]string{},
 		},
 	}
-}
-*/
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/E2Manager/resources/configuration.yaml b/E2Manager/resources/configuration.yaml
index d79565b..88e276a 100644
--- a/E2Manager/resources/configuration.yaml
+++ b/E2Manager/resources/configuration.yaml
@@ -16,4 +16,7 @@
 e2tInstanceDeletionTimeoutMs: 15000
 globalRicId:
   plmnId: 131014
-  ricNearRtId: 556670
\ No newline at end of file
+  ricNearRtId: 556670
+kubernetes:
+  configPath: ./kube_config.yml
+  kubeNamespace: ricplt
\ No newline at end of file