func (r *Resource) getAPILoadBalancerPool(name string) (types.Resource, error) {
	stateFound := r.State != nil && r.State.APILoadBalancerPools != nil && r.State.APILoadBalancerPools[name] != nil
	configPool, configFound := r.APILoadBalancerPools[name]
	if !stateFound && !configFound {
		return nil, fmt.Errorf("pool not configured and state not found")
	}
	pool := &apiloadbalancer.APILoadBalancers{}
	if configFound {
		pool = configPool
	}
	if stateFound {
		pool.State = *r.State.APILoadBalancerPools[name]
	}
	return validateAndNew(pool)
}
getAPILoadBalancerPool returns requested kubelet pool with state injected.
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)
}
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)
}
func (r *Resource) getKubeletPool(name string) (types.Resource, error) {
	stateFound := r.State != nil && r.State.KubeletPools != nil && r.State.KubeletPools[name] != nil
	configPool, configFound := r.KubeletPools[name]
	if !stateFound && !configFound {
		return nil, fmt.Errorf("pool not configured and state not found")
	}
	pool := &kubelet.Pool{}
	if configFound {
		pool = configPool
	}
	if stateFound {
		pool.State = *r.State.KubeletPools[name]
	}
	if r.State != nil && r.State.PKI != nil {
		pool.PKI = r.State.PKI
	}
	return validateAndNew(pool)
}
func (r *Resource) getPKI() (*pki.PKI, error) {
	if r.PKI == nil {
		return nil, fmt.Errorf("PKI config configured")
	}
	pki := &pki.PKI{}
	if r.State != nil && r.State.PKI != nil {
		fmt.Println("Loading existing PKI state from state.yaml file")
		pki = r.State.PKI
	}
	pkic, err := yaml.Marshal(r.PKI)
	if err != nil {
		return nil, fmt.Errorf("serializing PKI configuration: %w", err)
	}
	if err := yaml.Unmarshal(pkic, pki); err != nil {
		return nil, fmt.Errorf("merging PKI configuration with state: %w", err)
	}
	return pki, nil
}