func isBootstrapApp(labels map[string]string) bool {
	k8sApp := labels[k8sAppLabel]
	if k8sApp == "" {
		k8sApp = labels[componentAppLabel]
	}
	_, ok := bootstrapK8sApps[k8sApp]
	return ok
}
isBootstrapApp returns true if this app belongs to the bootstrap control plane, based on its
labels.
package recovery
import (
	"context"
	"fmt"
	"io/ioutil"
	"path"
	"path/filepath"
	"reflect"
	"github.com/ghodss/yaml"
	"github.com/kubernetes-sigs/bootkube/cmd/render/plugin/default/asset"
	v1apps "k8s.io/api/apps/v1"
	v1 "k8s.io/api/core/v1"
	"k8s.io/apimachinery/pkg/api/meta"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"k8s.io/apimachinery/pkg/runtime"
	"k8s.io/apimachinery/pkg/runtime/schema"
)
const (
	k8sAppLabel            = "k8s-app"    
	componentAppLabel      = "component"  
	kubeletKubeConfigPath  = "/etc/kubernetes"
	apiServerContainerName = "kube-apiserver"
)
var (
	bootstrapK8sApps = map[string]struct{}{
		apiServerContainerName:    {},
		"kube-controller-manager": {},
		"kube-scheduler":          {},
	}
	kubeConfigK8sContainers = map[string]struct{}{
		"kube-controller-manager": {},
		"kube-scheduler":          {},
	}
	typeMetas    = make(map[reflect.Type]metav1.TypeMeta)
	metaAccessor = meta.NewAccessor()
)
func init() {
	addTypeMeta := func(obj runtime.Object, gv schema.GroupVersion) {
		t := reflect.TypeOf(obj)
		typeMetas[t] = metav1.TypeMeta{
			APIVersion: gv.String(),
			Kind:       t.Elem().Name(),
		}
	}
	addTypeMeta(&v1.ConfigMap{}, v1.SchemeGroupVersion)
	addTypeMeta(&v1apps.DaemonSet{}, v1apps.SchemeGroupVersion)
	addTypeMeta(&v1apps.Deployment{}, v1apps.SchemeGroupVersion)
	addTypeMeta(&v1.Pod{}, v1.SchemeGroupVersion)
	addTypeMeta(&v1.Secret{}, v1.SchemeGroupVersion)
}
type Backend interface {
	read(context.Context) (*controlPlane, error)
}
type controlPlane struct {
	configMaps  v1.ConfigMapList
	daemonSets  v1apps.DaemonSetList
	deployments v1apps.DeploymentList
	secrets     v1.SecretList
}
func Recover(ctx context.Context, backend Backend, kubeConfigPath string) (asset.Assets, error) {
	cp, err := backend.read(ctx)
	if err != nil {
		return nil, err
	}
	as, err := cp.renderBootstrap()
	if err != nil {
		return nil, err
	}
	kc, err := renderKubeConfig(kubeConfigPath)
	if err != nil {
		return nil, err
	}
	as = append(as, kc)
	return as, nil
}
func (cp *controlPlane) renderBootstrap() (asset.Assets, error) {
	pods, err := extractBootstrapPods(cp.daemonSets.Items, cp.deployments.Items)
	if err != nil {
		return nil, err
	}
	requiredConfigMaps, requiredSecrets := fixUpBootstrapPods(pods)
	as, err := outputBootstrapPods(pods)
	if err != nil {
		return nil, err
	}
	configMaps, err := outputBootstrapConfigMaps(cp.configMaps, requiredConfigMaps)
	if err != nil {
		return nil, err
	}
	as = append(as, configMaps...)
	secrets, err := outputBootstrapSecrets(cp.secrets, requiredSecrets)
	if err != nil {
		return nil, err
	}
	as = append(as, secrets...)
	return as, nil
}
func extractBootstrapPods(daemonSets []v1apps.DaemonSet, deployments []v1apps.Deployment) ([]v1.Pod, error) {
	var pods []v1.Pod
	for _, ds := range daemonSets {
		if isBootstrapApp(ds.Labels) {
			pod := v1.Pod{Spec: ds.Spec.Template.Spec}
			if err := setBootstrapPodMetadata(&pod, ds.ObjectMeta); err != nil {
				return nil, err
			}
			pods = append(pods, pod)
		}
	}
	for _, ds := range deployments {
		if isBootstrapApp(ds.Labels) {
			pod := v1.Pod{Spec: ds.Spec.Template.Spec}
			if err := setBootstrapPodMetadata(&pod, ds.ObjectMeta); err != nil {
				return nil, err
			}
			pods = append(pods, pod)
		}
	}
	return pods, nil
}