-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[installer]: trigger a migration job when DB is ready
- Loading branch information
Simon Emms
committed
Oct 27, 2021
1 parent
85cfdb4
commit bc9ffe0
Showing
8 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Copyright (c) 2021 Gitpod GmbH. All rights reserved. | ||
// Licensed under the GNU Affero General Public License (AGPL). | ||
// See License-AGPL.txt in the project root for license information. | ||
|
||
package migrations | ||
|
||
const ( | ||
Component = "migrations" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright (c) 2021 Gitpod GmbH. All rights reserved. | ||
// Licensed under the GNU Affero General Public License (AGPL). | ||
// See License-AGPL.txt in the project root for license information. | ||
|
||
package migrations | ||
|
||
import ( | ||
"github.com/gitpod-io/gitpod/installer/pkg/common" | ||
batchv1 "k8s.io/api/batch/v1" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/utils/pointer" | ||
) | ||
|
||
func job(ctx *common.RenderContext) ([]runtime.Object, error) { | ||
objectMeta := metav1.ObjectMeta{ | ||
Name: Component, | ||
Namespace: ctx.Namespace, | ||
Labels: common.DefaultLabels(Component), | ||
} | ||
|
||
return []runtime.Object{&batchv1.Job{ | ||
TypeMeta: common.TypeMetaBatchJob, | ||
ObjectMeta: objectMeta, | ||
Spec: batchv1.JobSpec{ | ||
Template: corev1.PodTemplateSpec{ | ||
ObjectMeta: objectMeta, | ||
Spec: corev1.PodSpec{ | ||
Affinity: &corev1.Affinity{}, | ||
RestartPolicy: corev1.RestartPolicyNever, | ||
ServiceAccountName: Component, | ||
EnableServiceLinks: pointer.Bool(false), | ||
// The init container is designed to emulate Helm hooks | ||
InitContainers: []corev1.Container{*common.DatabaseWaiterContainer(ctx)}, | ||
Containers: []corev1.Container{{ | ||
Name: Component, | ||
Image: common.ImageName(ctx.Config.Repository, "db-migrations", ctx.VersionManifest.Components.DBMigrations.Version), | ||
ImagePullPolicy: corev1.PullIfNotPresent, | ||
Env: common.MergeEnv( | ||
common.DatabaseEnv(&ctx.Config), | ||
), | ||
Command: []string{ | ||
"sh", | ||
"-c", | ||
"cd /app/node_modules/@gitpod/gitpod-db && yarn run wait-for-db && yarn run typeorm migrations:run", | ||
}, | ||
}}, | ||
}, | ||
}, | ||
}, | ||
}}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright (c) 2021 Gitpod GmbH. All rights reserved. | ||
// Licensed under the GNU Affero General Public License (AGPL). | ||
// See License-AGPL.txt in the project root for license information. | ||
|
||
package migrations | ||
|
||
import ( | ||
"github.com/gitpod-io/gitpod/installer/pkg/common" | ||
) | ||
|
||
var Objects = common.CompositeRenderFunc( | ||
job, | ||
rolebinding, | ||
common.DefaultServiceAccount(Component), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright (c) 2021 Gitpod GmbH. All rights reserved. | ||
// Licensed under the GNU Affero General Public License (AGPL). | ||
// See License-AGPL.txt in the project root for license information. | ||
|
||
package migrations | ||
|
||
import ( | ||
"fmt" | ||
"github.com/gitpod-io/gitpod/installer/pkg/common" | ||
rbacv1 "k8s.io/api/rbac/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
) | ||
|
||
func rolebinding(ctx *common.RenderContext) ([]runtime.Object, error) { | ||
labels := common.DefaultLabels(Component) | ||
|
||
return []runtime.Object{&rbacv1.RoleBinding{ | ||
TypeMeta: common.TypeMetaRoleBinding, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: Component, | ||
Namespace: ctx.Namespace, | ||
Labels: labels, | ||
}, | ||
RoleRef: rbacv1.RoleRef{ | ||
Kind: "ClusterRole", | ||
Name: fmt.Sprintf("%s-ns-psp:restricted-root-user", ctx.Namespace), | ||
APIGroup: "rbac.authorization.k8s.io", | ||
}, | ||
Subjects: []rbacv1.Subject{{ | ||
Kind: "ServiceAccount", | ||
Name: Component, | ||
}}, | ||
}}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters