From 78370bb5edd66d9da2975b534580814653be1924 Mon Sep 17 00:00:00 2001 From: Tim Ramlot <42113979+inteon@users.noreply.github.com> Date: Mon, 26 Jan 2026 11:26:55 +0100 Subject: [PATCH 1/2] move OIDCDiscoveryData to api/ Signed-off-by: Tim Ramlot <42113979+inteon@users.noreply.github.com> --- api/datareading.go | 19 +++++++++++++++++-- pkg/datagatherer/oidc/oidc.go | 10 ++-------- pkg/datagatherer/oidc/oidc_test.go | 6 ++++-- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/api/datareading.go b/api/datareading.go index 0556dd63..3412c847 100644 --- a/api/datareading.go +++ b/api/datareading.go @@ -130,14 +130,14 @@ func (v *GatheredResource) UnmarshalJSON(data []byte) error { return nil } -// DynamicData is the DataReading.Data returned by the k8s.DataGathererDynamic +// DynamicData is the DataReading.Data returned by the k8sdynamic.DataGathererDynamic // gatherer type DynamicData struct { // Items is a list of GatheredResource Items []*GatheredResource `json:"items"` } -// DiscoveryData is the DataReading.Data returned by the k8s.ConfigDiscovery +// DiscoveryData is the DataReading.Data returned by the k8sdiscovery.DataGathererDiscovery // gatherer type DiscoveryData struct { // ClusterID is the unique ID of the Kubernetes cluster which this snapshot was taken from. @@ -149,3 +149,18 @@ type DiscoveryData struct { // See https://godoc.org/k8s.io/apimachinery/pkg/version#Info ServerVersion *version.Info `json:"server_version"` } + +// OIDCDiscoveryData is the DataReading.Data returned by the oidc.OIDCDiscovery +// gatherer +type OIDCDiscoveryData struct { + // OIDCConfig contains OIDC configuration data from the API server's + // `/.well-known/openid-configuration` endpoint + OIDCConfig map[string]any `json:"openid_configuration,omitempty"` + // OIDCConfigError contains any error encountered while fetching the OIDC configuration + OIDCConfigError string `json:"openid_configuration_error,omitempty"` + + // JWKS contains JWKS data from the API server's `/openid/v1/jwks` endpoint + JWKS map[string]any `json:"jwks,omitempty"` + // JWKSError contains any error encountered while fetching the JWKS + JWKSError string `json:"jwks_error,omitempty"` +} diff --git a/pkg/datagatherer/oidc/oidc.go b/pkg/datagatherer/oidc/oidc.go index 069c482a..9df3c370 100644 --- a/pkg/datagatherer/oidc/oidc.go +++ b/pkg/datagatherer/oidc/oidc.go @@ -7,6 +7,7 @@ import ( "k8s.io/client-go/rest" + "github.com/jetstack/preflight/api" "github.com/jetstack/preflight/pkg/datagatherer" "github.com/jetstack/preflight/pkg/kubeconfig" ) @@ -73,7 +74,7 @@ func (g *DataGathererOIDC) Fetch() (any, int, error) { return "" } - return OIDCDiscoveryData{ + return api.OIDCDiscoveryData{ OIDCConfig: oidcResponse, OIDCConfigError: errToString(oidcErr), JWKS: jwksResponse, @@ -81,13 +82,6 @@ func (g *DataGathererOIDC) Fetch() (any, int, error) { }, 1 /* we have 1 result, so return 1 as count */, nil } -type OIDCDiscoveryData struct { - OIDCConfig map[string]any `json:"openid_configuration,omitempty"` - OIDCConfigError string `json:"openid_configuration_error,omitempty"` - JWKS map[string]any `json:"jwks,omitempty"` - JWKSError string `json:"jwks_error,omitempty"` -} - func (g *DataGathererOIDC) fetchOIDCConfig(ctx context.Context) (map[string]any, error) { // Fetch the OIDC discovery document from the well-known endpoint. bytes, err := g.cl.Get().AbsPath("/.well-known/openid-configuration").Do(ctx).Raw() diff --git a/pkg/datagatherer/oidc/oidc_test.go b/pkg/datagatherer/oidc/oidc_test.go index a603ee8e..3c3f61f6 100644 --- a/pkg/datagatherer/oidc/oidc_test.go +++ b/pkg/datagatherer/oidc/oidc_test.go @@ -8,6 +8,8 @@ import ( "k8s.io/client-go/discovery" "k8s.io/client-go/rest" + + "github.com/jetstack/preflight/api" ) func makeRESTClient(t *testing.T, ts *httptest.Server) rest.Interface { @@ -55,7 +57,7 @@ func TestFetch_Success(t *testing.T) { t.Fatalf("expected count 1, got %d", count) } - res, ok := anyRes.(OIDCDiscoveryData) + res, ok := anyRes.(api.OIDCDiscoveryData) if !ok { t.Fatalf("unexpected result type: %T", anyRes) } @@ -99,7 +101,7 @@ func TestFetch_Errors(t *testing.T) { t.Fatalf("Fetch returned error: %v", err) } - res, ok := anyRes.(OIDCDiscoveryData) + res, ok := anyRes.(api.OIDCDiscoveryData) if !ok { t.Fatalf("unexpected result type: %T", anyRes) } From e114701601c49f47d24b6428b6ada5699991731a Mon Sep 17 00:00:00 2001 From: Tim Ramlot <42113979+inteon@users.noreply.github.com> Date: Mon, 26 Jan 2026 11:43:31 +0100 Subject: [PATCH 2/2] unbreak ark-test-e2e Signed-off-by: Tim Ramlot <42113979+inteon@users.noreply.github.com> --- deploy/charts/disco-agent/templates/configmap.yaml | 2 -- .../tests/__snapshot__/configmap_test.yaml.snap | 8 -------- 2 files changed, 10 deletions(-) diff --git a/deploy/charts/disco-agent/templates/configmap.yaml b/deploy/charts/disco-agent/templates/configmap.yaml index 4766e762..231a26cd 100644 --- a/deploy/charts/disco-agent/templates/configmap.yaml +++ b/deploy/charts/disco-agent/templates/configmap.yaml @@ -19,8 +19,6 @@ data: {{- . | toYaml | nindent 6 }} {{- end }} data-gatherers: - - kind: oidc - name: ark/oidc - kind: k8s-discovery name: ark/discovery - kind: k8s-dynamic diff --git a/deploy/charts/disco-agent/tests/__snapshot__/configmap_test.yaml.snap b/deploy/charts/disco-agent/tests/__snapshot__/configmap_test.yaml.snap index 89a88ed3..2c70df00 100644 --- a/deploy/charts/disco-agent/tests/__snapshot__/configmap_test.yaml.snap +++ b/deploy/charts/disco-agent/tests/__snapshot__/configmap_test.yaml.snap @@ -7,8 +7,6 @@ custom-cluster-description: cluster_description: "A cloud hosted Kubernetes cluster hosting production workloads.\n\nteam: team-1\nemail: team-1@example.com\npurpose: Production workloads\n" period: "12h0m0s" data-gatherers: - - kind: oidc - name: ark/oidc - kind: k8s-discovery name: ark/discovery - kind: k8s-dynamic @@ -116,8 +114,6 @@ custom-cluster-name: cluster_description: "" period: "12h0m0s" data-gatherers: - - kind: oidc - name: ark/oidc - kind: k8s-discovery name: ark/discovery - kind: k8s-dynamic @@ -225,8 +221,6 @@ custom-period: cluster_description: "" period: "1m" data-gatherers: - - kind: oidc - name: ark/oidc - kind: k8s-discovery name: ark/discovery - kind: k8s-dynamic @@ -334,8 +328,6 @@ defaults: cluster_description: "" period: "12h0m0s" data-gatherers: - - kind: oidc - name: ark/oidc - kind: k8s-discovery name: ark/discovery - kind: k8s-dynamic