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
2 changes: 1 addition & 1 deletion deployment/chainloop/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ description: Chainloop is an open source software supply chain control plane, a

type: application
# Bump the patch (not minor, not major) version on each change in the Chart Source code
version: 1.489.0
version: 1.489.1
# Do not update appVersion, this is handled automatically by the release process
appVersion: v1.135.4

Expand Down
212 changes: 146 additions & 66 deletions deployment/chainloop/README.md

Large diffs are not rendered by default.

187 changes: 187 additions & 0 deletions deployment/chainloop/endpoints_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
// Copyright 2026 The Chainloop Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package chart_test

import (
"os"
"path/filepath"
"testing"

"github.com/stretchr/testify/require"
"gopkg.in/yaml.v3"
)

const (
notesResource = "ConfigMap/rendered-notes"
sharedEndpointsOptIn = "useLegacyGRPCEndpoints=false"
)

// renderWithNotes renders the chart and also NOTES.txt, which `helm template`
// skips. It copies the chart and wraps NOTES.txt in a ConfigMap template.
func renderWithNotes(t *testing.T, args []string) (map[string]chartResource, string) {
t.Helper()
dir := t.TempDir()
require.NoError(t, os.CopyFS(dir, os.DirFS(".")))
templates, err := os.OpenRoot(filepath.Join(dir, "templates"))
require.NoError(t, err)
defer templates.Close()

notes, err := templates.ReadFile("NOTES.txt")
require.NoError(t, err)
require.NoError(t, templates.Remove("NOTES.txt"))
tpl := `{{- define "test.notes" -}}` + string(notes) + `{{- end -}}`
require.NoError(t, templates.WriteFile("_test_notes.tpl", []byte(tpl), 0o600))
manifest := "apiVersion: v1\nkind: ConfigMap\nmetadata:\n name: rendered-notes\ndata:\n notes: |\n{{ include \"test.notes\" . | indent 4 }}\n"
require.NoError(t, templates.WriteFile("zz-test-notes.yaml", []byte(manifest), 0o600))

t.Chdir(dir)
resources := renderChart(t, args)
rendered, ok := resources[notesResource]
require.True(t, ok)
return resources, rendered.Data["notes"]
}

type controlplaneConfig struct {
CASServer struct {
GRPC struct {
Addr string `yaml:"addr"`
} `yaml:"grpc"`
} `yaml:"cas_server"`
}

// useLegacyGRPCEndpoints selects the endpoints that the clients use: the
// control plane connection to the CAS and the CLI configuration in NOTES.
// Only an explicit false selects the shared endpoints.
func TestUseLegacyGRPCEndpoints(t *testing.T) {
const (
legacyCASAddr = "test-chainloop-cas-api:80"
sharedCASAddr = "test-chainloop-cas:80"
)
sharedIngresses := []string{
helmSet, "controlplane.ingress.enabled=true", helmSet, "controlplane.ingress.tls=true",
helmSet, casIngressEnabled, helmSet, "cas.ingress.tls=true",
helmSet, "controlplane.ingressAPI.tls=true", helmSet, "cas.ingressAPI.tls=true",
}
for _, tc := range []struct {
name string
args []string
casAddr string
wantNotes []string
}{
{
name: "default uses the legacy endpoints",
args: sharedIngresses,
casAddr: legacyCASAddr,
wantNotes: []string{
"chainloop config save \\\n --control-plane api.cp.dev.local:443 \\\n --artifact-cas api.cas.dev.local:443",
},
},
{
name: "explicit true uses the legacy endpoints",
args: append([]string{helmSet, "useLegacyGRPCEndpoints=true"}, sharedIngresses...),
casAddr: legacyCASAddr,
wantNotes: []string{
"--control-plane api.cp.dev.local:443 \\\n --artifact-cas api.cas.dev.local:443",
},
},
{
// helm upgrade --reuse-values from an older chart leaves the key unset.
name: "unset key uses the legacy endpoints",
args: append([]string{helmSet, "useLegacyGRPCEndpoints=null"}, sharedIngresses...),
casAddr: legacyCASAddr,
wantNotes: []string{
"--control-plane api.cp.dev.local:443 \\\n --artifact-cas api.cas.dev.local:443",
},
},
{
name: "false uses the shared endpoints",
args: append([]string{helmSet, sharedEndpointsOptIn}, sharedIngresses...),
casAddr: sharedCASAddr,
wantNotes: []string{
"chainloop config save \\\n --control-plane cp.dev.local:443 \\\n --artifact-cas cas.dev.local:443",
},
},
{
name: "false as a string uses the shared endpoints",
args: append([]string{helmSetString, sharedEndpointsOptIn}, sharedIngresses...),
casAddr: sharedCASAddr,
wantNotes: []string{
"--control-plane cp.dev.local:443 \\\n --artifact-cas cas.dev.local:443",
},
},
{
name: "false without shared TLS keeps the CLI insecure",
args: []string{helmSet, sharedEndpointsOptIn, helmSet, "controlplane.ingress.enabled=true", helmSet, casIngressEnabled},
casAddr: sharedCASAddr,
wantNotes: []string{
"chainloop --insecure config save \\\n --control-plane cp.dev.local:80 \\\n --artifact-cas cas.dev.local:80",
},
},
{
name: "false without shared ingresses port-forwards the shared services",
args: []string{helmSet, sharedEndpointsOptIn},
casAddr: sharedCASAddr,
wantNotes: []string{
"svc/test-chainloop-controlplane 9000:80",
"svc/test-chainloop-cas 9001:80",
"--control-plane localhost:9000 \\\n --artifact-cas localhost:9001",
},
},
{
name: "false with NodePort uses the shared service node ports",
args: []string{
helmSet, sharedEndpointsOptIn,
helmSet, "controlplane.ingressAPI.enabled=false", helmSet, "cas.ingressAPI.enabled=false",
helmSet, "controlplane.service.type=NodePort", helmSetString, "controlplane.service.nodePorts.http=30800",
helmSet, "cas.service.type=NodePort", helmSetString, "cas.service.nodePorts.http=30801",
},
casAddr: sharedCASAddr,
wantNotes: []string{
"--control-plane localhost:30800 \\\n --artifact-cas localhost:30801",
},
},
{
name: "false with LoadBalancer reads the shared services",
args: []string{
helmSet, sharedEndpointsOptIn,
helmSet, "controlplane.ingressAPI.enabled=false", helmSet, "cas.ingressAPI.enabled=false",
helmSet, "controlplane.service.type=LoadBalancer", helmSet, "cas.service.type=LoadBalancer",
},
casAddr: sharedCASAddr,
wantNotes: []string{
"svc test-chainloop-controlplane -w",
"svc test-chainloop-cas -w",
"--control-plane $CP_HOST:$CP_PORT \\\n --artifact-cas $CAS_HOST:$CAS_PORT",
},
},
} {
t.Run(tc.name, func(t *testing.T) {
resources, notes := renderWithNotes(t, tc.args)
for _, want := range tc.wantNotes {
require.Contains(t, notes, want)
}

var cfg controlplaneConfig
require.NoError(t, yaml.Unmarshal([]byte(resources["ConfigMap/test-chainloop-controlplane"].Data["config.yaml"]), &cfg))
require.Equal(t, tc.casAddr, cfg.CASServer.GRPC.Addr)

// Both modes keep the legacy gRPC resources.
_, ok := resources["Service/test-chainloop-controlplane-api"]
require.True(t, ok)
_, ok = resources["Service/test-chainloop-cas-api"]
require.True(t, ok)
})
}
}
20 changes: 18 additions & 2 deletions deployment/chainloop/templates/NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,34 @@ APP VERSION: {{ .Chart.AppVersion }}
{{- $cpGrpcURL := include "chainloop.controlplane.external_grpc_url" . }}
{{- $casGrpcURL := include "chainloop.cas.external_grpc_url" . }}

{{- /* useLegacyGRPCEndpoints selects the deprecated gRPC-only endpoints (*-api) or the shared endpoints */ -}}
{{- $shared := eq (include "chainloop.sharedEndpoints.enabled" .) "true" }}

{{- $cpSvcType := .Values.controlplane.serviceAPI.type }}
{{- $cpSvcPort := .Values.controlplane.serviceAPI.ports.http }}
{{- $cpSvcName := printf "%s-api" (include "chainloop.controlplane.fullname" .) }}
{{- $cpIngress := .Values.controlplane.ingressAPI }}

{{- $casSvcType := .Values.cas.serviceAPI.type }}
{{- $casSvcPort := .Values.cas.serviceAPI.ports.http }}
{{- $casSvcName := printf "%s-api" (include "chainloop.cas.fullname" .) }}
{{- $casIngress := .Values.cas.ingressAPI }}

{{- if $shared }}
{{- $cpSvcType = .Values.controlplane.service.type }}
{{- $cpSvcPort = coalesce .Values.controlplane.service.port .Values.controlplane.service.ports.http }}
{{- $cpSvcName = include "chainloop.controlplane.fullname" . }}
{{- $cpIngress = .Values.controlplane.ingress }}
{{- $casSvcType = .Values.cas.service.type }}
{{- $casSvcPort = coalesce .Values.cas.service.port .Values.cas.service.ports.http }}
{{- $casSvcName = include "chainloop.cas.fullname" . }}
{{- $casIngress = .Values.cas.ingress }}
{{- end }}

{{- $namespace := include "common.names.namespace" . }}

{{- $cpHasTLS := or (and .Values.controlplane.ingressAPI.enabled .Values.controlplane.ingressAPI.tls) (ne (.Values.controlplane.tls.existingSecret | default "") "") }}
{{- $casHasTLS := or (and .Values.cas.ingressAPI.enabled .Values.cas.ingressAPI.tls) (ne (.Values.cas.tls.existingSecret | default "") "") }}
{{- $cpHasTLS := or (and $cpIngress.enabled $cpIngress.tls) (ne (.Values.controlplane.tls.existingSecret | default "") "") }}
{{- $casHasTLS := or (and $casIngress.enabled $casIngress.tls) (ne (.Values.cas.tls.existingSecret | default "") "") }}
{{- $insecure := not (and $cpHasTLS $casHasTLS) }}

{{- if and (ne $cpGrpcURL "") (ne $casGrpcURL "") }}
Expand Down
18 changes: 18 additions & 0 deletions deployment/chainloop/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -329,14 +329,27 @@ null
{{- end -}}
{{- end -}}

{{/*
"true" when the clients use the shared control plane and CAS endpoints.
Only an explicit false opts in: `helm upgrade --reuse-values` from an older chart leaves the key unset.
*/}}
{{- define "chainloop.sharedEndpoints.enabled" -}}
{{- ternary "true" "false" (eq (toString .Values.useLegacyGRPCEndpoints) "false") -}}
{{- end -}}

{{/*
External gRPC URL the controlplane API can be reached at
This endpoint is used by the CLI to connect via gRPC
It uses the shared endpoint when useLegacyGRPCEndpoints is false, else the deprecated gRPC-only endpoint
NOTE: Load balancer service type is not supported
*/}}
{{- define "chainloop.controlplane.external_grpc_url" -}}
{{- $service := .Values.controlplane.serviceAPI }}
{{- $ingress := .Values.controlplane.ingressAPI }}
{{- if eq (include "chainloop.sharedEndpoints.enabled" .) "true" }}
{{- $service = .Values.controlplane.service }}
{{- $ingress = .Values.controlplane.ingress }}
{{- end }}

{{- if (and $ingress $ingress.enabled $ingress.hostname) }}
{{- printf "%s:%s" $ingress.hostname (ternary "443" "80" $ingress.tls) }}
Expand Down Expand Up @@ -437,11 +450,16 @@ NOTE: Load balancer service type is not supported
{{/*
External gRPC URL the CAS API can be reached at
This endpoint is used by the CLI to connect via gRPC
It uses the shared endpoint when useLegacyGRPCEndpoints is false, else the deprecated gRPC-only endpoint
NOTE: Load balancer service type is not supported
*/}}
{{- define "chainloop.cas.external_grpc_url" -}}
{{- $service := .Values.cas.serviceAPI }}
{{- $ingress := .Values.cas.ingressAPI }}
{{- if eq (include "chainloop.sharedEndpoints.enabled" .) "true" }}
{{- $service = .Values.cas.service }}
{{- $ingress = .Values.cas.ingress }}
{{- end }}

{{- if (and $ingress $ingress.enabled $ingress.hostname) }}
{{- printf "%s:%s" $ingress.hostname (ternary "443" "80" $ingress.tls) }}
Expand Down
4 changes: 4 additions & 0 deletions deployment/chainloop/templates/controlplane/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ data:
{{- end }}
cas_server:
grpc:
{{- if eq (include "chainloop.sharedEndpoints.enabled" .) "true" }}
addr: {{ printf "%s:%d" (include "chainloop.cas.fullname" .) (coalesce .Values.cas.service.port .Values.cas.service.ports.http | int) }}
{{- else }}
addr: {{ printf "%s-api:%.0f" (include "chainloop.cas.fullname" .) .Values.cas.serviceAPI.ports.http }}
{{- end }}
insecure: {{ empty (include "controlplane.tls-secret-name" .) }}
download_url: {{ include "chainloop.cas.external_url" . }}/download
{{- if .Values.cas.defaultMaxEntrySize }}
Expand Down
12 changes: 8 additions & 4 deletions deployment/chainloop/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ global:
##
development: false

## @param useLegacyGRPCEndpoints Give the clients the deprecated gRPC-only control plane and CAS endpoints (`ingressAPI`, `serviceAPI`) instead of the shared endpoints (`ingress`, `service`). This applies to the control plane connection to the CAS and to the CLI configuration in the install notes (NOTES.txt). Set it to false to use the shared endpoints. A later release changes the default to false. The chart keeps the deprecated Services in both modes
##
useLegacyGRPCEndpoints: true

## @section Common parameters
##
## @param kubeVersion Override Kubernetes version
Expand Down Expand Up @@ -375,7 +379,7 @@ controlplane:
annotations: {}

serviceAPI:
## @param controlplane.serviceAPI.type Service type
## @param controlplane.serviceAPI.type Deprecated gRPC-only Service type. Use the shared `controlplane.service` and set `useLegacyGRPCEndpoints` to false
type: ClusterIP

## @param controlplane.serviceAPI.ports.http controlplane service HTTP port
Expand Down Expand Up @@ -540,7 +544,7 @@ controlplane:

## ref: http://kubernetes.io/docs/user-guide/ingress/
ingressAPI:
## @param controlplane.ingressAPI.enabled Enable ingress record generation for controlplane
## @param controlplane.ingressAPI.enabled Enable the deprecated gRPC-only ingress for controlplane. Use the shared `controlplane.ingress` and set `useLegacyGRPCEndpoints` to false
##
enabled: false
## @param controlplane.ingressAPI.pathType Ingress path type
Expand Down Expand Up @@ -1159,7 +1163,7 @@ cas:
annotations: {}

serviceAPI:
## @param cas.serviceAPI.type Service type
## @param cas.serviceAPI.type Deprecated gRPC-only Service type. Use the shared `cas.service` and set `useLegacyGRPCEndpoints` to false
type: ClusterIP

## @param cas.serviceAPI.ports.http cas service HTTP port
Expand Down Expand Up @@ -1338,7 +1342,7 @@ cas:

## ref: http://kubernetes.io/docs/user-guide/ingress/
ingressAPI:
## @param cas.ingressAPI.enabled Enable ingress record generation for controlplane
## @param cas.ingressAPI.enabled Enable the deprecated gRPC-only ingress for CAS. Use the shared `cas.ingress` and set `useLegacyGRPCEndpoints` to false
##
enabled: false
## @param cas.ingressAPI.pathType Ingress path type
Expand Down
Loading