Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions pkg/reconciler/kubernetes/tektonhub/tektonhub.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,19 +139,19 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, th *v1alpha1.TektonHub)

// Manage DB
if err := r.manageDbComponent(ctx, th, hubDir, version); err != nil {
return err
return r.handleError(err, th)
}
th.Status.MarkDbInstallerSetAvailable()

// Manage DB migration
if err := r.manageDbMigrationComponent(ctx, th, hubDir, version); err != nil {
return err
return r.handleError(err, th)
}
th.Status.MarkDatabasebMigrationDone()

// Manage API
if err := r.manageApiComponent(ctx, th, hubDir, version); err != nil {
return err
return r.handleError(err, th)
}
th.Status.MarkApiInstallerSetAvailable()

Expand All @@ -164,6 +164,14 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, th *v1alpha1.TektonHub)
return nil
}

func (r *Reconciler) handleError(err error, th *v1alpha1.TektonHub) error {
if err == v1alpha1.RECONCILE_AGAIN_ERR {
r.enqueueAfter(th, 10*time.Second)
return nil
}
return err
}

func (r *Reconciler) manageApiComponent(ctx context.Context, th *v1alpha1.TektonHub, hubDir, version string) error {
// Validate whether the secrets and configmap are created for API
if err := r.validateApiDependencies(ctx, th); err != nil {
Expand Down Expand Up @@ -191,8 +199,7 @@ func (r *Reconciler) manageApiComponent(ctx context.Context, th *v1alpha1.Tekton
err = r.checkComponentStatus(ctx, th, apiInstallerSet)
if err != nil {
th.Status.MarkApiInstallerSetNotAvailable(err.Error())
r.enqueueAfter(th, 10*time.Second)
return err
return v1alpha1.RECONCILE_AGAIN_ERR
}
return nil
}
Expand All @@ -216,8 +223,7 @@ func (r *Reconciler) manageDbMigrationComponent(ctx context.Context, th *v1alpha
err = r.checkComponentStatus(ctx, th, dbMigrationInstallerSet)
if err != nil {
th.Status.MarkDatabasebMigrationFailed(err.Error())
r.enqueueAfter(th, 10*time.Second)
return err
return v1alpha1.RECONCILE_AGAIN_ERR
}
return nil
}
Expand Down Expand Up @@ -247,8 +253,7 @@ func (r *Reconciler) manageDbComponent(ctx context.Context, th *v1alpha1.TektonH
err = r.checkComponentStatus(ctx, th, dbInstallerSet)
if err != nil {
th.Status.MarkDbInstallerSetNotAvailable(err.Error())
r.enqueueAfter(th, 10*time.Second)
return err
return v1alpha1.RECONCILE_AGAIN_ERR
}

return nil
Expand Down
7 changes: 6 additions & 1 deletion pkg/reconciler/kubernetes/tektoninstallerset/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package tektoninstallerset

import (
"context"
"fmt"
"strings"

Expand All @@ -30,6 +31,7 @@ import (
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/kubernetes/scheme"
"knative.dev/pkg/logging"
"knative.dev/pkg/ptr"
)

Expand Down Expand Up @@ -354,7 +356,7 @@ func (i *installer) AllDeploymentsReady() error {
return nil
}

func (i *installer) IsJobCompleted() error {
func (i *installer) IsJobCompleted(ctx context.Context, labels map[string]string, installSetName string) error {
for _, u := range i.Manifest.Filter(jobPred).Resources() {
resource, err := i.Manifest.Client.Get(&u)
if err != nil {
Expand All @@ -364,7 +366,10 @@ func (i *installer) IsJobCompleted() error {
if err := scheme.Scheme.Convert(resource, job, nil); err != nil {
return err
}

logger := logging.FromContext(ctx)
if !isJobCompleted(job) {
logger.Info("job not ready in installerset, name: %s, created-by: %s, in namespace: %s", installSetName, labels[v1alpha1.CreatedByKey], job.GetNamespace())
return fmt.Errorf("Job not successful")
}
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/reconciler/kubernetes/tektoninstallerset/install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package tektoninstallerset

import (
"context"
"fmt"
"testing"

Expand Down Expand Up @@ -416,7 +417,7 @@ func TestJobCompleted(t *testing.T) {
Manifest: manifest,
}

err = i.IsJobCompleted()
err = i.IsJobCompleted(context.Background(), nil, "")
if err != nil {
t.Fatal("Unexpected Error: ", err)
}
Expand All @@ -435,7 +436,7 @@ func TestJobFailed(t *testing.T) {
Manifest: manifest,
}

err = i.IsJobCompleted()
err = i.IsJobCompleted(context.Background(), nil, "")
if err == nil {
t.Fatal("Expected Error but got nil ")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,14 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, installerSet *v1alpha1.T
// Update Ready status of Controller
installerSet.Status.MarkControllerReady()

// job
labels := installerSet.GetLabels()
installSetname := installerSet.GetName()
err = installer.IsJobCompleted(ctx, labels, installSetname)
if err != nil {
return err
}

// Check if any other deployment exists other than controller
// and webhook and is ready
err = installer.AllDeploymentsReady()
Expand All @@ -178,12 +186,6 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, installerSet *v1alpha1.T
// Mark all deployments ready
installerSet.Status.MarkAllDeploymentsReady()

// job
err = installer.IsJobCompleted()
if err != nil {
return err
}

return nil
}

Expand Down