mirror of
https://github.com/fluxcd/flux2.git
synced 2026-02-07 16:27:27 +00:00
Add support for ExternalArtifact to flux trace
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
This commit is contained in:
parent
e56dfcacf2
commit
c3eadad983
1 changed files with 112 additions and 29 deletions
|
|
@ -223,6 +223,7 @@ func traceKustomization(ctx context.Context, kubeClient client.Client, ksName ty
|
||||||
|
|
||||||
var gitRepository *sourcev1.GitRepository
|
var gitRepository *sourcev1.GitRepository
|
||||||
var ociRepository *sourcev1.OCIRepository
|
var ociRepository *sourcev1.OCIRepository
|
||||||
|
var externalArtifact *sourcev1.ExternalArtifact
|
||||||
var ksRepositoryReady *metav1.Condition
|
var ksRepositoryReady *metav1.Condition
|
||||||
switch ks.Spec.SourceRef.Kind {
|
switch ks.Spec.SourceRef.Kind {
|
||||||
case sourcev1.GitRepositoryKind:
|
case sourcev1.GitRepositoryKind:
|
||||||
|
|
@ -253,6 +254,23 @@ func traceKustomization(ctx context.Context, kubeClient client.Client, ksName ty
|
||||||
return "", fmt.Errorf("failed to find OCIRepository: %w", err)
|
return "", fmt.Errorf("failed to find OCIRepository: %w", err)
|
||||||
}
|
}
|
||||||
ksRepositoryReady = meta.FindStatusCondition(ociRepository.Status.Conditions, fluxmeta.ReadyCondition)
|
ksRepositoryReady = meta.FindStatusCondition(ociRepository.Status.Conditions, fluxmeta.ReadyCondition)
|
||||||
|
case sourcev1.ExternalArtifactKind:
|
||||||
|
externalArtifact = &sourcev1.ExternalArtifact{}
|
||||||
|
sourceNamespace := ks.Namespace
|
||||||
|
if ks.Spec.SourceRef.Namespace != "" {
|
||||||
|
sourceNamespace = ks.Spec.SourceRef.Namespace
|
||||||
|
}
|
||||||
|
err = kubeClient.Get(ctx, types.NamespacedName{
|
||||||
|
Namespace: sourceNamespace,
|
||||||
|
Name: ks.Spec.SourceRef.Name,
|
||||||
|
}, externalArtifact)
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("failed to find ExternalArtifact: %w", err)
|
||||||
|
}
|
||||||
|
if externalArtifact.Spec.SourceRef == nil {
|
||||||
|
return "", fmt.Errorf("ExternalArtifact %s/%s is missing spec.sourceRef", externalArtifact.Namespace, externalArtifact.Name)
|
||||||
|
}
|
||||||
|
ksRepositoryReady = meta.FindStatusCondition(externalArtifact.Status.Conditions, fluxmeta.ReadyCondition)
|
||||||
}
|
}
|
||||||
|
|
||||||
var traceTmpl = `
|
var traceTmpl = `
|
||||||
|
|
@ -339,6 +357,31 @@ Message: {{.RepositoryReady.Message}}
|
||||||
Status: Unknown
|
Status: Unknown
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
{{- if .ExternalArtifact }}
|
||||||
|
---
|
||||||
|
ExternalArtifact:{{.ExternalArtifact.Name}}
|
||||||
|
Namespace: {{.ExternalArtifact.Namespace}}
|
||||||
|
Source: {{.ExternalArtifact.Spec.SourceRef.Kind}}/{{.ExternalArtifact.Spec.SourceRef.Namespace}}/{{.ExternalArtifact.Spec.SourceRef.Name}}
|
||||||
|
{{- if .ExternalArtifact.Status.Artifact }}
|
||||||
|
Revision: {{.ExternalArtifact.Status.Artifact.Revision}}
|
||||||
|
{{- if .ExternalArtifact.Status.Artifact.Metadata }}
|
||||||
|
{{- $metadata := .ExternalArtifact.Status.Artifact.Metadata }}
|
||||||
|
{{- range $k, $v := .Annotations }}
|
||||||
|
{{ with (index $metadata $v) }}{{ $k }}{{ . }}{{ end }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
|
{{- if .RepositoryReady }}
|
||||||
|
{{- if eq .RepositoryReady.Status "False" }}
|
||||||
|
Status: Last reconciliation failed at {{.RepositoryReady.LastTransitionTime}}
|
||||||
|
{{- else }}
|
||||||
|
Status: Last reconciled at {{.RepositoryReady.LastTransitionTime}}
|
||||||
|
{{- end }}
|
||||||
|
Message: {{.RepositoryReady.Message}}
|
||||||
|
{{- else }}
|
||||||
|
Status: Unknown
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
`
|
`
|
||||||
|
|
||||||
traceResult := struct {
|
traceResult := struct {
|
||||||
|
|
@ -348,6 +391,7 @@ Status: Unknown
|
||||||
KustomizationReady *metav1.Condition
|
KustomizationReady *metav1.Condition
|
||||||
GitRepository *sourcev1.GitRepository
|
GitRepository *sourcev1.GitRepository
|
||||||
OCIRepository *sourcev1.OCIRepository
|
OCIRepository *sourcev1.OCIRepository
|
||||||
|
ExternalArtifact *sourcev1.ExternalArtifact
|
||||||
RepositoryReady *metav1.Condition
|
RepositoryReady *metav1.Condition
|
||||||
Annotations map[string]string
|
Annotations map[string]string
|
||||||
}{
|
}{
|
||||||
|
|
@ -357,6 +401,7 @@ Status: Unknown
|
||||||
KustomizationReady: ksReady,
|
KustomizationReady: ksReady,
|
||||||
GitRepository: gitRepository,
|
GitRepository: gitRepository,
|
||||||
OCIRepository: ociRepository,
|
OCIRepository: ociRepository,
|
||||||
|
ExternalArtifact: externalArtifact,
|
||||||
RepositoryReady: ksRepositoryReady,
|
RepositoryReady: ksRepositoryReady,
|
||||||
Annotations: map[string]string{"Origin Source: ": oci.SourceAnnotation, "Origin Revision: ": oci.RevisionAnnotation},
|
Annotations: map[string]string{"Origin Source: ": oci.SourceAnnotation, "Origin Revision: ": oci.RevisionAnnotation},
|
||||||
}
|
}
|
||||||
|
|
@ -404,6 +449,8 @@ func traceHelm(ctx context.Context, kubeClient client.Client, hrName types.Names
|
||||||
var hrHelmRepositoryReady *metav1.Condition
|
var hrHelmRepositoryReady *metav1.Condition
|
||||||
var hrOCIRepository *sourcev1.OCIRepository
|
var hrOCIRepository *sourcev1.OCIRepository
|
||||||
var hrOCIRepositoryReady *metav1.Condition
|
var hrOCIRepositoryReady *metav1.Condition
|
||||||
|
var hrExternalArtifact *sourcev1.ExternalArtifact
|
||||||
|
var hrExternalArtifactReady *metav1.Condition
|
||||||
if hr.Spec.Chart == nil {
|
if hr.Spec.Chart == nil {
|
||||||
if hr.Spec.ChartRef != nil {
|
if hr.Spec.ChartRef != nil {
|
||||||
switch hr.Spec.ChartRef.Kind {
|
switch hr.Spec.ChartRef.Kind {
|
||||||
|
|
@ -421,11 +468,24 @@ func traceHelm(ctx context.Context, kubeClient client.Client, hrName types.Names
|
||||||
return "", fmt.Errorf("failed to find OCIRepository: %w", err)
|
return "", fmt.Errorf("failed to find OCIRepository: %w", err)
|
||||||
}
|
}
|
||||||
hrOCIRepositoryReady = meta.FindStatusCondition(hrOCIRepository.Status.Conditions, fluxmeta.ReadyCondition)
|
hrOCIRepositoryReady = meta.FindStatusCondition(hrOCIRepository.Status.Conditions, fluxmeta.ReadyCondition)
|
||||||
|
case sourcev1.ExternalArtifactKind:
|
||||||
|
hrExternalArtifact = &sourcev1.ExternalArtifact{}
|
||||||
|
sourceNamespace := hr.Namespace
|
||||||
|
if hr.Spec.ChartRef.Namespace != "" {
|
||||||
|
sourceNamespace = hr.Spec.ChartRef.Namespace
|
||||||
|
}
|
||||||
|
err = kubeClient.Get(ctx, types.NamespacedName{
|
||||||
|
Namespace: sourceNamespace,
|
||||||
|
Name: hr.Spec.ChartRef.Name,
|
||||||
|
}, hrExternalArtifact)
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("failed to find ExternalArtifact: %w", err)
|
||||||
|
}
|
||||||
|
if hrExternalArtifact.Spec.SourceRef == nil {
|
||||||
|
return "", fmt.Errorf("ExternalArtifact %s/%s is missing spec.sourceRef", hrExternalArtifact.Namespace, hrExternalArtifact.Name)
|
||||||
|
}
|
||||||
|
hrExternalArtifactReady = meta.FindStatusCondition(hrExternalArtifact.Status.Conditions, fluxmeta.ReadyCondition)
|
||||||
}
|
}
|
||||||
kubeClient.Get(ctx, types.NamespacedName{
|
|
||||||
Namespace: hr.Spec.ChartRef.Namespace,
|
|
||||||
Name: hr.Spec.ChartRef.Name,
|
|
||||||
}, hrOCIRepository)
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if hr.Spec.Chart.Spec.SourceRef.Kind == sourcev1.GitRepositoryKind {
|
if hr.Spec.Chart.Spec.SourceRef.Kind == sourcev1.GitRepositoryKind {
|
||||||
|
|
@ -569,35 +629,58 @@ Message: {{.OCIRepositoryReady.Message}}
|
||||||
Status: Unknown
|
Status: Unknown
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
{{- if .ExternalArtifact }}
|
||||||
|
---
|
||||||
|
ExternalArtifact:{{.ExternalArtifact.Name}}
|
||||||
|
Namespace: {{.ExternalArtifact.Namespace}}
|
||||||
|
Source: {{.ExternalArtifact.Spec.SourceRef.Kind}}/{{.ExternalArtifact.Spec.SourceRef.Namespace}}/{{.ExternalArtifact.Spec.SourceRef.Name}}
|
||||||
|
{{- if .ExternalArtifact.Status.Artifact }}
|
||||||
|
Revision: {{.ExternalArtifact.Status.Artifact.Revision}}
|
||||||
|
{{- end }}
|
||||||
|
{{- if .ExternalArtifactReady }}
|
||||||
|
{{- if eq .ExternalArtifactReady.Status "False" }}
|
||||||
|
Status: Last reconciliation failed at {{.ExternalArtifactReady.LastTransitionTime}}
|
||||||
|
{{- else }}
|
||||||
|
Status: Last reconciled at {{.ExternalArtifactReady.LastTransitionTime}}
|
||||||
|
{{- end }}
|
||||||
|
Message: {{.ExternalArtifactReady.Message}}
|
||||||
|
{{- else }}
|
||||||
|
Status: Unknown
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
`
|
`
|
||||||
|
|
||||||
traceResult := struct {
|
traceResult := struct {
|
||||||
ObjectName string
|
ObjectName string
|
||||||
ObjectNamespace string
|
ObjectNamespace string
|
||||||
HelmRelease *helmv2.HelmRelease
|
HelmRelease *helmv2.HelmRelease
|
||||||
HelmReleaseReady *metav1.Condition
|
HelmReleaseReady *metav1.Condition
|
||||||
HelmChart *sourcev1.HelmChart
|
HelmChart *sourcev1.HelmChart
|
||||||
HelmChartReady *metav1.Condition
|
HelmChartReady *metav1.Condition
|
||||||
GitRepository *sourcev1.GitRepository
|
GitRepository *sourcev1.GitRepository
|
||||||
GitRepositoryReady *metav1.Condition
|
GitRepositoryReady *metav1.Condition
|
||||||
HelmRepository *sourcev1.HelmRepository
|
HelmRepository *sourcev1.HelmRepository
|
||||||
HelmRepositoryReady *metav1.Condition
|
HelmRepositoryReady *metav1.Condition
|
||||||
OCIRepository *sourcev1.OCIRepository
|
OCIRepository *sourcev1.OCIRepository
|
||||||
OCIRepositoryReady *metav1.Condition
|
OCIRepositoryReady *metav1.Condition
|
||||||
Annotations map[string]string
|
ExternalArtifact *sourcev1.ExternalArtifact
|
||||||
|
ExternalArtifactReady *metav1.Condition
|
||||||
|
Annotations map[string]string
|
||||||
}{
|
}{
|
||||||
ObjectName: obj.GetKind() + "/" + obj.GetName(),
|
ObjectName: obj.GetKind() + "/" + obj.GetName(),
|
||||||
ObjectNamespace: obj.GetNamespace(),
|
ObjectNamespace: obj.GetNamespace(),
|
||||||
HelmRelease: hr,
|
HelmRelease: hr,
|
||||||
HelmReleaseReady: hrReady,
|
HelmReleaseReady: hrReady,
|
||||||
HelmChart: hrChart,
|
HelmChart: hrChart,
|
||||||
HelmChartReady: hrChartReady,
|
HelmChartReady: hrChartReady,
|
||||||
GitRepository: hrGitRepository,
|
GitRepository: hrGitRepository,
|
||||||
GitRepositoryReady: hrGitRepositoryReady,
|
GitRepositoryReady: hrGitRepositoryReady,
|
||||||
HelmRepository: hrHelmRepository,
|
HelmRepository: hrHelmRepository,
|
||||||
HelmRepositoryReady: hrHelmRepositoryReady,
|
HelmRepositoryReady: hrHelmRepositoryReady,
|
||||||
OCIRepository: hrOCIRepository,
|
OCIRepository: hrOCIRepository,
|
||||||
OCIRepositoryReady: hrOCIRepositoryReady,
|
OCIRepositoryReady: hrOCIRepositoryReady,
|
||||||
|
ExternalArtifact: hrExternalArtifact,
|
||||||
|
ExternalArtifactReady: hrExternalArtifactReady,
|
||||||
}
|
}
|
||||||
|
|
||||||
t, err := template.New("tmpl").Parse(traceTmpl)
|
t, err := template.New("tmpl").Parse(traceTmpl)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue