Skip to content

Commit

Permalink
Merge pull request #19 from janlauber/enhance-tls
Browse files Browse the repository at this point in the history
feat: add custom tlsSecretName
  • Loading branch information
janlauber authored Mar 26, 2024
2 parents 8df39f7 + e28ac4c commit 43d9acc
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 13 deletions.
7 changes: 4 additions & 3 deletions api/v1alpha1/rollout_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,10 @@ type IngressSpec struct {
}

type IngressRule struct {
Host string `json:"host"`
Path string `json:"path"`
TLS bool `json:"tls"`
Host string `json:"host"`
Path string `json:"path"`
TLS bool `json:"tls"`
TlsSecretName string `json:"tlsSecretName,omitempty"`
}

// RolloutSpec defines the desired state of Rollout
Expand Down
2 changes: 2 additions & 0 deletions config/crd/bases/one-click.dev_rollouts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ spec:
type: string
tls:
type: boolean
tlsSecretName:
type: string
required:
- host
- path
Expand Down
3 changes: 2 additions & 1 deletion controllers/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ func (r *RolloutReconciler) reconcileDeployment(ctx context.Context, rollout *on

func (r *RolloutReconciler) deploymentForRollout(ctx context.Context, f *oneclickiov1alpha1.Rollout) *appsv1.Deployment {
log := log.FromContext(context.Background())
labels := map[string]string{"rollout.one-click.dev/name": f.Name}
// the name of the namespace is the project name
labels := map[string]string{"rollout.one-click.dev/name": f.Name, "project.one-click.dev/name": f.Namespace}
replicas := int32(f.Spec.HorizontalScale.MinReplicas)

dep := &appsv1.Deployment{
Expand Down
34 changes: 26 additions & 8 deletions controllers/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ func (r *RolloutReconciler) reconcileIngress(ctx context.Context, f *oneclickiov
}

func (r *RolloutReconciler) ingressForRollout(f *oneclickiov1alpha1.Rollout, intf oneclickiov1alpha1.InterfaceSpec) *networkingv1.Ingress {
labels := map[string]string{"rollout.one-click.dev/name": f.Name}
// the name of the namespace is the project name
labels := map[string]string{"rollout.one-click.dev/name": f.Name, "project.one-click.dev/name": f.Namespace}
ingress := &networkingv1.Ingress{
ObjectMeta: metav1.ObjectMeta{
Name: intf.Name + "-ingress", // Create a unique name for the Ingress
Expand Down Expand Up @@ -183,9 +184,18 @@ func (r *RolloutReconciler) ingressForRollout(f *oneclickiov1alpha1.Rollout, int

// Add TLS configuration if TLS is enabled for this ingress path
if rule.TLS {
tls := networkingv1.IngressTLS{
Hosts: []string{rule.Host},
SecretName: intf.Name + "-tls-secret", // Name of the TLS secret
var tls networkingv1.IngressTLS

// Add the TLS secret name if defined
if rule.TlsSecretName == "" {
tls = networkingv1.IngressTLS{
Hosts: []string{rule.Host},
SecretName: intf.Name + "-tls-secret", // Name of the TLS secret
}
} else {
tls = networkingv1.IngressTLS{
SecretName: rule.TlsSecretName,
}
}
ingress.Spec.TLS = append(ingress.Spec.TLS, tls)
}
Expand Down Expand Up @@ -235,11 +245,19 @@ func getIngressTLS(intf oneclickiov1alpha1.InterfaceSpec) []networkingv1.Ingress

// Loop over each rule defined in the ingress path
for _, rule := range intf.Ingress.Rules {
// Add TLS configuration if TLS is enabled for this ingress path
if rule.TLS {
tls := networkingv1.IngressTLS{
Hosts: []string{rule.Host},
SecretName: intf.Name + "-tls-secret", // Name of the TLS secret
var tls networkingv1.IngressTLS

// Add the TLS secret name if defined
if rule.TlsSecretName == "" {
tls = networkingv1.IngressTLS{
Hosts: []string{rule.Host},
SecretName: intf.Name + "-tls-secret", // Name of the TLS secret
}
} else {
tls = networkingv1.IngressTLS{
SecretName: rule.TlsSecretName,
}
}
tlsConfigs = append(tlsConfigs, tls)
}
Expand Down
2 changes: 1 addition & 1 deletion controllers/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func (r *RolloutReconciler) secretForRollout(f *oneclickiov1alpha1.Rollout) (*co
ObjectMeta: metav1.ObjectMeta{
Name: f.Name + "-secrets", // Naming the secret based on the Rollout name
Namespace: f.Namespace,
Labels: map[string]string{"rollout.one-click.dev/name": f.Name},
Labels: map[string]string{"rollout.one-click.dev/name": f.Name, "project.one-click.dev/name": f.Namespace},
},
StringData: secretData,
}
Expand Down
1 change: 1 addition & 0 deletions controllers/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ func (r *RolloutReconciler) serviceForRollout(f *oneclickiov1alpha1.Rollout, int
}
selectorLabels := map[string]string{
"rollout.one-click.dev/name": f.Name,
"project.one-click.dev/name": f.Namespace,
}
svc := &corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Expand Down
1 change: 1 addition & 0 deletions controllers/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ func allowsVolumeExpansion(sc *storagev1.StorageClass) bool {
func (r *RolloutReconciler) constructPVCForRollout(rollout *oneclickiov1alpha1.Rollout, volSpec oneclickiov1alpha1.VolumeSpec) *corev1.PersistentVolumeClaim {
labels := map[string]string{
"rollout.one-click.dev/name": rollout.Name,
"project.one-click.dev/name": rollout.Namespace,
}

pvc := &corev1.PersistentVolumeClaim{
Expand Down

0 comments on commit 43d9acc

Please sign in to comment.