-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Restart the frontend deployment to update site-config #60776
base: main
Are you sure you want to change the base?
Changes from 8 commits
1853fff
2f5ecc0
da84257
f911529
1e3ff6d
0cbe359
05109d2
efecd89
c379ad6
0302598
5f98984
7f73efe
17d5aeb
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 |
|---|---|---|
|
|
@@ -2,29 +2,53 @@ package graphqlbackend | |
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "time" | ||
|
|
||
| "github.com/inconshreveable/log15" //nolint:logging // TODO move all logging to sourcegraph/log | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| k8stypes "k8s.io/apimachinery/pkg/types" | ||
|
|
||
| "github.com/sourcegraph/sourcegraph/cmd/frontend/internal/processrestart" | ||
| "github.com/sourcegraph/sourcegraph/internal/actor" | ||
| "github.com/sourcegraph/sourcegraph/internal/auth" | ||
| "github.com/sourcegraph/sourcegraph/internal/cloud" | ||
| "github.com/sourcegraph/sourcegraph/internal/endpoint" | ||
| "github.com/sourcegraph/sourcegraph/lib/errors" | ||
| ) | ||
|
|
||
| // canReloadSite is whether the current site can be reloaded via the API. Currently | ||
| // only goreman-managed sites can be reloaded. Callers must also check if the actor | ||
| // is an admin before actually reloading the site. | ||
| var canReloadSite = processrestart.CanRestart() | ||
| var isGoremanSite = processrestart.CanRestart() | ||
|
|
||
| func (r *schemaResolver) ReloadSite(ctx context.Context) (*EmptyResponse, error) { | ||
| // 🚨 SECURITY: Reloading the site is an interruptive action, so only admins | ||
| // 🚨 SECURITY: Reloading the site is an disruptive action, so only admins | ||
| // may do it. | ||
| if err := auth.CheckCurrentUserIsSiteAdmin(ctx, r.db); err != nil { | ||
| return nil, err | ||
| } | ||
| if cloud.SiteConfig().SourcegraphOperatorAuthProviderEnabled() { | ||
| // use k8s client to restart the frontend deployment rollout | ||
| client, err := endpoint.LoadClient() | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| ns := endpoint.Namespace(r.logger) | ||
| data := fmt.Sprintf(`{"spec": {"template": {"metadata": {"annotations": {"kubectl.kubernetes.io/restartedAt": "%s"}}}}}`, time.Now().Format("20060102150405")) | ||
|
Member
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. will this cause drift with the deployment manifests? e.g., kustomize, helm. I would like to see an E2E test against a locally deployed (with you can build images from this branch with: sg ci build docker-images-candidates-notestThen in your helm overrides: storageClass:
create: false
name: standard
sourcegraph:
localDevMode: true
image:
# you can find the tag from buildkite logs
defaultTag: docker-images-candidates-notest-<replace_md>
useGlobalTagAsDefault: true
Contributor
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.
@michaellzc I do not expect any drift, b/c I just did template:
metadata:
annotations:
checksum/auth: 5dda2c15191bf709225a311e8b732e6253d7b1c9afcf89e6ec994511cbbd2cf4
checksum/redis: 63b58e05a2640417d599c4aee6d866cb9063e3a9aa452dc08dbfff836b7781b7
kubectl.kubernetes.io/default-container: frontend
kubectl.kubernetes.io/restartedAt: "2024-02-29T00:51:29+01:00" <-- new one just added by kubectlso this action is same as normal operation done by our self-service
Member
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. got it, didn't know that's how on that notes, a few suggestions:
|
||
| deploymentClient := client.AppsV1().Deployments(ns) | ||
|
|
||
| r.logger.Info("Restarting k8s deployment") | ||
|
|
||
| _, err = deploymentClient.Patch(ctx, "sourcegraph-frontend", | ||
| k8stypes.StrategicMergePatchType, []byte(data), metav1.PatchOptions{}) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| return &EmptyResponse{}, nil | ||
| } | ||
|
|
||
| if !canReloadSite { | ||
| if !isGoremanSite { | ||
| return nil, errors.New("reloading site is not supported") | ||
| } | ||
|
|
||
|
|
||
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.
Cloud only - nice 👍