Skip to content

Commit 6cf031e

Browse files
committed
Pass ttrpc address to shim via env
Because of the way go handles flags, passing a flag that is not defined will cause an error. In our case, if we kept this as a flag, then third-party shims would break when they see this new flag. To fix this, I moved this new configuration option to an env var. We should use env vars from here on out to avoid breaking shim compat. Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
1 parent 1be6ee5 commit 6cf031e

File tree

4 files changed

+13
-8
lines changed

4 files changed

+13
-8
lines changed

runtime/v2/runc/v1/service.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ func newCommand(ctx context.Context, id, containerdBinary, containerdAddress, co
119119
"-namespace", ns,
120120
"-id", id,
121121
"-address", containerdAddress,
122-
"-ttrpc-address", containerdTTRPCAddress,
123122
}
124123
cmd := exec.Command(self, args...)
125124
cmd.Dir = cwd

runtime/v2/runc/v2/service.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ func newCommand(ctx context.Context, id, containerdBinary, containerdAddress, co
135135
"-namespace", ns,
136136
"-id", id,
137137
"-address", containerdAddress,
138-
"-ttrpc-address", containerdTTRPCAddress,
139138
}
140139
cmd := exec.Command(self, args...)
141140
cmd.Dir = cwd

runtime/v2/shim/shim.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,14 @@ var (
8989
socketFlag string
9090
bundlePath string
9191
addressFlag string
92-
ttrpcAddressFlag string
9392
containerdBinaryFlag string
9493
action string
9594
)
9695

96+
const (
97+
ttrpcAddressEnv = "TTRPC_ADDRESS"
98+
)
99+
97100
func parseFlags() {
98101
flag.BoolVar(&debugFlag, "debug", false, "enable debug output in logs")
99102
flag.StringVar(&namespaceFlag, "namespace", "", "namespace that owns the shim")
@@ -102,7 +105,6 @@ func parseFlags() {
102105
flag.StringVar(&bundlePath, "bundle", "", "path to the bundle if not workdir")
103106

104107
flag.StringVar(&addressFlag, "address", "", "grpc address back to main containerd")
105-
flag.StringVar(&ttrpcAddressFlag, "ttrpc-address", "", "ttrpc address back to main containerd")
106108
flag.StringVar(&containerdBinaryFlag, "publish-binary", "containerd", "path to publish binary (used for publishing events)")
107109

108110
flag.Parse()
@@ -165,7 +167,9 @@ func run(id string, initFunc Init, config Config) error {
165167
}
166168
}
167169

168-
publisher, err := newPublisher(ttrpcAddressFlag)
170+
ttrpcAddress := os.Getenv(ttrpcAddressEnv)
171+
172+
publisher, err := newPublisher(ttrpcAddress)
169173
if err != nil {
170174
return err
171175
}
@@ -204,7 +208,7 @@ func run(id string, initFunc Init, config Config) error {
204208
}
205209
return nil
206210
case "start":
207-
address, err := service.StartShim(ctx, idFlag, containerdBinaryFlag, addressFlag, ttrpcAddressFlag)
211+
address, err := service.StartShim(ctx, idFlag, containerdBinaryFlag, addressFlag, ttrpcAddress)
208212
if err != nil {
209213
return err
210214
}

runtime/v2/shim/util.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ func Command(ctx context.Context, runtime, containerdAddress, containerdTTRPCAdd
5050
args := []string{
5151
"-namespace", ns,
5252
"-address", containerdAddress,
53-
"-ttrpc-address", containerdTTRPCAddress,
5453
"-publish-binary", self,
5554
}
5655
args = append(args, cmdArgs...)
@@ -96,7 +95,11 @@ func Command(ctx context.Context, runtime, containerdAddress, containerdTTRPCAdd
9695

9796
cmd := exec.Command(cmdPath, args...)
9897
cmd.Dir = path
99-
cmd.Env = append(os.Environ(), "GOMAXPROCS=2")
98+
cmd.Env = append(
99+
os.Environ(),
100+
"GOMAXPROCS=2",
101+
fmt.Sprintf("%s=%s", ttrpcAddressEnv, containerdTTRPCAddress),
102+
)
100103
cmd.SysProcAttr = getSysProcAttr()
101104
if opts != nil {
102105
d, err := proto.Marshal(opts)

0 commit comments

Comments
 (0)