func()

in pkg/cmd/podidentity/detect.go [97:128]


func (dc *detectCmd) prerun() error {
	dc.serializer = json.NewSerializerWithOptions(
		json.DefaultMetaFactory, scheme, scheme,
		json.SerializerOptions{
			Yaml:   true,
			Pretty: true,
			Strict: true,
		},
	)
	// TODO(aramase): this validation can be refactored to a common function as it's used in multiple places
	minTokenExpirationDuration := time.Duration(webhook.MinServiceAccountTokenExpiration) * time.Second
	maxTokenExpirationDuration := time.Duration(webhook.MaxServiceAccountTokenExpiration) * time.Second
	if dc.serviceAccountTokenExpiration < minTokenExpirationDuration {
		return errors.Errorf("--service-account-token-expiration must be greater than or equal to %s", minTokenExpirationDuration.String())
	}
	if dc.serviceAccountTokenExpiration > maxTokenExpirationDuration {
		return errors.Errorf("--service-account-token-expiration must be less than or equal to %s", maxTokenExpirationDuration.String())
	}

	var err error
	dc.kubeClient, err = kuberneteshelper.GetKubeClient()
	if err != nil {
		return errors.Wrap(err, "failed to get Kubernetes client")
	}

	// create output directory if it doesn't exist
	if _, err := os.Stat(dc.outputDir); os.IsNotExist(err) {
		return os.MkdirAll(dc.outputDir, 0755)
	}

	return nil
}