Skip to content

Commit

Permalink
Adds Tekton Hub ownerRef for Hub components
Browse files Browse the repository at this point in the history
Currently, there is no ownerRef added for secrets and configMap
of db, api and ui

This patch adds an ownerRef of `TektonHub` when Hub instance is
created

Note: If the secrets of db and api are created by user then those
one's are not deleted

Signed-off-by: Puneet Punamiya [email protected]
  • Loading branch information
PuneetPunamiya authored and tekton-robot committed Jun 27, 2022
1 parent a3407f7 commit b86e2ef
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions pkg/reconciler/kubernetes/tektonhub/tektonhub.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ func (r *Reconciler) validateOrCreateDBSecrets(ctx context.Context, th *v1alpha1

dbSecret, err := r.getSecret(ctx, dbSecretName, namespace, dbKeys)
if err != nil {
newDbSecret := createDbSecret(dbSecretName, namespace, dbSecret)
newDbSecret := createDbSecret(dbSecretName, namespace, dbSecret, th)
if apierrors.IsNotFound(err) {
_, err = r.kubeClientSet.CoreV1().Secrets(namespace).Create(ctx, newDbSecret, metav1.CreateOptions{})
if err != nil {
Expand Down Expand Up @@ -496,6 +496,7 @@ func createUiConfigMap(name, namespace string, th *v1alpha1.TektonHub) *corev1.C
Labels: map[string]string{
"ui": "tektonhub-ui",
},
OwnerReferences: []metav1.OwnerReference{getOwnerRef(th)},
},
Data: map[string]string{
"API_URL": th.Status.ApiRouteUrl,
Expand Down Expand Up @@ -946,6 +947,7 @@ func createApiConfigMap(name, namespace string, th *v1alpha1.TektonHub) *corev1.
Labels: map[string]string{
"app": "api",
},
OwnerReferences: []metav1.OwnerReference{getOwnerRef(th)},
},
Data: map[string]string{
"CONFIG_FILE_URL": th.Spec.Api.HubConfigUrl,
Expand Down Expand Up @@ -987,14 +989,15 @@ func (r *Reconciler) getHubManifest(ctx context.Context, th *v1alpha1.TektonHub,
return manifest, nil
}

func createDbSecret(name, namespace string, existingSecret *corev1.Secret) *corev1.Secret {
func createDbSecret(name, namespace string, existingSecret *corev1.Secret, th *v1alpha1.TektonHub) *corev1.Secret {
s := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
Labels: map[string]string{
"app": "db",
},
OwnerReferences: []metav1.OwnerReference{getOwnerRef(th)},
},
Type: corev1.SecretTypeOpaque,
}
Expand Down Expand Up @@ -1028,6 +1031,11 @@ func createDbSecret(name, namespace string, existingSecret *corev1.Secret) *core
return s
}

// Get an ownerRef of TektonHub
func getOwnerRef(th *v1alpha1.TektonHub) metav1.OwnerReference {
return *metav1.NewControllerRef(th, th.GroupVersionKind())
}

func (r *Reconciler) targetNamespaceCheck(ctx context.Context, th *v1alpha1.TektonHub) error {
_, err := r.kubeClientSet.CoreV1().Namespaces().Get(ctx, namespace, metav1.GetOptions{})
if err != nil {
Expand Down

0 comments on commit b86e2ef

Please sign in to comment.