Merge pull request 'fix: flatten generated runtime hosts' (#65) from feat/runtime-host-suffix into main
Reviewed-on: #65
This commit is contained in:
commit
2b3bb299b7
|
|
@ -167,7 +167,7 @@ spec:
|
|||
repository: $IMAGE
|
||||
tag: $TAG
|
||||
gateway:
|
||||
hostname: $APP_NAME-pr-$PR_NUMBER.{{ .ClusterDomain }}
|
||||
hostname: $APP_NAME-pr-$PR_NUMBER{{ .RuntimeHostnameSuffix }}
|
||||
EOF
|
||||
cat > "$app_dir/kustomization.yaml" <<EOF
|
||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||
|
|
|
|||
|
|
@ -618,21 +618,22 @@ func canonicalForgejoOrigin(value string) (string, error) {
|
|||
}
|
||||
|
||||
type appDeliveryTemplateConfig struct {
|
||||
AppName string
|
||||
AppRepository string
|
||||
AppRepoURL string
|
||||
AppRepoRef string
|
||||
ProductionBranch string
|
||||
ImageRepository string
|
||||
BuildStrategy string
|
||||
BuildOutputDirectory string
|
||||
BuildConfiguration string
|
||||
ForgejoBaseURL string
|
||||
ForgejoOwner string
|
||||
ManifestsURL string
|
||||
ManifestsRepo string
|
||||
ManifestsBranch string
|
||||
ClusterDomain string
|
||||
AppName string
|
||||
AppRepository string
|
||||
AppRepoURL string
|
||||
AppRepoRef string
|
||||
ProductionBranch string
|
||||
ImageRepository string
|
||||
BuildStrategy string
|
||||
BuildOutputDirectory string
|
||||
BuildConfiguration string
|
||||
ForgejoBaseURL string
|
||||
ForgejoOwner string
|
||||
ManifestsURL string
|
||||
ManifestsRepo string
|
||||
ManifestsBranch string
|
||||
ClusterDomain string
|
||||
RuntimeHostnameSuffix string
|
||||
}
|
||||
|
||||
var deliveryAppName = regexp.MustCompile(`^[a-z0-9]([a-z0-9-]{0,45}[a-z0-9])?$`)
|
||||
|
|
@ -656,9 +657,9 @@ func renderAppDelivery(cfg config.Config) ([]byte, error) {
|
|||
AppName: cfg.Delivery.AppName, AppRepository: appRepository, AppRepoURL: cfg.Delivery.AppRepoURL,
|
||||
AppRepoRef: cfg.Delivery.AppRepoRef, ProductionBranch: cfg.Delivery.ProductionBranch, ImageRepository: cfg.Delivery.ImageRepository,
|
||||
BuildStrategy: cfg.Delivery.BuildStrategy, BuildOutputDirectory: cfg.Delivery.BuildOutputDirectory, BuildConfiguration: cfg.Delivery.BuildConfiguration,
|
||||
ForgejoBaseURL: origin, ForgejoOwner: cfg.Git.Owner, ManifestsURL: forgejo.CloneURL(origin, cfg.Git.Owner, cfg.Flux.ManifestsRepo), ManifestsRepo: cfg.Flux.ManifestsRepo, ManifestsBranch: cfg.Flux.Branch, ClusterDomain: cfg.Flux.ClusterDomain,
|
||||
ForgejoBaseURL: origin, ForgejoOwner: cfg.Git.Owner, ManifestsURL: forgejo.CloneURL(origin, cfg.Git.Owner, cfg.Flux.ManifestsRepo), ManifestsRepo: cfg.Flux.ManifestsRepo, ManifestsBranch: cfg.Flux.Branch, ClusterDomain: cfg.Flux.ClusterDomain, RuntimeHostnameSuffix: deliveryRuntimeHostnameSuffix(cfg.Flux.ClusterDomain),
|
||||
}
|
||||
for name, value := range map[string]string{"appRepository": values.AppRepository, "appRepoUrl": values.AppRepoURL, "appRepoRef": values.AppRepoRef, "productionBranch": values.ProductionBranch, "imageRepository": values.ImageRepository, "buildOutputDirectory": values.BuildOutputDirectory, "buildConfiguration": values.BuildConfiguration, "forgejoBaseUrl": values.ForgejoBaseURL, "forgejoOwner": values.ForgejoOwner, "manifestsUrl": values.ManifestsURL, "manifestsRepo": values.ManifestsRepo, "manifestsBranch": values.ManifestsBranch, "clusterDomain": values.ClusterDomain} {
|
||||
for name, value := range map[string]string{"appRepository": values.AppRepository, "appRepoUrl": values.AppRepoURL, "appRepoRef": values.AppRepoRef, "productionBranch": values.ProductionBranch, "imageRepository": values.ImageRepository, "buildOutputDirectory": values.BuildOutputDirectory, "buildConfiguration": values.BuildConfiguration, "forgejoBaseUrl": values.ForgejoBaseURL, "forgejoOwner": values.ForgejoOwner, "manifestsUrl": values.ManifestsURL, "manifestsRepo": values.ManifestsRepo, "manifestsBranch": values.ManifestsBranch, "clusterDomain": values.ClusterDomain, "runtimeHostnameSuffix": values.RuntimeHostnameSuffix} {
|
||||
if value == "" || strings.ContainsAny(value, "\r\n") || config.RedactURL(value) != value {
|
||||
return nil, fmt.Errorf("delivery %s cannot be empty or contain credentials", name)
|
||||
}
|
||||
|
|
@ -674,6 +675,14 @@ func renderAppDelivery(cfg config.Config) ([]byte, error) {
|
|||
return bytes.ReplaceAll(rendered.Bytes(), []byte("\r\n"), []byte("\n")), nil
|
||||
}
|
||||
|
||||
func deliveryRuntimeHostnameSuffix(clusterDomain string) string {
|
||||
labels := strings.Split(clusterDomain, ".")
|
||||
if len(labels) < 3 {
|
||||
return "." + clusterDomain
|
||||
}
|
||||
return "-" + strings.Join(labels[:len(labels)-2], "-") + "." + strings.Join(labels[len(labels)-2:], ".")
|
||||
}
|
||||
|
||||
func deliveryRepository(baseURL, repositoryURL string) (string, error) {
|
||||
base, err := canonicalForgejoOrigin(baseURL)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -135,6 +135,17 @@ func TestGeneratedDeliveryUsesCombinedStaticBuildArtifactContract(t *testing.T)
|
|||
}
|
||||
}
|
||||
|
||||
func TestDeliveryRuntimeHostnameSuffix(t *testing.T) {
|
||||
for domain, want := range map[string]string{
|
||||
"example.test": ".example.test",
|
||||
"dev02.nid3.com": "-dev02.nid3.com",
|
||||
} {
|
||||
if got := deliveryRuntimeHostnameSuffix(domain); got != want {
|
||||
t.Fatalf("deliveryRuntimeHostnameSuffix(%q) = %q, want %q", domain, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestGeneratedDeliveryUsesRuntimeImageWithoutStaticParameters(t *testing.T) {
|
||||
cfg := config.Config{
|
||||
Git: config.GitConfig{BaseURL: "https://git.example.test", Owner: "platform"},
|
||||
|
|
|
|||
Loading…
Reference in a new issue