renoki-co / php-k8s

Unofficial PHP client for Kubernetes. It supports any form of authentication, the exec API, and it has an easy implementation for CRDs.
Apache License 2.0
307 stars 56 forks source link

watch() takes 60s to access object method and only runs once #283

Closed brucedevcom closed 1 year ago

brucedevcom commented 1 year ago

Hi!

I'm hoping to write an operator in laravel but I'm finding that the watch method isn't working as expected.

Taking the following quick test command:

    public function __construct()
    {
        parent::__construct();
        $this->cluster = K8s::getCluster();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    { 
        $start = time();
        $this->info('Getting name. Time: ' . $start);
        $this->info($this->cluster->pod()->whereName('speaker-nqd27')->whereNamespace('metallb-system')->getName());
        $this->info('Took: ' . time() - $start);

        $start = time();
        $this->info('Getting name in watch. Time: ' . $start);
        $this->cluster->pod()->whereName('speaker-nqd27')->whereNamespace('metallb-system')->watch(function ($type, $pod) use ($start) {
            $this->info($pod->getName());
            $this->info('Took: ' . time() - $start);
            $start = time();
        });

        $this->info('Loop done');
    }

I get the following output:

> php artisan test:watch
Getting name. Time: 1668994421
speaker-nqd27
Took: 0
Getting name in watch. Time: 1668994421
speaker-nqd27
Took: 60
Loop done

As you can see the watch function both takes 60s to access the name (and this is consistent every time) and only runs once, though it does take another 60s after the Took: 60 line is outputted for the Loop done line to be output.

This occurs both against a GKE cluster running 1.23 and a local k3s cluster running 1.25 using both the kubeconfig connection and a bearer token connection. It's also not just pods affected but other resources seem affected too.

stale[bot] commented 1 year ago

This issue has been automatically closed because it has not had any recent activity. 😨

brucedevcom commented 1 year ago

This is still an issue