Skip to content

Commit

Permalink
wip: create database resources with collision-free names
Browse files Browse the repository at this point in the history
  • Loading branch information
kimtore committed May 28, 2024
1 parent d33e805 commit d4144f1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pkg/resourcecreator/google/sql/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@ package google_sql

import (
google_sql_crd "github.com/nais/liberator/pkg/apis/sql.cnrm.cloud.google.com/v1beta1"
"github.com/nais/liberator/pkg/namegen"
"github.com/nais/naiserator/pkg/resourcecreator/google"
"github.com/nais/naiserator/pkg/util"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/validation"
)

func GoogleSQLDatabase(objectMeta metav1.ObjectMeta, instanceName, dbName, projectId string, cascadingDelete bool) *google_sql_crd.SQLDatabase {
// Spec for CloudSqlDatabase states that Name is required
objectMeta.Name = dbName
var err error

objectMeta.Name, err = namegen.ShortName(objectMeta.GetName()+"-"+dbName, validation.DNS1035LabelMaxLength)
if err != nil {
panic(err) // never happens
}
util.SetAnnotation(&objectMeta, google.ProjectIdAnnotation, projectId)

// This is an annotation, but also a spec field.
Expand Down
1 change: 1 addition & 0 deletions pkg/resourcecreator/testdata/gcp_database.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ tests:
deletionPolicy: ABANDON
instanceRef:
name: myapplication
resourceID: mydb

- apiVersion: v1
kind: Secret
Expand Down

0 comments on commit d4144f1

Please sign in to comment.