Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: allenporter/flux-local
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 7.1.0
Choose a base ref
...
head repository: allenporter/flux-local
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 7.2.0
Choose a head ref
  • 3 commits
  • 10 files changed
  • 2 contributors

Commits on Mar 3, 2025

  1. Fix OCIRepository support in get cluster (#843)

    Fixes #842
    allenporter authored Mar 3, 2025

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    5995dd1 View commit details

Commits on Mar 4, 2025

  1. Detect more images from commonly used crds (#833)

    Detect more images from commonly used crds
    
    ---------
    
    Co-authored-by: Allen Porter <allen.porter@gmail.com>
    buroa and allenporter authored Mar 4, 2025
    Copy the full SHA
    52381a8 View commit details
  2. Update setup.cfg to 7.2.0

    allenporter authored Mar 4, 2025
    Copy the full SHA
    cb59c38 View commit details
27 changes: 22 additions & 5 deletions flux_local/image.py
Original file line number Diff line number Diff line change
@@ -18,22 +18,38 @@
"CronJob",
"Job",
"ReplicationController",
"EMQX", # apps.emqx.io/v2beta1
"Cluster", # postgresql.cnpg.io/v1
"CephCluster", # ceph.rook.io/v1
"Alertmanager", # monitoring.coreos.com/v1
"Prometheus", # monitoring.coreos.com/v1
"AutoscalingRunnerSet", # actions.github.com/v1alpha1
]

# Default image key for most object types.
IMAGE_KEY = "image"

# Override the default image key for some object types.
KINDS_IMAGE_KEY = {
"Cluster": "imageName"
}


def _extract_images(doc: dict[str, Any]) -> set[str]:
def _extract_images(kind: str, doc: dict[str, Any]) -> set[str]:
"""Extract the image from a Kubernetes object."""
images: set[str] = set({})
image_key = KINDS_IMAGE_KEY.get(kind) or IMAGE_KEY

for key, value in doc.items():
if key == IMAGE_KEY:
if key == image_key:
images.add(value)
elif isinstance(value, dict):
images.update(_extract_images(value))
images.update(_extract_images(kind, value))
elif isinstance(value, list):
for item in value:
if isinstance(item, dict):
images.update(_extract_images(item))
images.update(_extract_images(kind, item))

return images


@@ -56,7 +72,8 @@ def add_image(name: str, doc: dict[str, Any]) -> None:
Updates the image set with the images found in the document.
"""
images = _extract_images(doc)
kind: str = doc["kind"]
images = _extract_images(kind, doc)
if not images:
return
if name in self.images:
1 change: 1 addition & 0 deletions flux_local/tool/get.py
Original file line number Diff line number Diff line change
@@ -231,6 +231,7 @@ async def run( # type: ignore[no-untyped-def]
helm_content = ImageOutput()
helm_visitor = HelmVisitor()
query.helm_repo.visitor = helm_visitor.repo_visitor()
query.oci_repo.visitor = helm_visitor.repo_visitor()
query.helm_release.visitor = helm_visitor.release_visitor()

manifest = await git_repo.build_manifest(
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = flux-local
version = 7.1.0
version = 7.2.0
description = flux-local is a python library and set of tools for managing a flux gitops repository, with validation steps to help improve quality of commits, PRs, and general local testing.
long_description = file: README.md
long_description_content_type = text/markdown
9 changes: 9 additions & 0 deletions tests/test_image.py
Original file line number Diff line number Diff line change
@@ -24,6 +24,15 @@
CWD / "tests/testdata/cluster7",
{},
),
(
CWD / "tests/testdata/cluster",
{
"flux-system/infra-configs": {
"ceph/ceph:v16.2.6",
"ghcr.io/cloudnative-pg/postgis:17-3.4",
},
},
)
],
)
async def test_image_visitor(
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
apiVersion: ceph.rook.io/v1
kind: CephCluster
metadata:
name: rook-ceph
namespace: rook-ceph
spec:
cephVersion:
image: ceph/ceph:v16.2.6
18 changes: 18 additions & 0 deletions tests/testdata/cluster/infrastructure/configs/database.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
name: cluster-example
spec:
instances: 3
imageName: ghcr.io/cloudnative-pg/postgis:17-3.4
bootstrap:
initdb:
postInitTemplateSQL:
- CREATE EXTENSION postgis;
- CREATE EXTENSION postgis_topology;
- CREATE EXTENSION fuzzystrmatch;
- CREATE EXTENSION postgis_tiger_geocoder;

storage:
size: 1Gi
Original file line number Diff line number Diff line change
@@ -4,3 +4,5 @@ kind: Kustomization
resources:
- cluster-policies.yaml
- helm-repositories.yaml
- ceph-cluster.yaml
- database.yaml
114 changes: 114 additions & 0 deletions tests/tool/__snapshots__/test_build.ambr
Original file line number Diff line number Diff line change
@@ -3204,6 +3204,44 @@
interval: 120m
type: oci
url: oci://ghcr.io/weaveworks/charts
---
apiVersion: ceph.rook.io/v1
kind: CephCluster
metadata:
labels:
kustomize.toolkit.fluxcd.io/name: infra-configs
kustomize.toolkit.fluxcd.io/namespace: flux-system
name: rook-ceph
namespace: rook-ceph
annotations:
config.kubernetes.io/index: '4'
internal.config.kubernetes.io/index: '4'
spec:
cephVersion:
image: ceph/ceph:v16.2.6
---
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
labels:
kustomize.toolkit.fluxcd.io/name: infra-configs
kustomize.toolkit.fluxcd.io/namespace: flux-system
name: cluster-example
annotations:
config.kubernetes.io/index: '5'
internal.config.kubernetes.io/index: '5'
spec:
bootstrap:
initdb:
postInitTemplateSQL:
- CREATE EXTENSION postgis;
- CREATE EXTENSION postgis_topology;
- CREATE EXTENSION fuzzystrmatch;
- CREATE EXTENSION postgis_tiger_geocoder;
imageName: ghcr.io/cloudnative-pg/postgis:17-3.4
instances: 3
storage:
size: 1Gi

---
apiVersion: helm.toolkit.fluxcd.io/v2beta1
@@ -4993,6 +5031,44 @@
interval: 120m
type: oci
url: oci://ghcr.io/weaveworks/charts
---
apiVersion: ceph.rook.io/v1
kind: CephCluster
metadata:
labels:
kustomize.toolkit.fluxcd.io/name: infra-configs
kustomize.toolkit.fluxcd.io/namespace: flux-system
name: rook-ceph
namespace: rook-ceph
annotations:
config.kubernetes.io/index: '4'
internal.config.kubernetes.io/index: '4'
spec:
cephVersion:
image: ceph/ceph:v16.2.6
---
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
labels:
kustomize.toolkit.fluxcd.io/name: infra-configs
kustomize.toolkit.fluxcd.io/namespace: flux-system
name: cluster-example
annotations:
config.kubernetes.io/index: '5'
internal.config.kubernetes.io/index: '5'
spec:
bootstrap:
initdb:
postInitTemplateSQL:
- CREATE EXTENSION postgis;
- CREATE EXTENSION postgis_topology;
- CREATE EXTENSION fuzzystrmatch;
- CREATE EXTENSION postgis_tiger_geocoder;
imageName: ghcr.io/cloudnative-pg/postgis:17-3.4
instances: 3
storage:
size: 1Gi

---
apiVersion: helm.toolkit.fluxcd.io/v2beta1
@@ -7049,6 +7125,44 @@
interval: 120m
type: oci
url: oci://ghcr.io/weaveworks/charts
---
apiVersion: ceph.rook.io/v1
kind: CephCluster
metadata:
labels:
kustomize.toolkit.fluxcd.io/name: infra-configs
kustomize.toolkit.fluxcd.io/namespace: flux-system
name: rook-ceph
namespace: rook-ceph
annotations:
config.kubernetes.io/index: '4'
internal.config.kubernetes.io/index: '4'
spec:
cephVersion:
image: ceph/ceph:v16.2.6
---
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
labels:
kustomize.toolkit.fluxcd.io/name: infra-configs
kustomize.toolkit.fluxcd.io/namespace: flux-system
name: cluster-example
annotations:
config.kubernetes.io/index: '5'
internal.config.kubernetes.io/index: '5'
spec:
bootstrap:
initdb:
postInitTemplateSQL:
- CREATE EXTENSION postgis;
- CREATE EXTENSION postgis_topology;
- CREATE EXTENSION fuzzystrmatch;
- CREATE EXTENSION postgis_tiger_geocoder;
imageName: ghcr.io/cloudnative-pg/postgis:17-3.4
instances: 3
storage:
size: 1Gi

---
apiVersion: helm.toolkit.fluxcd.io/v2beta1
60 changes: 59 additions & 1 deletion tests/tool/__snapshots__/test_get_cluster.ambr
Original file line number Diff line number Diff line change
@@ -141,7 +141,11 @@
"oci_repos": [],
"helm_releases": [],
"config_maps": [],
"secrets": []
"secrets": [],
"images": [
"ceph/ceph:v16.2.6",
"ghcr.io/cloudnative-pg/postgis:17-3.4"
]
},
{
"name": "infra-controllers",
@@ -368,6 +372,9 @@
helm_releases: []
config_maps: []
secrets: []
images:
- ceph/ceph:v16.2.6
- ghcr.io/cloudnative-pg/postgis:17-3.4
- name: infra-controllers
namespace: flux-system
path: tests/testdata/cluster/infrastructure/controllers
@@ -651,3 +658,54 @@

'''
# ---
# name: test_get_cluster[yaml-cluster9-only-images-with-oci]
'''
---
clusters:
- path: tests/testdata/cluster9/clusters/dev
kustomizations:
- name: apps-stack
namespace: flux-system
path: tests/testdata/cluster9/apps
helm_repos: []
oci_repos:
- name: podinfo
namespace: default
url: oci://ghcr.io/stefanprodan/charts/podinfo
helm_releases:
- name: nginx
namespace: default
chart:
name: ./tests/testdata/cluster9/local-charts/nginx
repo_name: flux-system
repo_namespace: flux-system
repo_kind: GitRepository
images:
- nginx:1.16.0
- name: podinfo
namespace: default
chart:
name: podinfo
repo_name: podinfo
repo_namespace: default
repo_kind: OCIRepository
images:
- ghcr.io/stefanprodan/podinfo:6.7.1
config_maps: []
secrets: []
- name: flux-system
namespace: flux-system
path: tests/testdata/cluster9/clusters/dev
helm_repos: []
oci_repos: []
helm_releases: []
config_maps: []
secrets: []
images:
- ghcr.io/fluxcd/helm-controller:v0.37.4
- ghcr.io/fluxcd/kustomize-controller:v1.2.2
- ghcr.io/fluxcd/notification-controller:v1.2.4
- ghcr.io/fluxcd/source-controller:v1.2.4

'''
# ---
10 changes: 10 additions & 0 deletions tests/tool/test_get_cluster.py
Original file line number Diff line number Diff line change
@@ -50,6 +50,15 @@
"--only-images",
]
),
(
[
"--path",
"tests/testdata/cluster9/clusters/dev",
"--output",
"yaml",
"--enable-images",
]
),
(["--path", "tests/testdata/cluster", "-o", "json"]),
(["--path", "tests/testdata/cluster", "-o", "json", "--enable-images"]),
(
@@ -79,6 +88,7 @@
"yaml-cluster8-images",
"yaml-cluster8-images-allow-secrets",
"yaml-cluster8-only-images",
"yaml-cluster9-only-images-with-oci",
"json-cluster",
"json-cluster-images",
"json-cluster-only-images",