Skip to content

Commit

Permalink
improvement(sync): update Mutagen to 0.17.5 (#5744)
Browse files Browse the repository at this point in the history
**What this PR does / why we need it**:

This PR updates the Mutagen tool to the latest available version. 

**Which issue(s) this PR fixes**:

This should fix #5053

**Special notes for your reviewer**:
  • Loading branch information
vvagaytsev committed Feb 22, 2024
1 parent d1deef5 commit eec7832
Show file tree
Hide file tree
Showing 14 changed files with 66 additions and 39 deletions.
37 changes: 23 additions & 14 deletions core/src/mutagen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,14 @@ class _MutagenMonitor extends TypedEventEmitter<MonitorEvents> {
log.warn(crashMessage)
})

let monitorFailureLogged = false
proc.on("exit", (code: number) => {
if (code && code !== 0) {
log.warn(`Synchronization monitor exited with code ${code}.`)
if (!monitorFailureLogged) {
logMutagenDaemonWarning(log)
monitorFailureLogged = true
}
}
})

Expand Down Expand Up @@ -322,6 +327,16 @@ class _MutagenMonitor extends TypedEventEmitter<MonitorEvents> {
}
}

function logMutagenDaemonWarning(log: Log) {
log.warn(
dedent`
It looks like you've changed to a different version of the sync daemon and therefore the sync daemon needs to be restarted.
Please see our Troubleshooting docs for instructions on how to restart the daemon for your platform: ${styles.link(
makeDocsLink("guides/code-synchronization", "#restarting-sync-daemon")
)}}`
)
}

/**
* A class for managing the Mutagen daemon process and its syncs.
*
Expand Down Expand Up @@ -533,13 +548,7 @@ export class Mutagen {
}

if (isMutagenForkError(err)) {
log.warn(
dedent`
It looks like you've changed to a different version of the sync daemon and therefore the sync daemon needs to be restarted.
Please see our Troubleshooting docs for instructions on how to restart the daemon for your platform: ${styles.link(
makeDocsLink("guides/code-synchronization", "#restarting-sync-daemon")
)}}`
)
logMutagenDaemonWarning(log)
throw err
}
}
Expand Down Expand Up @@ -897,7 +906,7 @@ export function parseSyncListResult(res: ExecaReturnValue): SyncSession[] {
}

const mutagenVersionLegacy = "0.15.0"
const mutagenVersionNative = "0.15.0"
const mutagenVersionNative = "0.17.5"

export const mutagenVersion = gardenEnv.GARDEN_ENABLE_NEW_SYNC ? mutagenVersionNative : mutagenVersionLegacy

Expand All @@ -912,7 +921,7 @@ export function mutagenCliSpecLegacy(): PluginToolSpec {
{
platform: "darwin",
architecture: "amd64",
url: `https://github.com/garden-io/mutagen/releases/download/v${mutagenVersionLegacy}-garden-1/mutagen_darwin_amd64_v${mutagenVersion}.tar.gz`,
url: `https://github.com/garden-io/mutagen/releases/download/v${mutagenVersionLegacy}-garden-1/mutagen_darwin_amd64_v${mutagenVersionLegacy}.tar.gz`,
sha256: "370bf71e28f94002453921fda83282280162df7192bd07042bf622bf54507e3f",
extract: {
format: "tar",
Expand Down Expand Up @@ -975,7 +984,7 @@ export function mutagenCliSpecNative(): PluginToolSpec {
platform: "darwin",
architecture: "amd64",
url: `https://github.com/mutagen-io/mutagen/releases/download/v${mutagenVersionNative}/mutagen_darwin_amd64_v${mutagenVersionNative}.tar.gz`,
sha256: "7ff3fae37c90f050db283f557d4370546691e4d5ec2f6dd10fbcbe6a20ba0154",
sha256: "5b963b3dab36ac8a3d2a87ca162717bf2172fd8ca7410d477a78affd7631a45d",
extract: {
format: "tar",
targetPath: "mutagen",
Expand All @@ -985,7 +994,7 @@ export function mutagenCliSpecNative(): PluginToolSpec {
platform: "darwin",
architecture: "arm64",
url: `https://github.com/mutagen-io/mutagen/releases/download/v${mutagenVersionNative}/mutagen_darwin_arm64_v${mutagenVersionNative}.tar.gz`,
sha256: "2ab938830c9a1a7d5b3289826f9765654ca465b7a089b74df407071bc5f8b7b0",
sha256: "4dbbbc222a3986705a998343ff23d69e62bfe1c4e341ef9f1cdf39d25a37c324",
extract: {
format: "tar",
targetPath: "mutagen",
Expand All @@ -995,7 +1004,7 @@ export function mutagenCliSpecNative(): PluginToolSpec {
platform: "linux",
architecture: "amd64",
url: `https://github.com/mutagen-io/mutagen/releases/download/v${mutagenVersionNative}/mutagen_linux_amd64_v${mutagenVersionNative}.tar.gz`,
sha256: "dd4a0b6fa8b36232108075d2c740d563ec945d8e872c749ad027fa1b241a8b07",
sha256: "cabee0af590faf822cb5542437e254406b0f037df43781c02bf6eeac267911f6",
extract: {
format: "tar",
targetPath: "mutagen",
Expand All @@ -1005,7 +1014,7 @@ export function mutagenCliSpecNative(): PluginToolSpec {
platform: "linux",
architecture: "arm64",
url: `https://github.com/mutagen-io/mutagen/releases/download/v${mutagenVersionNative}/mutagen_linux_arm64_v${mutagenVersionNative}.tar.gz`,
sha256: "137274f443aaf6bfb9c9170cdfa91d9ea88c5903e8c79b445870881ef678b4e8",
sha256: "bbe92496c2bad6424a879490ca5b49da36c80e28e7b866201fcaf7a959037237",
extract: {
format: "tar",
targetPath: "mutagen",
Expand All @@ -1015,7 +1024,7 @@ export function mutagenCliSpecNative(): PluginToolSpec {
platform: "windows",
architecture: "amd64",
url: `https://github.com/mutagen-io/mutagen/releases/download/v${mutagenVersionNative}/mutagen_windows_amd64_v${mutagenVersionNative}.zip`,
sha256: "8b502693add563a7dd7973f043301b25ef34bd3846619dffce3ba47f64c15a0a",
sha256: "63ed4b217f798f49039cae5db4b63f592217be5685282e3669a9b6a4ae18cb64",
extract: {
format: "zip",
targetPath: "mutagen.exe",
Expand Down
4 changes: 2 additions & 2 deletions core/src/plugins/kubernetes/commands/pull-image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import type { Log } from "../../../logger/log-entry.js"
import { containerHelpers } from "../../container/helpers.js"
import { RuntimeError } from "../../../exceptions.js"
import { PodRunner } from "../run.js"
import { dockerAuthSecretKey, systemDockerAuthSecretName, k8sUtilImageName } from "../constants.js"
import { dockerAuthSecretKey, getK8sUtilImageName, systemDockerAuthSecretName } from "../constants.js"
import { getAppNamespace, getSystemNamespace } from "../namespace.js"
import { randomString } from "../../../util/string.js"
import type { PluginContext } from "../../../plugin-context.js"
Expand Down Expand Up @@ -144,7 +144,7 @@ async function pullFromExternalRegistry({ ctx, log, localId, remoteId }: PullPar
containers: [
{
name: "main",
image: k8sUtilImageName,
image: getK8sUtilImageName(),
command: ["sleep", "" + (imagePullTimeoutSeconds + 10)],
volumeMounts: [
{
Expand Down
19 changes: 17 additions & 2 deletions core/src/plugins/kubernetes/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

import type { DockerImageWithDigest } from "../../util/string.js"
import { gardenEnv } from "../../constants.js"
import { makeDocsLink } from "../../docs/common.js"

export const rsyncPortName = "garden-rsync"
Expand All @@ -31,10 +32,24 @@ export const skopeoDaemonContainerName = "util"
export const defaultIngressClass = "nginx"

// Docker images that Garden ships with
export const k8sUtilImageName: DockerImageWithDigest =
export const k8sUtilImageNameLegacy: DockerImageWithDigest =
"gardendev/k8s-util:0.5.7@sha256:522da245a5e6ae7c711aa94f84fc83f82a8fdffbf6d8bc48f4d80fee0e0e631b"
export const k8sSyncUtilImageName: DockerImageWithDigest =
export const k8sUtilImageName: DockerImageWithDigest =
"gardendev/k8s-util:0.6.0@sha256:8c62c47278dcd71dce04a7d10e794eae611ed1a3202ea3edd8f6a8651f2ea2a2"

export function getK8sUtilImageName(): DockerImageWithDigest {
return gardenEnv.GARDEN_ENABLE_NEW_SYNC ? k8sUtilImageName : k8sUtilImageNameLegacy
}

export const k8sSyncUtilImageNameLegacy: DockerImageWithDigest =
"gardendev/k8s-sync:0.1.5@sha256:28263cee5ac41acebb8c08f852c4496b15e18c0c94797d7a949a4453b5f91578"
export const k8sSyncUtilImageName: DockerImageWithDigest =
"gardendev/k8s-sync:0.2.0@sha256:749aa42e2e2837037abeb9e48e77498ca570a56281a335eed0609bfba8b732bc"

export function getK8sSyncUtilImageName(): DockerImageWithDigest {
return gardenEnv.GARDEN_ENABLE_NEW_SYNC ? k8sSyncUtilImageName : k8sSyncUtilImageNameLegacy
}

export const k8sReverseProxyImageName: DockerImageWithDigest =
"gardendev/k8s-reverse-proxy:0.1.0@sha256:df2976dc67c237114bd9c70e32bfe4d7131af98e140adf6dac29b47b85e07232"
export const buildkitImageName: DockerImageWithDigest =
Expand Down
4 changes: 2 additions & 2 deletions core/src/plugins/kubernetes/container/build/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import type { Resolved } from "../../../../actions/types.js"
import { stringifyResources } from "../util.js"
import { getKubectlExecDestination } from "../../sync.js"
import { getRunningDeploymentPod } from "../../util.js"
import { buildSyncVolumeName, dockerAuthSecretKey, k8sUtilImageName, rsyncPortName } from "../../constants.js"
import { buildSyncVolumeName, dockerAuthSecretKey, getK8sUtilImageName, rsyncPortName } from "../../constants.js"
import { styles } from "../../../../logger/styles.js"
import type { StringMap } from "../../../../config/common.js"
import { LogLevel } from "../../../../logger/logger.js"
Expand Down Expand Up @@ -517,7 +517,7 @@ export function getBuilderServiceAccountSpec(namespace: string, annotations?: St
export function getUtilContainer(authSecretName: string, provider: KubernetesProvider): V1Container {
return {
name: utilContainerName,
image: k8sUtilImageName,
image: getK8sUtilImageName(),
imagePullPolicy: "IfNotPresent",
command: ["/rsync-server.sh"],
env: [
Expand Down
4 changes: 2 additions & 2 deletions core/src/plugins/kubernetes/container/build/kaniko.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import type { V1PodSpec } from "@kubernetes/client-node"
import {
skopeoDaemonContainerName,
dockerAuthSecretKey,
k8sUtilImageName,
defaultKanikoImageName,
getK8sUtilImageName,
} from "../../constants.js"
import { KubeApi } from "../../api.js"
import type { Log } from "../../../../logger/log-entry.js"
Expand Down Expand Up @@ -288,7 +288,7 @@ export function getKanikoBuilderPodManifest({
initContainers: [
{
name: "init",
image: k8sUtilImageName,
image: getK8sUtilImageName(),
command: [
"/bin/sh",
"-c",
Expand Down
3 changes: 2 additions & 1 deletion core/src/plugins/kubernetes/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ import { isConfiguredForSyncMode } from "./status/status.js"
import type { PluginContext } from "../../plugin-context.js"
import type { SyncConfig, SyncSession } from "../../mutagen.js"
import { haltedStatuses, Mutagen, mutagenAgentPath, mutagenStatusDescriptions } from "../../mutagen.js"
import { k8sSyncUtilImageName, syncGuideLink } from "./constants.js"
import { getK8sSyncUtilImageName, syncGuideLink } from "./constants.js"
import { isAbsolute, relative, resolve } from "path"
import type { Resolved } from "../../actions/types.js"
import { joinWithPosix } from "../../util/fs.js"
Expand Down Expand Up @@ -452,6 +452,7 @@ export async function configureSyncMode({
if (!podSpec.initContainers) {
podSpec.initContainers = []
}
const k8sSyncUtilImageName = getK8sSyncUtilImageName()
if (!podSpec.initContainers.find((c) => c.image === k8sSyncUtilImageName)) {
const initContainer = {
name: "garden-dev-init",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ import { apply } from "../../../../../../src/plugins/kubernetes/kubectl.js"
import { getAppNamespace } from "../../../../../../src/plugins/kubernetes/namespace.js"
import { gardenAnnotationKey } from "../../../../../../src/util/string.js"
import {
getK8sSyncUtilImageName,
k8sReverseProxyImageName,
k8sSyncUtilImageName,
PROXY_CONTAINER_SSH_TUNNEL_PORT,
PROXY_CONTAINER_SSH_TUNNEL_PORT_NAME,
PROXY_CONTAINER_USER_NAME,
Expand Down Expand Up @@ -451,7 +451,7 @@ describe("kubernetes container deployment handlers", () => {
expect(resource.spec.template?.spec?.initContainers).to.eql([
{
name: "garden-dev-init",
image: k8sSyncUtilImageName,
image: getK8sSyncUtilImageName(),
command: ["/bin/sh", "-c", "cp /usr/local/bin/mutagen-agent /.garden/mutagen-agent"],
imagePullPolicy: "IfNotPresent",
volumeMounts: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type {
KubernetesProvider,
} from "../../../../../../../src/plugins/kubernetes/config.js"
import { defaultResources } from "../../../../../../../src/plugins/kubernetes/config.js"
import { buildkitImageName, k8sUtilImageName } from "../../../../../../../src/plugins/kubernetes/constants.js"
import { buildkitImageName, getK8sUtilImageName } from "../../../../../../../src/plugins/kubernetes/constants.js"
import {
getBuildkitDeployment,
getBuildkitFlags,
Expand Down Expand Up @@ -121,7 +121,7 @@ describe("buildkit build", () => {
value: "8730",
},
],
image: k8sUtilImageName,
image: getK8sUtilImageName(),
imagePullPolicy: "IfNotPresent",
lifecycle: {
preStop: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { expect } from "chai"
import type { KubernetesProvider } from "../../../../../../../src/plugins/kubernetes/config.js"
import { defaultResources } from "../../../../../../../src/plugins/kubernetes/config.js"
import type { DeepPartial } from "../../../../../../../src/util/util.js"
import { k8sUtilImageName } from "../../../../../../../src/plugins/kubernetes/constants.js"
import { getK8sUtilImageName } from "../../../../../../../src/plugins/kubernetes/constants.js"

describe("common build", () => {
describe("manifest error", () => {
Expand Down Expand Up @@ -102,7 +102,7 @@ describe("common build", () => {
containers: [
{
name: "util",
image: k8sUtilImageName,
image: getK8sUtilImageName(),
imagePullPolicy: "IfNotPresent",
command: ["/rsync-server.sh"],
env: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import { expect } from "chai"
import type { KubernetesProvider } from "../../../../../../../src/plugins/kubernetes/config.js"
import { defaultResources } from "../../../../../../../src/plugins/kubernetes/config.js"
import { defaultKanikoImageName, k8sUtilImageName } from "../../../../../../../src/plugins/kubernetes/constants.js"
import { defaultKanikoImageName, getK8sUtilImageName } from "../../../../../../../src/plugins/kubernetes/constants.js"
import type { DeepPartial } from "utility-types"
import { inClusterBuilderServiceAccount } from "../../../../../../../src/plugins/kubernetes/container/build/common.js"

Expand Down Expand Up @@ -128,7 +128,7 @@ describe("kaniko build", () => {
"-c",
'echo "Copying from sourceURL to /.garden/context"\nmkdir -p /.garden/context\nn=0\nuntil [ "$n" -ge 30 ]\ndo\n rsync arg1 arg2 && break\n n=$((n+1))\n sleep 1\ndone\necho "Done!"',
],
image: k8sUtilImageName,
image: getK8sUtilImageName(),
imagePullPolicy: "IfNotPresent",
name: "init",
volumeMounts: [
Expand Down
12 changes: 7 additions & 5 deletions images/k8s-sync/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
FROM alpine:3.15.4@sha256:a777c9c66ba177ccfea23f2a216ff6721e78a662cd17019488c417135299cd89
FROM alpine:3.19.1@sha256:6457d53fb065d6f250e1504b9bc42d5b6c65941d57532c072d929dd0628977d0

RUN apk add --no-cache wget

# Get mutagen agent
RUN wget "https://github.com/mutagen-io/mutagen/releases/download/v0.15.0/mutagen_linux_amd64_v0.15.0.tar.gz" && \
echo "dd4a0b6fa8b36232108075d2c740d563ec945d8e872c749ad027fa1b241a8b07 mutagen_linux_amd64_v0.15.0.tar.gz" | sha256sum -c && \
tar xzf mutagen_linux_amd64_v0.15.0.tar.gz --to-stdout mutagen-agents.tar.gz \
RUN MUTAGEN_VERSION="0.17.5" && \
mutagen_distr_name="mutagen_linux_amd64_v${MUTAGEN_VERSION}.tar.gz" && \
wget "https://github.com/mutagen-io/mutagen/releases/download/v${MUTAGEN_VERSION}/${mutagen_distr_name}" && \
echo "cabee0af590faf822cb5542437e254406b0f037df43781c02bf6eeac267911f6 ${mutagen_distr_name}" | sha256sum -c && \
tar xzf ${mutagen_distr_name} --to-stdout mutagen-agents.tar.gz \
| tar xz --to-stdout linux_amd64 > /usr/local/bin/mutagen-agent && \
rm mutagen_linux_amd64_v0.15.0.tar.gz && \
rm ${mutagen_distr_name} && \
chmod +x /usr/local/bin/mutagen-agent && \
mkdir -p /.garden && \
ln -s /usr/local/bin/mutagen-agent /.garden/mutagen-agent
2 changes: 1 addition & 1 deletion images/k8s-sync/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ To update the mutagen version:

### Publish new Docker images

1. Update the [Dockerfile](./Dockerfile) to use the new mutagen binaries and update the image name.
1. Update the [Dockerfile](./Dockerfile) to use the new mutagen binaries and update the image name
in [garden.yml](./garden.yml).
2. Build and publish the new `k8s-sync` image.
3. Increment the version of [k8s-util](../k8s-util) image by updating its [Dockerfile](../k8s-util/Dockerfile)
Expand Down
2 changes: 1 addition & 1 deletion images/k8s-sync/garden.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ kind: Module
type: container
name: k8s-sync
description: Used by the kubernetes provider for sync setup
image: gardendev/k8s-sync:0.1.5
image: gardendev/k8s-sync:0.2.0 # Starting from version 0.2.0 Garden uses original Mutagen binaries instead of own fork.
dockerfile: Dockerfile
extraFlags: [ "--platform", "linux/amd64" ]
2 changes: 1 addition & 1 deletion images/k8s-util/garden.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ kind: Module
type: container
name: k8s-util
description: Used by the kubernetes provider for build-related activities
image: gardendev/k8s-util:0.5.7
image: gardendev/k8s-util:0.6.0 # Starting from version 0.6.0 k8s-util uses k8s-sync 0.2.x.
dockerfile: Dockerfile
build:
dependencies: [k8s-sync]
Expand Down

0 comments on commit eec7832

Please sign in to comment.