Skip to content

Streaming issues when watching ConfigMaps in .allNamespaces #31

Closed
@MyIgel

Description

@MyIgel

When watching ConfigMaps by using .allNamespaces i see other events before the triggering one. This happens only in ConfigMaps in all namespaces, not in single namespaces or for example with deployments in all namespaces.

Tested on k8s v1.27.1
Package version 0.14.0

This is a script that i used to show the problem:

import Foundation
import SwiftkubeClient

@main
class KubeEvent {
    let kubeClient: KubernetesClient? = KubernetesClient()

    deinit {
        try? kubeClient?.syncShutdown()
    }

    static func main() {
        let m = KubeEvent()
        try? m.listen()

        RunLoop.main.run()
    }

    func listen() throws {

        /// Stream all deployments in all namespaces
        /// Works
        /*
        when running
        kubectl apply -f example-1.yml
        kubectl delete -f example-1.yml

        Deployments in all namespaces: ADDED test
        Deployments in all namespaces: MODIFIED test
        Deployments in all namespaces: MODIFIED test
        Deployments in all namespaces: MODIFIED test
        Deployments in all namespaces: MODIFIED test
        Deployments in all namespaces: DELETED test
        */
        Task {
            let task = try kubeClient!.appsV1.deployments.watch(in: .allNamespaces)
            for try await item in  task.start() {
                if let name = item.resource.name  {
                    print("Deployments in all namespaces: \(item.type.rawValue) \(name)")
                }
            }
        }

        /// Stream all configmaps in one namespace
        /// Works
        Task {
            let task = try kubeClient!.configMaps.watch(in: .default)
            for try await item in  task.start() {
                if let name = item.resource.name {
                    print("Configmaps in default namespace: \(item.type.rawValue) \(name)")
                }
            }
        }

        /// Stream all configmaps in all namespaces
        /// Has streaming issues
        /*
        when running
        kubectl apply -f example-2.yml
        kubectl delete -f example-2.yml

        Configmaps in default namespace: ADDED foo
        Configmaps in all namespaces: ADDED kube-proxy
        Configmaps in default namespace: DELETED foo
        Configmaps in all namespaces: ADDED kube-root-ca.crt
        */
        Task {
            let task = try kubeClient!.configMaps.watch(in: .allNamespaces)
            for try await item in  task.start() {
                if let name = item.resource.name  {
                    /// This shows the problem
                    print("Configmaps in all namespaces: \(item.type.rawValue) \(name)")
                }
            }
        }
    }
}

example-1.yml

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: test
spec:
  selector:
    matchLabels:
      app: test
  template:
    metadata:
      name: test
      labels:
        app: test
    spec:
      containers:
      - name: test
        image: nginx
        imagePullPolicy: IfNotPresent

example-2.yml

apiVersion: v1
kind: ConfigMap
metadata:
  name: foo
  namespace: test

It would be great to get some feedback if this is some problem with swiftkube or a implementation issue on my side.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions