func extractEsInfo()

in internal/stackdiag.go [439:489]


func extractEsInfo(typ string, ns string, resourceInfo *resource.Info) (bool, string, error) {
	resourceName := resourceInfo.Name

	es, err := runtime.DefaultUnstructuredConverter.ToUnstructured(resourceInfo.Object)
	if err != nil {
		return false, "", err
	}

	var isTLS bool
	switch typ {
	case logstashJob:
		// Logstash API SSL is not yet configurable via spec.http.tls, try to read the config as a best-effort,
		// to change after https://github.com/elastic/cloud-on-k8s/issues/6971 is fixed.
		enabled, found, err := unstructured.NestedBool(es, "spec", "config", "api.ssl.enabled")
		if err != nil {
			return false, "", err
		}
		isTLS = found && enabled

	default:
		disabled, found, err := unstructured.NestedBool(es, "spec", "http", "tls", "selfSignedCertificate", "disabled")
		if err != nil {
			return false, "", err
		}
		isTLS = !(found && disabled)
	}

	var esName string
	switch typ {
	case elasticsearchJob:
		esName = resourceName
	case kibanaJob:
		name, found, err := unstructured.NestedString(es, "spec", "elasticsearchRef", "name")
		if err != nil {
			return false, "", err
		}
		if !found || name == "" {
			logger.Printf("Skipping %s/%s as elasticsearchRef is not defined", ns, resourceName)
			return false, "", nil
		}
		esName = name
	case logstashJob:
		// Logstash doesn't store its credentials in Elastiscearch,
		// api.auth.* settings not yet supported
		esName = ""
	default:
		panic("unknown type while extracting es info")
	}

	return isTLS, esName, nil
}