-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[usage] Initial installer configuration #10228
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 usage | ||
|
||
const ( | ||
Component = "usage" | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
// Copyright (c) 2022 Gitpod GmbH. All rights reserved. | ||
// Licensed under the MIT License. See License-MIT.txt in the project root for license information. | ||
|
||
package usage | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/gitpod-io/gitpod/common-go/baseserver" | ||
"github.com/gitpod-io/gitpod/installer/pkg/cluster" | ||
"github.com/gitpod-io/gitpod/installer/pkg/common" | ||
appsv1 "k8s.io/api/apps/v1" | ||
corev1 "k8s.io/api/core/v1" | ||
"k8s.io/apimachinery/pkg/api/resource" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/apimachinery/pkg/util/intstr" | ||
"k8s.io/utils/pointer" | ||
) | ||
|
||
func deployment(ctx *common.RenderContext) ([]runtime.Object, error) { | ||
labels := common.DefaultLabels(Component) | ||
return []runtime.Object{ | ||
&appsv1.Deployment{ | ||
TypeMeta: common.TypeMetaDeployment, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: Component, | ||
Namespace: ctx.Namespace, | ||
Labels: labels, | ||
}, | ||
Spec: appsv1.DeploymentSpec{ | ||
Selector: &metav1.LabelSelector{MatchLabels: labels}, | ||
Replicas: common.Replicas(ctx, Component), | ||
Strategy: common.DeploymentStrategy, | ||
Template: corev1.PodTemplateSpec{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: Component, | ||
Namespace: ctx.Namespace, | ||
Labels: labels, | ||
}, | ||
Spec: corev1.PodSpec{ | ||
Affinity: common.NodeAffinity(cluster.AffinityLabelMeta), | ||
ServiceAccountName: Component, | ||
EnableServiceLinks: pointer.Bool(false), | ||
DNSPolicy: "ClusterFirst", | ||
RestartPolicy: "Always", | ||
TerminationGracePeriodSeconds: pointer.Int64(30), | ||
Containers: []corev1.Container{{ | ||
Name: Component, | ||
Image: ctx.ImageName(ctx.Config.Repository, Component, ctx.VersionManifest.Components.Usage.Version), | ||
Args: []string{ | ||
"run", | ||
}, | ||
ImagePullPolicy: corev1.PullIfNotPresent, | ||
Resources: common.ResourceRequirements(ctx, Component, Component, corev1.ResourceRequirements{ | ||
Requests: corev1.ResourceList{ | ||
"cpu": resource.MustParse("100m"), | ||
"memory": resource.MustParse("64Mi"), | ||
}, | ||
}), | ||
Ports: []corev1.ContainerPort{}, | ||
SecurityContext: &corev1.SecurityContext{ | ||
Privileged: pointer.Bool(false), | ||
}, | ||
Env: common.MergeEnv( | ||
common.DefaultEnv(&ctx.Config), | ||
), | ||
LivenessProbe: &corev1.Probe{ | ||
ProbeHandler: corev1.ProbeHandler{ | ||
HTTPGet: &corev1.HTTPGetAction{ | ||
Path: "/live", | ||
Port: intstr.IntOrString{IntVal: baseserver.BuiltinHealthPort}, | ||
Scheme: corev1.URISchemeHTTP, | ||
}, | ||
}, | ||
FailureThreshold: 3, | ||
SuccessThreshold: 1, | ||
TimeoutSeconds: 1, | ||
}, | ||
ReadinessProbe: &corev1.Probe{ | ||
ProbeHandler: corev1.ProbeHandler{ | ||
HTTPGet: &corev1.HTTPGetAction{ | ||
Path: "/ready", | ||
Port: intstr.IntOrString{IntVal: baseserver.BuiltinHealthPort}, | ||
Scheme: corev1.URISchemeHTTP, | ||
}, | ||
}, | ||
FailureThreshold: 3, | ||
SuccessThreshold: 1, | ||
TimeoutSeconds: 1, | ||
}, | ||
}, | ||
*common.KubeRBACProxyContainerWithConfig(ctx, 9500, fmt.Sprintf("http://127.0.0.1:%d/", baseserver.BuiltinMetricsPort)), | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright (c) 2022 Gitpod GmbH. All rights reserved. | ||
// Licensed under the MIT License. See License-MIT.txt in the project root for license information. | ||
|
||
package usage | ||
|
||
import ( | ||
"github.com/gitpod-io/gitpod/common-go/log" | ||
"github.com/gitpod-io/gitpod/installer/pkg/common" | ||
"github.com/gitpod-io/gitpod/installer/pkg/config/v1/experimental" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
) | ||
|
||
func Objects(ctx *common.RenderContext) ([]runtime.Object, error) { | ||
cfg := getExperimentalConfig(ctx) | ||
if cfg == nil { | ||
return nil, nil | ||
} | ||
|
||
log.Debug("Detected experimental.WebApp.Usage configuration", cfg) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to leave this log line? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the time being when it's experimental, I'm keen to leave it just to have the interpretation of the config in CI a bit more transparent. |
||
return common.CompositeRenderFunc( | ||
deployment, | ||
rolebinding, | ||
common.DefaultServiceAccount(Component), | ||
)(ctx) | ||
} | ||
|
||
func getExperimentalConfig(ctx *common.RenderContext) *experimental.UsageConfig { | ||
var experimentalCfg *experimental.Config | ||
|
||
_ = ctx.WithExperimental(func(ucfg *experimental.Config) error { | ||
experimentalCfg = ucfg | ||
return nil | ||
}) | ||
|
||
if experimentalCfg == nil || experimentalCfg.WebApp == nil || experimentalCfg.WebApp.Usage == nil { | ||
return nil | ||
} | ||
|
||
return experimentalCfg.WebApp.Usage | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright (c) 2022 Gitpod GmbH. All rights reserved. | ||
// Licensed under the MIT License. See License-MIT.txt in the project root for license information. | ||
|
||
package usage | ||
|
||
import ( | ||
"github.com/gitpod-io/gitpod/installer/pkg/common" | ||
"github.com/gitpod-io/gitpod/installer/pkg/config/v1" | ||
"github.com/gitpod-io/gitpod/installer/pkg/config/v1/experimental" | ||
"github.com/gitpod-io/gitpod/installer/pkg/config/versions" | ||
"github.com/stretchr/testify/require" | ||
"testing" | ||
) | ||
|
||
func TestObjects_NotRenderedByDefault(t *testing.T) { | ||
ctx, err := common.NewRenderContext(config.Config{}, versions.Manifest{}, "test-namespace") | ||
require.NoError(t, err) | ||
|
||
objects, err := Objects(ctx) | ||
require.NoError(t, err) | ||
require.Empty(t, objects, "no objects should be rendered with default config") | ||
} | ||
|
||
func TestObjects_RenderedWhenExperimentalConfigSet(t *testing.T) { | ||
ctx := renderContextWithUsageEnabled(t) | ||
|
||
objects, err := Objects(ctx) | ||
require.NoError(t, err) | ||
require.NotEmpty(t, objects, "must render objects because experimental config is specified") | ||
require.Len(t, objects, 4, "should render expected k8s objects") | ||
} | ||
|
||
func renderContextWithUsageEnabled(t *testing.T) *common.RenderContext { | ||
ctx, err := common.NewRenderContext(config.Config{ | ||
Domain: "test.domain.everything.awesome.is", | ||
Experimental: &experimental.Config{ | ||
WebApp: &experimental.WebAppConfig{ | ||
Usage: &experimental.UsageConfig{Enabled: true}, | ||
}, | ||
}, | ||
}, versions.Manifest{ | ||
Components: versions.Components{ | ||
Usage: versions.Versioned{ | ||
Version: "commit-test-latest", | ||
}, | ||
}, | ||
}, "test-namespace") | ||
require.NoError(t, err) | ||
|
||
return ctx | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// 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 usage | ||
|
||
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.ClusterRoleBinding{ | ||
TypeMeta: common.TypeMetaClusterRoleBinding, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: fmt.Sprintf("%s-%s-rb-kube-rbac-proxy", ctx.Namespace, Component), | ||
Labels: labels, | ||
}, | ||
RoleRef: rbacv1.RoleRef{ | ||
Kind: "ClusterRole", | ||
Name: fmt.Sprintf("%s-kube-rbac-proxy", ctx.Namespace), | ||
APIGroup: "rbac.authorization.k8s.io", | ||
}, | ||
Subjects: []rbacv1.Subject{{ | ||
Kind: "ServiceAccount", | ||
Name: Component, | ||
Namespace: ctx.Namespace, | ||
}}, | ||
}, | ||
&rbacv1.RoleBinding{ | ||
TypeMeta: common.TypeMetaRoleBinding, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: Component, | ||
Namespace: ctx.Namespace, | ||
Labels: common.DefaultLabels(Component), | ||
}, | ||
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 | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to be specified? It's the default AFAIK.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we'll want to tweak it down the line so keeping it here to make adjusting easier.