func (r *Resource) getControlplane() (types.Resource, error) {
	if r.Controlplane == nil {
		if r.State == nil || r.State.Controlplane == nil {
			return nil, fmt.Errorf("controlplane not configured and state not found")
		}
		r.Controlplane = &controlplane.Controlplane{
			Destroy: true,
		}
	}
	if r.State != nil {
		r.Controlplane.State = r.State.Controlplane
	}
	if r.State != nil && r.State.PKI != nil {
		r.Controlplane.PKI = r.State.PKI
	}
	return validateAndNew(r.Controlplane)
}
getControlplane returns controlplane resource, with state and PKI integration enabled.
package flexkube
import (
	"bufio"
	"bytes"
	"fmt"
	"io/fs"
	"io/ioutil"
	"os"
	"strings"
	"text/template"
	sprig "github.com/Masterminds/sprig/v3"
	"github.com/google/go-cmp/cmp"
	"sigs.k8s.io/yaml"
	"github.com/flexkube/libflexkube/internal/util"
	"github.com/flexkube/libflexkube/pkg/apiloadbalancer"
	"github.com/flexkube/libflexkube/pkg/container"
	"github.com/flexkube/libflexkube/pkg/container/resource"
	"github.com/flexkube/libflexkube/pkg/controlplane"
	"github.com/flexkube/libflexkube/pkg/etcd"
	"github.com/flexkube/libflexkube/pkg/kubelet"
	"github.com/flexkube/libflexkube/pkg/kubernetes/client"
	"github.com/flexkube/libflexkube/pkg/pki"
	"github.com/flexkube/libflexkube/pkg/types"
)
type Resource struct {
	Etcd *etcd.Cluster `json:"etcd,omitempty"`
	Controlplane *controlplane.Controlplane `json:"controlplane,omitempty"`
	PKI *pki.PKI `json:"pki,omitempty"`
	KubeletPools map[string]*kubelet.Pool `json:"kubeletPools,omitempty"`
	APILoadBalancerPools map[string]*apiloadbalancer.APILoadBalancers `json:"apiLoadBalancerPools,omitempty"`
	Containers map[string]*container.ContainersState `json:"containers,omitempty"`
	State *ResourceState `json:"state,omitempty"`
	Confirmed bool `json:"confirmed,omitempty"`
	Noop bool `json:"noop,omitempty"`
}
type ResourceState struct {
	Etcd *container.ContainersState `json:"etcd,omitempty"`
	Controlplane *container.ContainersState `json:"controlplane,omitempty"`
	KubeletPools map[string]*container.ContainersState `json:"kubeletPools,omitempty"`
	APILoadBalancerPools map[string]*container.ContainersState `json:"apiLoadBalancerPools,omitempty"`
	Containers map[string]*container.ContainersState `json:"containers,omitempty"`
	PKI *pki.PKI `json:"pki,omitempty"`
}
func (r *Resource) getEtcd() (types.Resource, error) {
	if r.Etcd == nil {
		if r.State == nil || r.State.Etcd == nil {
			return nil, fmt.Errorf("etcd management not enabled in the configuration and state not found")
		}
		r.Etcd = &etcd.Cluster{}
	}
	if r.State != nil && r.State.Etcd != nil {
		r.Etcd.State = *r.State.Etcd
	}
	if r.State != nil && r.State.PKI != nil {
		r.Etcd.PKI = r.State.PKI
	}
	return validateAndNew(r.Etcd)
}