Skip to content

[spicedb] rolling update when schema changes #18561

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

Merged
merged 1 commit into from
Aug 21, 2023
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
9 changes: 6 additions & 3 deletions components/server/src/authorization/spicedb-authorizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import { v1 } from "@authzed/authzed-node";
import { log } from "@gitpod/gitpod-protocol/lib/util/logging";
import { TrustedValue } from "@gitpod/gitpod-protocol/lib/util/scrubbing";

import { getExperimentsClientForBackend } from "@gitpod/gitpod-protocol/lib/experiments/configcat-server";
import { inject, injectable } from "inversify";
Expand Down Expand Up @@ -47,7 +48,9 @@ export class SpiceDBAuthorizer {
return permitted;
} catch (err) {
error = err;
log.error("[spicedb] Failed to perform authorization check.", err, { req });
log.error("[spicedb] Failed to perform authorization check.", err, {
request: new TrustedValue(req),
});
return false;
} finally {
observeSpicedbClientLatency("check", error, timer());
Expand All @@ -72,7 +75,7 @@ export class SpiceDBAuthorizer {
return response;
} catch (err) {
error = err;
log.error("[spicedb] Failed to write relationships.", err, { updates });
log.error("[spicedb] Failed to write relationships.", err, { updates: new TrustedValue(updates) });
} finally {
observeSpicedbClientLatency("write", error, timer());
}
Expand Down Expand Up @@ -104,7 +107,7 @@ export class SpiceDBAuthorizer {
error = err;
// While in we're running two authorization systems in parallel, we do not hard fail on writes.
//TODO throw new ApplicationError(ErrorCodes.INTERNAL_SERVER_ERROR, "Failed to delete relationships.");
log.error("[spicedb] Failed to delete relationships.", err, { req });
log.error("[spicedb] Failed to delete relationships.", err, { request: new TrustedValue(req) });
return [];
} finally {
observeSpicedbClientLatency("delete", error, timer());
Expand Down
14 changes: 9 additions & 5 deletions install/installer/pkg/components/spicedb/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func deployment(ctx *common.RenderContext) ([]runtime.Object, error) {
return nil, errors.New("missing configuration for spicedb.secretRef")
}

bootstrapVolume, bootstrapVolumeMount, bootstrapFiles, err := getBootstrapConfig(ctx)
bootstrapVolume, bootstrapVolumeMount, bootstrapFiles, contentHash, err := getBootstrapConfig(ctx)
if err != nil {
return nil, fmt.Errorf("failed to get bootstrap config: %w", err)
}
Expand All @@ -56,10 +56,14 @@ func deployment(ctx *common.RenderContext) ([]runtime.Object, error) {
Strategy: common.DeploymentStrategy,
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Name: Component,
Namespace: ctx.Namespace,
Labels: labels,
Annotations: common.CustomizeAnnotation(ctx, Component, common.TypeMetaDeployment),
Name: Component,
Namespace: ctx.Namespace,
Labels: labels,
Annotations: common.CustomizeAnnotation(ctx, Component, common.TypeMetaDeployment, func() map[string]string {
return map[string]string{
common.AnnotationConfigChecksum: contentHash,
}
}),
},
Spec: corev1.PodSpec{
Affinity: cluster.WithNodeAffinityHostnameAntiAffinity(Component, cluster.AffinityLabelMeta),
Expand Down
17 changes: 14 additions & 3 deletions install/installer/pkg/components/spicedb/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
package spicedb

import (
"crypto/sha256"
"encoding/hex"
"fmt"
"path/filepath"

Expand Down Expand Up @@ -42,7 +44,7 @@ func bootstrap(ctx *common.RenderContext) ([]runtime.Object, error) {
}, nil
}

func getBootstrapConfig(ctx *common.RenderContext) (corev1.Volume, corev1.VolumeMount, []string, error) {
func getBootstrapConfig(ctx *common.RenderContext) (corev1.Volume, corev1.VolumeMount, []string, string, error) {
var volume corev1.Volume
var mount corev1.VolumeMount
var paths []string
Expand All @@ -68,12 +70,21 @@ func getBootstrapConfig(ctx *common.RenderContext) (corev1.Volume, corev1.Volume

files, err := spicedb_component.GetBootstrapFiles()
if err != nil {
return corev1.Volume{}, corev1.VolumeMount{}, nil, fmt.Errorf("failed to get bootstrap files: %w", err)
return corev1.Volume{}, corev1.VolumeMount{}, nil, "", fmt.Errorf("failed to get bootstrap files: %w", err)
}

for _, f := range files {
paths = append(paths, filepath.Join(mountPath, f.Name))
}

return volume, mount, paths, nil
concatenated := ""
for _, f := range files {
concatenated += f.Data
}

hasher := sha256.New()
hasher.Write([]byte(concatenated))
hash := hex.EncodeToString(hasher.Sum(nil))

return volume, mount, paths, hash, nil
}