Skip to content
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

OSTree Plugin Updates #33

Merged
merged 2 commits into from
Jan 25, 2024
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
1 change: 0 additions & 1 deletion build/mage/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ var binaries = map[string]binaryConfig{
"CGO_ENABLED": "1",
},
excludedPlatforms: map[dagger.Platform]struct{}{
"linux/arm64": {},
"linux/s390x": {},
"linux/ppc64le": {},
"linux/arm/v6": {},
Expand Down
File renamed without changes.
File renamed without changes.
16 changes: 16 additions & 0 deletions internal/plugins/ostree/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,22 @@ func (p *Plugin) AddRemote(ctx context.Context, repository string, properties *a
return p.repositoryManager.Get(ctx, repository).AddRemote(ctx, properties)
}

func (p *Plugin) UpdateRemote(ctx context.Context, repository string, remoteName string, properties *apiv1.OSTreeRemoteProperties) (err error) {
if err := checkRepository(repository); err != nil {
return err
}

return p.repositoryManager.Get(ctx, repository).UpdateRemote(ctx, remoteName, properties)
}

func (p *Plugin) DeleteRemote(ctx context.Context, repository string, remoteName string) (err error) {
if err := checkRepository(repository); err != nil {
return err
}

return p.repositoryManager.Get(ctx, repository).DeleteRemote(ctx, remoteName)
}

func (p *Plugin) SyncRepository(ctx context.Context, repository string, properties *apiv1.OSTreeRepositorySyncRequest) (err error) {
if err := checkRepository(repository); err != nil {
return err
Expand Down
9 changes: 9 additions & 0 deletions internal/plugins/ostree/pkg/libostree/pull_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,15 @@ func TestRepo_Pull(t *testing.T) {
assert.Error(t, err)
})

t.Run("should create then delete remote", func(t *testing.T) {
remoteToDelete := "delete-me"
err := repo.AddRemote(remoteToDelete, remoteURL, NoGPGVerify())
assert.NoError(t, err)

err = repo.DeleteRemote(remoteToDelete)
assert.NoError(t, err)
})

t.Run("should list remotes", func(t *testing.T) {
remotes := repo.ListRemotes()
assert.Equal(t, remotes, []string{remoteName})
Expand Down
83 changes: 81 additions & 2 deletions internal/plugins/ostree/pkg/ostreerepository/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,60 @@ func (h *Handler) AddRemote(ctx context.Context, remote *apiv1.OSTreeRemotePrope
}, SkipPull())
}

func (h *Handler) UpdateRemote(ctx context.Context, remoteName string, remote *apiv1.OSTreeRemoteProperties) (err error) {
// Transition to provisioning state
if err := h.setState(StateProvisioning); err != nil {
return err
}
defer h.clearState()

if !h.checkRepoExists(ctx) {
return ctl.Errf("repository does not exist")
}

return h.BeginLocalRepoTransaction(ctx, func(ctx context.Context, repo *libostree.Repo) (bool, error) {
// Delete user provided remote
if err := repo.DeleteRemote(remoteName); err != nil {
// No need to make error pretty, it is already pretty
return false, err
}

// Add user provided remote
var opts []libostree.Option
if remote.NoGPGVerify {
opts = append(opts, libostree.NoGPGVerify())
}
if err := repo.AddRemote(remote.Name, remote.RemoteURL, opts...); err != nil {
// No need to make error pretty, it is already pretty
return false, err
}

return true, nil
}, SkipPull())
}
kyleishie marked this conversation as resolved.
Show resolved Hide resolved

func (h *Handler) DeleteRemote(ctx context.Context, remoteName string) (err error) {
// Transition to provisioning state
if err := h.setState(StateProvisioning); err != nil {
return err
}
defer h.clearState()

if !h.checkRepoExists(ctx) {
return ctl.Errf("repository does not exist")
}

return h.BeginLocalRepoTransaction(ctx, func(ctx context.Context, repo *libostree.Repo) (bool, error) {
// Delete user provided remote
if err := repo.DeleteRemote(remoteName); err != nil {
// No need to make error pretty, it is already pretty
return false, err
}

return true, nil
}, SkipPull())
}

func (h *Handler) SyncRepository(_ context.Context, properties *apiv1.OSTreeRepositorySyncRequest) (err error) {
// Transition to syncing state
if err := h.setState(StateSyncing); err != nil {
Expand All @@ -187,7 +241,7 @@ func (h *Handler) SyncRepository(_ context.Context, properties *apiv1.OSTreeRepo
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()

err = h.BeginLocalRepoTransaction(ctx, func(ctx context.Context, repo *libostree.Repo) (bool, error) {
err = h.BeginLocalRepoTransaction(ctx, func(ctx context.Context, repo *libostree.Repo) (commit bool, transactionFnErr error) {
// Pull the latest changes from the remote.
opts := []libostree.Option{
libostree.Depth(properties.Depth),
Expand All @@ -197,8 +251,33 @@ func (h *Handler) SyncRepository(_ context.Context, properties *apiv1.OSTreeRepo
opts = append(opts, libostree.Refs(properties.Refs...))
}

remoteName := properties.Remote
if properties.EphemeralRemote != nil {
remoteName = properties.EphemeralRemote.Name

var opts []libostree.Option
if properties.EphemeralRemote.NoGPGVerify {
opts = append(opts, libostree.NoGPGVerify())
}

if err := repo.AddRemote(properties.EphemeralRemote.Name, properties.EphemeralRemote.RemoteURL, opts...); err != nil {
// No need to make error pretty, it is already pretty
return false, err
}

defer func() {
if transactionFnErr == nil {
if err := repo.DeleteRemote(properties.EphemeralRemote.Name); err != nil {
h.logger.Error("deleting ephemeral remote", "error", err.Error())
commit = false
transactionFnErr = err
}
}
}()
}

// pull remote content into local repo
if err := repo.Pull(ctx, properties.Remote, opts...); err != nil {
if err := repo.Pull(ctx, remoteName, opts...); err != nil {
return false, ctl.Errf("pulling ostree repository: %s", err)
}

Expand Down
File renamed without changes.
File renamed without changes.
15 changes: 15 additions & 0 deletions pkg/plugins/ostree/api/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,13 @@ type OSTreeRemoteProperties struct {

type OSTreeRepositorySyncRequest struct {
// Remote - The name of the remote to sync.
// Remote and EphemeralRemote are mutually exclusive. EphemeralRemote takes precedence.
Remote string `json:"remote"`

// EphemeralRemote - A remote to add to the repository in Beskar for the duration of the sync.
// Remote and EphemeralRemote are mutually exclusive. EphemeralRemote takes precedence.
EphemeralRemote *OSTreeRemoteProperties `json:"ephemeral_remote"`

// Refs - The branches/refs to mirror. Leave empty to mirror all branches/refs.
Refs []string `json:"refs"`

Expand Down Expand Up @@ -88,6 +93,16 @@ type OSTree interface {
//kun:success statusCode=200
AddRemote(ctx context.Context, repository string, properties *OSTreeRemoteProperties) (err error)

// Updates a remote in the OSTree repository. If it doesn't exist it will be created.
//kun:op PUT /repository/remote
//kun:success statusCode=200
UpdateRemote(ctx context.Context, repository string, remoteName string, properties *OSTreeRemoteProperties) (err error)

// Delete an existing remote to the OSTree repository.
//kun:op DELETE /repository/remote
//kun:success statusCode=200
DeleteRemote(ctx context.Context, repository string, remoteName string) (err error)

// Sync an ostree repository with one of the configured remotes.
//kun:op POST /repository/sync
//kun:success statusCode=202
Expand Down
76 changes: 76 additions & 0 deletions pkg/plugins/ostree/api/v1/endpoint.go

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

60 changes: 60 additions & 0 deletions pkg/plugins/ostree/api/v1/http.go

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

Loading
Loading