kubernetes-sigs / cli-utils

This repo contains binaries that built from libraries in cli-runtime.
Apache License 2.0
155 stars 77 forks source link

Watch for client-go deployments #618

Closed scottillogical closed 6 months ago

scottillogical commented 1 year ago

I have some code that will wait that works fine with an unstructured deployment, but when I converted my code to use client-gos DeployApplyConfiguration object https://pkg.go.dev/k8s.io/client-go@v0.27.1/applyconfigurations/apps/v1#DeploymentApplyConfiguration, kstatus will not successfully watch that, even after converting to unstructured. Does anyone have any suggested workarounds?


        deployment := appapplyv1.DeploymentApplyConfiguration{} //
    content, _  := runtime.DefaultUnstructuredConverter.ToUnstructured(deployment)
    unstructuredContent:= unstructured.Unstructured{}
    unstructuredContent.SetUnstructuredContent(content)
    objs := object.UnstructuredSetToObjMetadataSet(object.UnstructuredSet{&unstructuredContent})

    wait := time.Duration(cheet.c.defaultDeploymentTimeoutS*cheetah.Instances) * time.Second
    logger.Log.Info().Dur("wait", wait).Str("namespace", cheet.namespace).Str("app", cheetah.Name).Msg("Waiting for deployment to be rolled out successfully")
    ctx, cancelFunc := context.WithTimeout(context.TODO(), wait)

    defer cancelFunc()
    eventCh := cheet.c.statusWatcher.Watch(ctx, objs, watcher.Options{})
    for e := range eventCh {
        if e.Error != nil {
            fmt.Println(e.Error)
            return e.Error
        }
        if e.Type == event.ErrorEvent {
            cancelFunc()
            return e.Error
        }
        if e.Resource != nil {
            if e.Resource.Status == "Current" {
                cancelFunc()
                logger.Log.Info().Str("namespace", cheet.namespace).Str("app", cheetah.Name).
                    Msg("Deployment finished successfully")
                return nil
            }
        }
    }
    if ctx.Err() == context.DeadlineExceeded {
        return fmt.Errorf("%s deployment timed out in %s", cheetah.Name, namespace)
    }
    <-ctx.Done()

    return ctx.Err()
scottillogical commented 1 year ago

It works fine when I do

    identifiers := []object.ObjMetadata{
        {
            GroupKind: schema.GroupKind{
                Group: "apps",
                Kind:  "Deployment",
            },
            Name:     deploymentName, 
            Namespace: namespace,
        },
    }
k8s-triage-robot commented 1 year ago

The Kubernetes project currently lacks enough contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

You can:

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

k8s-triage-robot commented 7 months ago

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

You can:

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

k8s-triage-robot commented 6 months ago

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues according to the following rules:

You can:

Please send feedback to sig-contributor-experience at kubernetes/community.

/close not-planned

k8s-ci-robot commented 6 months ago

@k8s-triage-robot: Closing this issue, marking it as "Not Planned".

In response to [this](https://github.com/kubernetes-sigs/cli-utils/issues/618#issuecomment-1951474594): >The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs. > >This bot triages issues according to the following rules: >- After 90d of inactivity, `lifecycle/stale` is applied >- After 30d of inactivity since `lifecycle/stale` was applied, `lifecycle/rotten` is applied >- After 30d of inactivity since `lifecycle/rotten` was applied, the issue is closed > >You can: >- Reopen this issue with `/reopen` >- Mark this issue as fresh with `/remove-lifecycle rotten` >- Offer to help out with [Issue Triage][1] > >Please send feedback to sig-contributor-experience at [kubernetes/community](https://github.com/kubernetes/community). > >/close not-planned > >[1]: https://www.kubernetes.dev/docs/guide/issue-triage/ Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.