Skip to content

Commit

Permalink
cmd/root: randomize pivot container name
Browse files Browse the repository at this point in the history
This is a backport of
openshift/machine-config-operator#1285, which
for the 4.1 release should live here since we were still using the
separate pivot package.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1783621

Original cherry-picked commit message:

If podman has a bug and cannot cleanup container names, we'll be stuck
in the update process as seen in
https://bugzilla.redhat.com/show_bug.cgi?id=1775647.
Randomize container names with UUID to avoid that and I think it's
generally better to do this w/o cleaning up at the beginning every time.

Signed-off-by: Antonio Murdaca <runcom@linux.com>
  • Loading branch information
jlebon committed Dec 18, 2019
1 parent 8688a45 commit 883c9e2
Show file tree
Hide file tree
Showing 44 changed files with 1,896 additions and 9 deletions.
25 changes: 24 additions & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 11 additions & 6 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/openshift/pivot/utils"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"k8s.io/apimachinery/pkg/util/uuid"

imgref "github.com/containers/image/docker/reference"
)
Expand Down Expand Up @@ -307,11 +308,18 @@ func pullAndRebase(container string) (imgid string, changed bool) {
imgid = container
}

// Clean up a previous container
podmanRemove(types.PivotName)
// Clean up any previous container which used the old name
podmanRemove(types.OldPivotName)

containerName := types.PivotNamePrefix + string(uuid.NewUUID())

// `podman mount` wants a container, so let's make create a dummy one, but not run it
cid := utils.RunGetOut("podman", "create", "--net=none", "--name", types.PivotName, imgid)
cid := utils.RunGetOut("podman", "create", "--net=none", "--annotation=org.openshift.machineconfigoperator.pivot=true", "--name", containerName, imgid)

defer func() {
// Kill our dummy container
podmanRemove(containerName)
}()
// Use the container ID to find its mount point
mnt := utils.RunGetOut("podman", "mount", cid)
repo := fmt.Sprintf("%s/srv/repo", mnt)
Expand Down Expand Up @@ -350,9 +358,6 @@ func pullAndRebase(container string) (imgid string, changed bool) {
"--custom-origin-url", customURL,
"--custom-origin-description", "Managed by pivot tool")

// Kill our dummy container
podmanRemove(types.PivotName)

changed = true
return
}
Expand Down
5 changes: 3 additions & 2 deletions types/imageinspection.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import (
)

const (
// PivotName is literally the name of the new pivot
PivotName = "ostree-container-pivot"
OldPivotName = "ostree-container-pivot"
// PivotNamePrefix is literally the name prefix of the new pivot
PivotNamePrefix = "ostree-container-pivot-"
)

// ImageInspection is a public implementation of
Expand Down
9 changes: 9 additions & 0 deletions vendor/github.com/google/uuid/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions vendor/github.com/google/uuid/CONTRIBUTING.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions vendor/github.com/google/uuid/CONTRIBUTORS

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions vendor/github.com/google/uuid/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions vendor/github.com/google/uuid/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

80 changes: 80 additions & 0 deletions vendor/github.com/google/uuid/dce.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions vendor/github.com/google/uuid/doc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vendor/github.com/google/uuid/go.mod

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 53 additions & 0 deletions vendor/github.com/google/uuid/hash.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions vendor/github.com/google/uuid/marshal.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 883c9e2

Please sign in to comment.