Skip to content

Commit

Permalink
fix tektonConfig, chain tutorial and hub e2e test issues in OpenShift…
Browse files Browse the repository at this point in the history
… environment

Signed-off-by: Jeeva Kandasamy <jkandasa@gmail.com>
  • Loading branch information
jkandasa committed Apr 11, 2023
1 parent 862a853 commit 210827c
Show file tree
Hide file tree
Showing 60 changed files with 11,856 additions and 959 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,6 @@ tags
.idea/*

.bin/

# ignore chain certificate
test/e2e/common/cosign.pub
4 changes: 4 additions & 0 deletions config/base/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ rules:
- create
- update
- delete
- list
- watch
- apiGroups:
- ""
resources:
Expand All @@ -129,6 +131,8 @@ rules:
- create
- update
- delete
- list
- watch
- apiGroups:
- apiextensions.k8s.io
resources:
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ require (
github.com/openshift/client-go v0.0.0-20210521082421-73d9475a9142
github.com/sigstore/cosign/v2 v2.0.0
github.com/spf13/viper v1.15.0
github.com/stretchr/testify v1.8.1
github.com/tektoncd/pipeline v0.45.0
github.com/tektoncd/plumbing v0.0.0-20221102182345-5dbcfda657d7
github.com/tektoncd/triggers v0.23.1
Expand Down Expand Up @@ -203,6 +204,7 @@ require (
github.com/openzipkin/zipkin-go v0.4.1 // indirect
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.14.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.39.0 // indirect
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/operator/v1alpha1/tektonhub_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
func (th *TektonHub) SetDefaults(ctx context.Context) {

if th.Spec.Api.ApiSecretName == "" {
th.Spec.Api.ApiSecretName = "tekton-hub-api"
th.Spec.Api.ApiSecretName = HubApiSecretName
}

if th.Spec.CommonSpec.TargetNamespace == "" {
Expand Down
13 changes: 7 additions & 6 deletions pkg/apis/operator/v1alpha1/tektonhub_lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ const (
DbDependenciesInstalled apis.ConditionType = "DbDependenciesInstalled"
DbInstallerSetAvailable apis.ConditionType = "DbInstallSetAvailable"
// DB-migration
DatabasebMigrationDone apis.ConditionType = "DatabasebMigrationDone"
// TODO: fix the typo on the value: "DatabasebMigrationDone"
DatabaseMigrationDone apis.ConditionType = "DatabasebMigrationDone"
// API
ApiDependenciesInstalled apis.ConditionType = "ApiDependenciesInstalled"
ApiInstallerSetAvailable apis.ConditionType = "ApiInstallSetAvailable"
Expand All @@ -43,7 +44,7 @@ var (
hubCondSet = apis.NewLivingConditionSet(
DbDependenciesInstalled,
DbInstallerSetAvailable,
DatabasebMigrationDone,
DatabaseMigrationDone,
PreReconciler,
ApiDependenciesInstalled,
ApiInstallerSetAvailable,
Expand Down Expand Up @@ -119,16 +120,16 @@ func (ths *TektonHubStatus) MarkDbInstallerSetAvailable() {
}

// Lifecycle for the DB migration component of Tekton Hub
func (ths *TektonHubStatus) MarkDatabasebMigrationFailed(msg string) {
func (ths *TektonHubStatus) MarkDatabaseMigrationFailed(msg string) {
ths.MarkNotReady("Database migration job not ready")
hubCondSet.Manage(ths).MarkFalse(
DatabasebMigrationDone,
DatabaseMigrationDone,
"Error",
"Database migration job not ready: %s", msg)
}

func (ths *TektonHubStatus) MarkDatabasebMigrationDone() {
hubCondSet.Manage(ths).MarkTrue(DatabasebMigrationDone)
func (ths *TektonHubStatus) MarkDatabaseMigrationDone() {
hubCondSet.Manage(ths).MarkTrue(DatabaseMigrationDone)
}

// Lifecycle for the API component of Tekton Hub
Expand Down
20 changes: 10 additions & 10 deletions pkg/apis/operator/v1alpha1/tektonhub_lifecycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestTektonHubHappyPath(t *testing.T) {

apistest.CheckConditionOngoing(th, DbDependenciesInstalled, t)
apistest.CheckConditionOngoing(th, DbInstallerSetAvailable, t)
apistest.CheckConditionOngoing(th, DatabasebMigrationDone, t)
apistest.CheckConditionOngoing(th, DatabaseMigrationDone, t)
apistest.CheckConditionOngoing(th, ApiDependenciesInstalled, t)
apistest.CheckConditionOngoing(th, PreReconciler, t)
apistest.CheckConditionOngoing(th, ApiInstallerSetAvailable, t)
Expand All @@ -62,12 +62,12 @@ func TestTektonHubHappyPath(t *testing.T) {

// Db-migration
// InstallerSet is not ready when Job pods are not up
th.MarkDatabasebMigrationFailed("waiting for Job to complete")
apistest.CheckConditionFailed(th, DatabasebMigrationDone, t)
th.MarkDatabaseMigrationFailed("waiting for Job to complete")
apistest.CheckConditionFailed(th, DatabaseMigrationDone, t)

// Installer set created for DB migration
th.MarkDatabasebMigrationDone()
apistest.CheckConditionSucceeded(th, DatabasebMigrationDone, t)
th.MarkDatabaseMigrationDone()
apistest.CheckConditionSucceeded(th, DatabaseMigrationDone, t)

//API

Expand Down Expand Up @@ -107,7 +107,7 @@ func TestTektonHubErrorPath(t *testing.T) {

apistest.CheckConditionOngoing(th, DbDependenciesInstalled, t)
apistest.CheckConditionOngoing(th, DbInstallerSetAvailable, t)
apistest.CheckConditionOngoing(th, DatabasebMigrationDone, t)
apistest.CheckConditionOngoing(th, DatabaseMigrationDone, t)
apistest.CheckConditionOngoing(th, ApiDependenciesInstalled, t)
apistest.CheckConditionOngoing(th, PreReconciler, t)
apistest.CheckConditionOngoing(th, ApiInstallerSetAvailable, t)
Expand All @@ -126,12 +126,12 @@ func TestTektonHubErrorPath(t *testing.T) {
apistest.CheckConditionSucceeded(th, DbInstallerSetAvailable, t)

// InstallerSet is not ready when Job pods are not up
th.MarkDatabasebMigrationFailed("waiting for Job to complete")
apistest.CheckConditionFailed(th, DatabasebMigrationDone, t)
th.MarkDatabaseMigrationFailed("waiting for Job to complete")
apistest.CheckConditionFailed(th, DatabaseMigrationDone, t)

// Installer set created for DB migration
th.MarkDatabasebMigrationDone()
apistest.CheckConditionSucceeded(th, DatabasebMigrationDone, t)
th.MarkDatabaseMigrationDone()
apistest.CheckConditionSucceeded(th, DatabaseMigrationDone, t)

th.MarkApiDependenciesInstalled()
apistest.CheckConditionSucceeded(th, ApiDependenciesInstalled, t)
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/operator/v1alpha1/tektonhub_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ import (
duckv1 "knative.dev/pkg/apis/duck/v1"
)

const (
HubDbSecretName = "tekton-hub-db"
HubApiSecretName = "tekton-hub-api"
)

var (
_ TektonComponent = (*TektonHub)(nil)
_ TektonComponentSpec = (*TektonHubSpec)(nil)
Expand Down
21 changes: 6 additions & 15 deletions pkg/apis/operator/v1alpha1/tektonhub_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,27 +41,18 @@ func validateHubParams(params []Param, pathToParams string) *apis.FieldError {
}

func (th *TektonHub) Validate(ctx context.Context) (errs *apis.FieldError) {

if apis.IsInDelete(ctx) {
return nil
}

errs = errs.Also(th.Spec.Db.validate("spec.db"))

return errs.Also(th.Spec.Api.validate("spec.api"))

}

func (db *DbSpec) validate(path string) (errs *apis.FieldError) {
if db.DbSecretName != "" && db.DbSecretName != "tekton-hub-db" {
return errs.Also(apis.ErrInvalidValue(db.DbSecretName, path+".DbSecretName"))
// validate database secret name
if th.Spec.Db.DbSecretName != "" && th.Spec.Db.DbSecretName != HubDbSecretName {
errs = errs.Also(apis.ErrInvalidValue(th.Spec.Db.DbSecretName, "spec.db.secret"))
}
return errs
}

func (api *ApiSpec) validate(path string) (errs *apis.FieldError) {
if api.ApiSecretName != "" && api.ApiSecretName != "tekton-hub-api" {
return errs.Also(apis.ErrInvalidValue(api.ApiSecretName, path+".ApiSecretName"))
// validate api secret name
if th.Spec.Api.ApiSecretName != "" && th.Spec.Api.ApiSecretName != HubApiSecretName {
errs = errs.Also(apis.ErrInvalidValue(th.Spec.Api.ApiSecretName, "spec.api.secret"))
}

return errs
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/operator/v1alpha1/tektonhub_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func Test_ValidateTektonHub_InvalidDbSecretName(t *testing.T) {
}

err := th.Validate(context.TODO())
assert.Equal(t, "invalid value: invalid-value: spec.db.DbSecretName", err.Error())
assert.Equal(t, "invalid value: invalid-value: spec.db.secret", err.Error())
}

func Test_ValidateTektonHub_InvalidApiSecretName(t *testing.T) {
Expand All @@ -117,5 +117,5 @@ func Test_ValidateTektonHub_InvalidApiSecretName(t *testing.T) {
}

err := th.Validate(context.TODO())
assert.Equal(t, "invalid value: invalid-value: spec.api.ApiSecretName", err.Error())
assert.Equal(t, "invalid value: invalid-value: spec.api.secret", err.Error())
}

0 comments on commit 210827c

Please sign in to comment.