Skip to content

Commit eede0c9

Browse files
committed
Checkpoint: deploying a postgres works. There is a small issue with the credentials in the terraformrc file.
Signed-off-by: ytimocin <[email protected]>
1 parent 63c6542 commit eede0c9

File tree

10 files changed

+587
-71
lines changed

10 files changed

+587
-71
lines changed
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
terraform {
2+
required_providers {
3+
kubernetes = {
4+
source = "hashicorp/kubernetes"
5+
version = ">= 2.0"
6+
}
7+
}
8+
}
9+
10+
variable "context" {
11+
description = "This variable contains Radius recipe context."
12+
type = any
13+
}
14+
15+
resource "kubernetes_namespace" "postgres" {
16+
metadata {
17+
# name = "postgres-${lower(element(split("/", var.context.resource.id), length(split("/", var.context.resource.id)) - 1))}"
18+
name = "postgres-recipe"
19+
}
20+
}
21+
22+
# Removed PVC - using emptyDir volume instead to avoid permission issues
23+
24+
resource "kubernetes_deployment" "postgres" {
25+
metadata {
26+
name = "postgres"
27+
namespace = kubernetes_namespace.postgres.metadata[0].name
28+
}
29+
30+
spec {
31+
replicas = 1
32+
33+
selector {
34+
match_labels = {
35+
app = "postgres"
36+
}
37+
}
38+
39+
template {
40+
metadata {
41+
labels = {
42+
app = "postgres"
43+
}
44+
}
45+
46+
spec {
47+
container {
48+
image = "ghcr.io/ytimocin/postgres:15-alpine"
49+
name = "postgres"
50+
image_pull_policy = "IfNotPresent"
51+
52+
env {
53+
name = "POSTGRES_DB"
54+
value = "mydb"
55+
}
56+
env {
57+
name = "POSTGRES_USER"
58+
value = "postgres"
59+
}
60+
env {
61+
name = "POSTGRES_PASSWORD"
62+
value = "mysecretpassword"
63+
}
64+
65+
port {
66+
container_port = 5432
67+
}
68+
69+
volume_mount {
70+
mount_path = "/var/lib/postgresql/data"
71+
name = "postgres-storage"
72+
}
73+
}
74+
75+
volume {
76+
name = "postgres-storage"
77+
empty_dir {}
78+
}
79+
}
80+
}
81+
}
82+
}
83+
84+
resource "kubernetes_service" "postgres" {
85+
metadata {
86+
name = "postgres"
87+
namespace = kubernetes_namespace.postgres.metadata[0].name
88+
}
89+
spec {
90+
selector = {
91+
app = "postgres"
92+
}
93+
port {
94+
port = 5432
95+
target_port = 5432
96+
}
97+
type = "ClusterIP"
98+
}
99+
}
100+
101+
output "result" {
102+
value = {
103+
values = {
104+
host = "${kubernetes_service.postgres.metadata[0].name}.${kubernetes_namespace.postgres.metadata[0].name}.svc.cluster.local"
105+
port = "5432"
106+
database = "mydb"
107+
username = "postgres"
108+
password = "mysecretpassword"
109+
}
110+
}
111+
}

pkg/recipes/configloader/environment.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,18 @@ func getRecipeDefinition(environment *v20231001preview.EnvironmentResource, reci
167167
switch c := found.(type) {
168168
case *v20231001preview.TerraformRecipeProperties:
169169
definition.TemplateVersion = *c.TemplateVersion
170+
// Extract TLS configuration
171+
if c.TLS != nil {
172+
definition.TLS = &recipes.TLSConfig{
173+
SkipVerify: c.TLS.SkipVerify != nil && *c.TLS.SkipVerify,
174+
}
175+
if c.TLS.CaCertificate != nil {
176+
definition.TLS.CACertificate = &recipes.SecretReference{
177+
Source: *c.TLS.CaCertificate.Source,
178+
Key: *c.TLS.CaCertificate.Key,
179+
}
180+
}
181+
}
170182
case *v20231001preview.BicepRecipeProperties:
171183
if c.PlainHTTP != nil {
172184
definition.PlainHTTP = *c.PlainHTTP

pkg/recipes/configloader/secrets.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
/*
22
Copyright 2023 The Radius Authors.
3+
34
Licensed under the Apache License, Version 2.0 (the "License");
45
you may not use this file except in compliance with the License.
56
You may obtain a copy of the License at
7+
68
http://www.apache.org/licenses/LICENSE-2.0
9+
710
Unless required by applicable law or agreed to in writing, software
811
distributed under the License is distributed on an "AS IS" BASIS,
912
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -16,6 +19,7 @@ package configloader
1619
import (
1720
"context"
1821
"fmt"
22+
"slices"
1923

2024
"github.com/Azure/azure-sdk-for-go/sdk/azcore/arm"
2125
aztoken "github.com/radius-project/radius/pkg/azure/tokencredentials"
@@ -110,10 +114,24 @@ func populateSecretData(secretStoreID string, secretKeysFilter []string, secrets
110114
for _, secretKey := range secretKeysFilter {
111115
secretDataValue, ok := secrets.Data[secretKey]
112116
if !ok {
117+
// Special handling for Git authentication: username is optional
118+
// If pat exists but username doesn't, that's acceptable for Git auth
119+
if secretKey == "username" && containsString(secretKeysFilter, "pat") {
120+
// Check if pat exists in the secret store
121+
if _, patExists := secrets.Data["pat"]; patExists {
122+
// Skip missing username - it's optional for Git authentication
123+
continue
124+
}
125+
}
113126
return recipes.SecretData{}, fmt.Errorf("a secret key was not found in secret store '%s'", secretStoreID)
114127
}
115128
secretData.Data[secretKey] = *secretDataValue.Value
116129
}
117130

118131
return secretData, nil
119132
}
133+
134+
// containsString checks if a string slice contains a specific string
135+
func containsString(slice []string, str string) bool {
136+
return slices.Contains(slice, str)
137+
}

0 commit comments

Comments
 (0)