public function init()
    {
        $kubernetesClient = $this->controller->getKubernetesClient();
        $storeNamespace = $this->namespace;
        $storeName = $this->name;

        // check for ConfigMap existence
        $response = $kubernetesClient->request("/api/v1/namespaces/${storeNamespace}/configmaps/${storeName}");
        if ($response['status'] == 'Failure') {
            // create ConfigMap
            $data = [
                'kind' => 'ConfigMap',
                'metadata' => [
                    'name' => $storeName,
                ],
                'data' => null,
            ];

            // check for success
            $response = $kubernetesClient->request("/api/v1/namespaces/${storeNamespace}/configmaps", 'POST', [], $data);
            if ($response['status'] == 'Failure') {
                $this->log($response['message']);
                return;
            }
        }

        // load initial data
        if (!empty($response['data'])) {
            array_walk($response['data'], function (&$item, $key) {
                $item = json_decode($item, true);
            });
        }
        $this->data = $response['data'];

        // create watch
        $params = [
            'resourceVersion' => $response['metadata']['resourceVersion'],
        ];
        $watch = $kubernetesClient->createWatch("/api/v1/watch/namespaces/${storeNamespace}/configmaps/${storeName}", $params, $this->getConfigMapWatchCallback());
        $this->addWatch($watch);

        $this->initialized = true;
        $this->controller->log('store successfully initialized');
    }
public function init()
    {
        $kubernetesClient = $this->controller->getKubernetesClient();
        $storeNamespace = $this->namespace;
        $storeName = $this->name;

        // check for ConfigMap existence
        $response = $kubernetesClient->request("/api/v1/namespaces/${storeNamespace}/configmaps/${storeName}");
        if ($response['status'] == 'Failure') {
            // create ConfigMap
            $data = [
                'kind' => 'ConfigMap',
                'metadata' => [
                    'name' => $storeName,
                ],
                'data' => null,
            ];

            // check for success
            $response = $kubernetesClient->request("/api/v1/namespaces/${storeNamespace}/configmaps", 'POST', [], $data);
            if ($response['status'] == 'Failure') {
                $this->log($response['message']);
                return;
            }
        }

        // load initial data
        if (!empty($response['data'])) {
            array_walk($response['data'], function (&$item, $key) {
                $item = json_decode($item, true);
            });
        }
        $this->data = $response['data'];

        // create watch
        $params = [
            'resourceVersion' => $response['metadata']['resourceVersion'],
        ];
        $watch = $kubernetesClient->createWatch("/api/v1/watch/namespaces/${storeNamespace}/configmaps/${storeName}", $params, $this->getConfigMapWatchCallback());
        $this->addWatch($watch);

        $this->initialized = true;
        $this->controller->log('store successfully initialized');
    }
public function init ( ) { $ kubernetesClient = $ this -> controller -> getKubernetesClient ( ) ; $ storeNamespace = $ this -> namespace ; $ storeName = $ this -> name ; // check for ConfigMap existence $ response = $ kubernetesClient -> request ( "/api/v1/namespaces/${storeNamespace}/configmaps/${storeName}" ) ; if ( $ response [ 'status' ] == 'Failure' ) { // create ConfigMap $ data = [ 'kind' => 'ConfigMap' , 'metadata' => [ 'name' => $ storeName , ] , 'data' => null , ] ; // check for success $ response = $ kubernetesClient -> request ( "/api/v1/namespaces/${storeNamespace}/configmaps" , 'POST' , [ ] , $ data ) ; if ( $ response [ 'status' ] == 'Failure' ) { $ this -> log ( $ response [ 'message' ] ) ; return ; } } // load initial data if ( ! empty ( $ response [ 'data' ] ) ) { array_walk ( $ response [ 'data' ] , function ( & $ item , $ key ) { $ item = json_decode ( $ item , true ) ; } ) ; } $ this -> data = $ response [ 'data' ] ; // create watch $ params = [ 'resourceVersion' => $ response [ 'metadata' ] [ 'resourceVersion' ] , ] ; $ watch = $ kubernetesClient -> createWatch ( "/api/v1/watch/namespaces/${storeNamespace}/configmaps/${storeName}" , $ params , $ this -> getConfigMapWatchCallback ( ) ) ; $ this -> addWatch ( $ watch ) ; $ this -> initialized = true ; $ this -> controller -> log ( 'store successfully initialized' ) ; }
Initialize the store
Initialize the store