func (g *InitGenerator) generate(ctx context.Context, dk *dynatracev1beta1.DynaKube) (map[string][]byte, error) {
	kubeSystemUID, err := kubesystem.GetUID(g.apiReader)
	if err != nil {
		return nil, err
	}
	infraMonitoringNodes, err := g.getInfraMonitoringNodes(dk)
	if err != nil {
		return nil, err
	}
	script, err := g.prepareScriptForDynaKube(dk, kubeSystemUID, infraMonitoringNodes)
	if err != nil {
		return nil, err
	}
	data, err := script.generate()
	if err != nil {
		return nil, err
	}
	return data, nil
}
generate gets the necessary info the create the init secret data
package initgeneration
import (
	"bytes"
	"context"
	_ "embed"
	"fmt"
	"strings"
	"text/template"
	dynatracev1beta1 "github.com/Dynatrace/dynatrace-operator/api/v1beta1"
	"github.com/Dynatrace/dynatrace-operator/controllers/kubeobjects"
	"github.com/Dynatrace/dynatrace-operator/controllers/kubesystem"
	"github.com/Dynatrace/dynatrace-operator/dtclient"
	"github.com/Dynatrace/dynatrace-operator/mapper"
	"github.com/Dynatrace/dynatrace-operator/webhook"
	"github.com/go-logr/logr"
	"github.com/pkg/errors"
	corev1 "k8s.io/api/core/v1"
	"k8s.io/apimachinery/pkg/labels"
	"k8s.io/apimachinery/pkg/types"
	"sigs.k8s.io/controller-runtime/pkg/client"
)
const (
	notMappedIM              = "-"
	trustedCASecretField     = "certs"
	proxyInitSecretField     = "proxy"
	trustedCAInitSecretField = "ca.pem"
	initScriptSecretField    = "init.sh"
)
var (
	scriptContent string
	scriptTmpl    = template.Must(template.New("initScript").Parse(scriptContent))
)
type InitGenerator struct {
	client        client.Client
	apiReader     client.Reader
	logger        logr.Logger
	namespace     string
	canWatchNodes bool
}
type nodeInfo struct {
	nodes   []corev1.Node
	imNodes map[string]string
}
type script struct {
	ApiUrl        string
	SkipCertCheck bool
	PaaSToken     string
	Proxy         string
	TrustedCAs    []byte
	ClusterID     string
	TenantUUID    string
	IMNodes       map[string]string
	HostGroup     string
	HasHost       bool
}
func NewInitGenerator(client client.Client, apiReader client.Reader, ns string, logger logr.Logger) *InitGenerator {
	return &InitGenerator{
		client:    client,
		apiReader: apiReader,
		namespace: ns,
		logger:    logger,
	}
}
func (g *InitGenerator) GenerateForNamespace(ctx context.Context, dk dynatracev1beta1.DynaKube, targetNs string) error {
	g.logger.Info("Reconciling namespace init secret for", "namespace", targetNs)
	g.canWatchNodes = false
	data, err := g.generate(ctx, &dk)
	if err != nil {
		return err
	}
	return kubeobjects.CreateOrUpdateSecretIfNotExists(g.client, g.apiReader, webhook.SecretConfigName, targetNs, data, corev1.SecretTypeOpaque, g.logger)
}
func (g *InitGenerator) GenerateForDynakube(ctx context.Context, dk *dynatracev1beta1.DynaKube) (bool, error) {
	g.logger.Info("Reconciling namespace init secret for", "dynakube", dk.Name)
	g.canWatchNodes = true
	data, err := g.generate(ctx, dk)
	if err != nil {
		return false, err
	}
	nsList, err := mapper.GetNamespacesForDynakube(ctx, g.apiReader, dk.Name)
	if err != nil {
		return false, err
	}
	for _, targetNs := range nsList {
		if err = kubeobjects.CreateOrUpdateSecretIfNotExists(g.client, g.apiReader, webhook.SecretConfigName, targetNs.Name, data, corev1.SecretTypeOpaque, g.logger); err != nil {
			return false, err
		}
	}
	g.logger.Info("Done updating init secrets")
	return true, nil
}