Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ Versions and dates above this section are from upstream and are preserved
for historical context.

### Added
* `--release-source labels` on `nova find`: discovers installed Helm releases
from the `helm.sh/chart` / `chart` labels and `meta.helm.sh/release-*`
annotations on deployments, statefulsets, daemonsets, cronjobs, services and
configmaps, without reading Secrets. Releases whose objects carry more than
one chart label (umbrella charts) are skipped, and Artifact Hub matches are
limited to packages that published the installed version
(`pkg/helm/labels.go`, `pkg/helm/findscore.go`).
* `RepositoryUrl` field on `ReleaseOutput` exposing the source Helm repository
URL for matched releases (`pkg/output/output.go`).
* `Date` field on `VersionInfo` exposing the installed release's
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ For the original feature documentation see the
| Output | `ReleaseOutput` now includes the source Helm `RepositoryUrl` for matched releases. |
| Output | `VersionInfo` now includes a `Date` field — `FirstDeployed` for the installed version, `Created` for the latest version. |
| Discovery | New `pkg/helm/helm_repo_exporter.go` calls ArtifactHub's `/helm-exporter` API and (with `FindHelmRepoMatch` in `pkg/helm/findscore.go`) attaches the source repo URL to each release. Optional file cache via `ARTIFACT_HELM_REPO_HUB_CACHE_FILE`. |
| Discovery | `nova find --release-source labels` reads installed releases from the `helm.sh/chart` (or older `chart`) label and `meta.helm.sh/release-*` annotations on workloads, cronjobs, services and configmaps, so it needs no access to Secrets. It cannot see CRD-only charts or the parent of an umbrella chart (those releases are skipped), and it only matches Artifact Hub packages that published the installed version. The default, `--release-source secrets`, is unchanged. |
| CLI | Removed the upstream "Want more? Automate Nova for free with Fairwinds Insights!" message that was printed after every command. |
| Build | Multi-stage `Dockerfile` that builds `nova` from source instead of copying a pre-built binary. |
| CI | GitHub Actions workflows that build a multi-arch image and push to Nudgebee's container registry. |
Expand Down Expand Up @@ -65,6 +66,10 @@ nova find --containers

# Output JSON
nova find --format json

# Read releases from object labels instead of Helm's release Secrets
# (for service accounts that may not list Secrets)
nova find --release-source labels
```

Run `nova --help` for the full command surface.
Expand Down
10 changes: 10 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@ func init() {
klog.Exitf("Failed to bind chart-ignore-list flag: %v", err)
}

findCmd.Flags().String("release-source", nova_helm.ReleaseSourceSecrets, "Where to read installed Helm releases from: secrets (Helm's release Secrets; needs list on secrets) or labels (helm.sh/chart labels on workloads, services and configmaps; no Secrets access, but misses CRD-only and umbrella charts)")
err = viper.BindPFlag("release-source", findCmd.Flags().Lookup("release-source"))
if err != nil {
klog.Exitf("Failed to bind release-source flag: %v", err)
}

klog.InitFlags(nil)
_ = flag.Set("alsologtostderr", "true")
_ = flag.Set("logtostderr", "true")
Expand Down Expand Up @@ -361,6 +367,10 @@ func handleContainers(kubeContext, kubeConfigPath string) (*output.ContainersOut

func handleHelm(kubeContext, kubeConfigPath string) (*output.Output, error) {
h := nova_helm.NewHelm(kubeContext, kubeConfigPath)
h.ReleaseSource = viper.GetString("release-source")
if h.ReleaseSource != nova_helm.ReleaseSourceSecrets && h.ReleaseSource != nova_helm.ReleaseSourceLabels {
return nil, fmt.Errorf("--release-source must be %q or %q, got %q", nova_helm.ReleaseSourceSecrets, nova_helm.ReleaseSourceLabels, h.ReleaseSource)
}
if viper.IsSet("desired-versions") {
klog.V(3).Infof("desired-versions is set - attempting to load them")
klog.V(8).Infof("raw desired-versions: %v", viper.Get("desired-versions"))
Expand Down
10 changes: 10 additions & 0 deletions pkg/helm/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package helm

import (
"context"
"fmt"
"slices"

Expand All @@ -31,6 +32,8 @@ import (
type Helm struct {
Kube *kube.Connection
DesiredVersions []DesiredVersion
// ReleaseSource is ReleaseSourceSecrets (default) or ReleaseSourceLabels.
ReleaseSource string
}

// DesiredVersion is a specific desired version that overrides the latest from the repository
Expand Down Expand Up @@ -64,6 +67,13 @@ func (h *Helm) GetReleaseOutput(namespace string, releaseIgnoreList []string, ch

// GetHelmReleases returns a list of helm releases from the cluster
func (h *Helm) GetHelmReleases(namespace string, releaseIgnoreList []string, chartIgnoreList []string) ([]*release.Release, error) {
if h.ReleaseSource == ReleaseSourceLabels {
found, err := GetHelmReleasesFromLabels(context.Background(), h.Kube.Client, namespace)
if err != nil {
return nil, err
}
return filterIgnoredReleases(found, releaseIgnoreList, chartIgnoreList), nil
}
hs := helmdriver.NewSecrets(h.Kube.Client.CoreV1().Secrets(namespace))
helmClient := helmstorage.Init(hs)
deployed, err := helmClient.ListDeployed()
Expand Down
21 changes: 21 additions & 0 deletions pkg/helm/findscore.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,18 @@ func FindBestArtifactHubMatch(clusterRelease *release.Release, ahubPackages []Ar
packageScores := map[packageKey]float32{}
packageStars := map[packageKey]int{}
var useStars bool
fromLabels := clusterRelease.Labels[releaseSourceKey] == ReleaseSourceLabels
for _, p := range ahubPackages {
if p.Name != clusterRelease.Chart.Metadata.Name {
continue
}
// A release read from labels has no chart metadata (home, sources,
// maintainers) to score on, so a same-name chart from an unrelated
// repo would often win. Only consider packages that have published
// the installed version; if none has, report no match rather than guess.
if fromLabels && !packagePublishedVersion(clusterRelease.Chart.Metadata.Version, p) {
continue
}

key := packageKey{Name: p.Name, Repository: p.Repository.Name}
packageScores[key] = scoreChartSimilarity(clusterRelease, p)
Expand Down Expand Up @@ -196,6 +204,19 @@ func clusterVersionExistsInPackage(clusterVersion string, pkg ArtifactHubHelmPac
return false
}

// packagePublishedVersion reports whether pkg lists v among its versions,
// ignoring a leading "v" on either side (cert-manager labels "v1.13.1",
// Artifact Hub lists "1.13.1").
func packagePublishedVersion(v string, pkg ArtifactHubHelmPackage) bool {
want := strings.TrimPrefix(v, "v")
for _, packageVersion := range pkg.AvailableVersions {
if strings.TrimPrefix(packageVersion.Version, "v") == want {
return true
}
}
return false
}

func containsString(arr []string, val string) bool {
return slices.Contains(arr, val)
}
Expand Down
Loading
Loading