<p>I am creating a program that gets a list of all deployments from Kubernetes as a <code>*v1.DeploymentList</code>. I managed to do that and it works. Then I do some processing of this list and execute many actions afterwards. Now, I have a new requirement; need to also be able to pull just ONE deployment and apply the same logic to it. The problem is when I use get the deployment what I get is <code>*v1.Deployment</code> which of course is different from <code>*v1.DeploymentList</code> as this is a list. Now, this DeploymentList is not a slice, so I can NOT just use <code>append</code> and do not know how to convert/cast. As a &quot;pragmatic&quot; solution, what I am trying to do it to just convert that Deployment into DeploymentList and then apply the rest of my logic as just a deployment as changing everything else would imply a lot of burden at this point.</p>
<p>I have the following code:</p>
<pre><code>func listK8sDeployments(the_clientset *kubernetes.Clientset, mirrorDeploy *string) *v1.DeploymentList {
    if mirrorDeploy != nil {
        tmp_deployments, err := the_clientset.AppsV1().Deployments(apiv1.NamespaceDefault).Get(context.TODO(), *mirrorDeploy, metav1.GetOptions{})
        if err != nil {
            panic(err.Error())
        }
        // Here would need to convert the *v1.Deployment into *v1.DeploymentList a list to retun it according to my EXISTING logic. If I can do this, I do not need to change anything else on the program.
        // return the Deployment list with one single deployment inside and finish.
    }
    deployments_list, err := the_clientset.AppsV1().Deployments(apiv1.NamespaceDefault).List(context.TODO(), metav1.ListOptions{})
    if err != nil {
        panic(err.Error())
    }
    return deployments_list
}
</code></pre>
<p>It returns a <code>*v1.Deployment</code>, but I need this data as a list even if it <code>*v1.DeploymentList</code> I have tried to append, but the <code>*v1.DeploymentList</code> is not a slice, so I can not do it. Any ideas as to how to achieve this or should I change the way things are done? Please explain. FYI: I am new to Go and to programming k8s related things too.</p>

<p>when you look at the definition of v1.DeploymentList you can see where the Deployment is located:</p>
<pre><code>// DeploymentList is a list of Deployments.
type DeploymentList struct {
    metav1.TypeMeta `json:&quot;,inline&quot;`
    // Standard list metadata.
    // +optional
    metav1.ListMeta `json:&quot;metadata,omitempty&quot; protobuf:&quot;bytes,1,opt,name=metadata&quot;`

    // Items is the list of Deployments.
    Items []Deployment `json:&quot;items&quot; protobuf:&quot;bytes,2,rep,name=items&quot;`
}

</code></pre>
<p>then you can easily create a new instance of it with your value:</p>
<pre><code>func listK8sDeployments(the_clientset *kubernetes.Clientset, mirrorDeploy *string) *v1.DeploymentList {
    if *mirrorDeploy != &quot;&quot; {
        tmp_deployments, err := the_clientset.AppsV1().Deployments(apiv1.NamespaceDefault).Get(context.TODO(), *mirrorDeploy, metav1.GetOptions{})
        if err != nil {
            panic(err.Error())
        }
        // create a new list with your deployment and return it
        deployments_list := v1.DeploymentList{Items: []v1.Deployment{*tmp_deployments}}
        return &amp;deployments_list
    }
    deployments_list, err := the_clientset.AppsV1().Deployments(apiv1.NamespaceDefault).List(context.TODO(), metav1.ListOptions{})
    if err != nil {
        panic(err.Error())
    }
    return deployments_list
}
</code></pre>
