1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-08-04 21:35:23 +02:00

feat(edge/update): select endpoints to update [EE-4043] (#7602)

This commit is contained in:
Chaim Lev-Ari 2022-09-18 14:42:18 +03:00 committed by GitHub
parent 36e7981ab7
commit 4d123895ea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
37 changed files with 1192 additions and 130 deletions

View file

@ -15,11 +15,11 @@ import (
)
type updatePayload struct {
Name string
GroupIDs []portainer.EdgeGroupID
Type edgetypes.UpdateScheduleType
Version string
Time int64
Name string
GroupIDs []portainer.EdgeGroupID
Environments map[portainer.EndpointID]string
Type edgetypes.UpdateScheduleType
Time int64
}
func (payload *updatePayload) Validate(r *http.Request) error {
@ -35,8 +35,8 @@ func (payload *updatePayload) Validate(r *http.Request) error {
return errors.New("Invalid schedule type")
}
if payload.Version == "" {
return errors.New("Invalid version")
if len(payload.Environments) == 0 {
return errors.New("No Environment is scheduled for update")
}
return nil
@ -80,7 +80,23 @@ func (handler *Handler) update(w http.ResponseWriter, r *http.Request) *httperro
item.GroupIDs = payload.GroupIDs
item.Time = payload.Time
item.Type = payload.Type
item.Version = payload.Version
item.Status = map[portainer.EndpointID]edgetypes.UpdateScheduleStatus{}
for environmentID, version := range payload.Environments {
environment, err := handler.dataStore.Endpoint().Endpoint(environmentID)
if err != nil {
return httperror.InternalServerError("Unable to retrieve environment from the database", err)
}
if environment.Type != portainer.EdgeAgentOnDockerEnvironment {
return httperror.BadRequest("Only standalone docker Environments are supported for remote update", nil)
}
item.Status[environmentID] = edgetypes.UpdateScheduleStatus{
TargetVersion: version,
CurrentVersion: environment.Agent.Version,
}
}
}
err = handler.dataStore.EdgeUpdateSchedule().Update(item.ID, item)