refactor preheat model (#14858)

Move the notification to preheat models

Signed-off-by: Wang Yan <wangyan@vmware.com>
This commit is contained in:
Wang Yan 2021-05-12 22:29:01 +08:00 committed by GitHub
parent 17dd48e5a3
commit ad9569da26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 10 deletions

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package models package notification
import ( import (
"time" "time"

View File

@ -3,11 +3,11 @@ package provider
import ( import (
"errors" "errors"
"fmt" "fmt"
"github.com/goharbor/harbor/src/pkg/p2p/preheat/models/notification"
"strings" "strings"
"time" "time"
"github.com/docker/distribution/manifest/schema2" "github.com/docker/distribution/manifest/schema2"
cm "github.com/goharbor/harbor/src/common/models"
"github.com/goharbor/harbor/src/common/utils" "github.com/goharbor/harbor/src/common/utils"
"github.com/goharbor/harbor/src/pkg/p2p/preheat/models/provider" "github.com/goharbor/harbor/src/pkg/p2p/preheat/models/provider"
"github.com/goharbor/harbor/src/pkg/p2p/preheat/provider/auth" "github.com/goharbor/harbor/src/pkg/p2p/preheat/provider/auth"
@ -67,13 +67,13 @@ func (kd *KrakenDriver) Preheat(preheatingImage *PreheatImage) (*PreheatingStatu
} }
url := fmt.Sprintf("%s%s", strings.TrimSuffix(kd.instance.Endpoint, "/"), krakenPreheatPath) url := fmt.Sprintf("%s%s", strings.TrimSuffix(kd.instance.Endpoint, "/"), krakenPreheatPath)
var events = make([]cm.Event, 0) var events = make([]notification.Event, 0)
eventID := utils.GenerateRandomString() eventID := utils.GenerateRandomString()
event := cm.Event{ event := notification.Event{
ID: eventID, ID: eventID,
TimeStamp: time.Now().UTC(), TimeStamp: time.Now().UTC(),
Action: "push", Action: "push",
Target: &cm.Target{ Target: &notification.Target{
MediaType: schema2.MediaTypeManifest, MediaType: schema2.MediaTypeManifest,
Digest: preheatingImage.Digest, Digest: preheatingImage.Digest,
Repository: preheatingImage.ImageName, Repository: preheatingImage.ImageName,
@ -82,7 +82,7 @@ func (kd *KrakenDriver) Preheat(preheatingImage *PreheatImage) (*PreheatingStatu
}, },
} }
events = append(events, event) events = append(events, event)
var payload = cm.Notification{ var payload = notification.Notification{
Events: events, Events: events,
} }
_, err := client.GetHTTPClient(kd.instance.Insecure).Post(url, kd.getCred(), payload, nil) _, err := client.GetHTTPClient(kd.instance.Insecure).Post(url, kd.getCred(), payload, nil)

View File

@ -16,13 +16,12 @@ package provider
import ( import (
"encoding/json" "encoding/json"
"github.com/goharbor/harbor/src/pkg/p2p/preheat/models/notification"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"strings" "strings"
"time" "time"
cm "github.com/goharbor/harbor/src/common/models"
) )
// This is a package to provide mock utilities. // This is a package to provide mock utilities.
@ -111,8 +110,8 @@ func MockKrakenProvider() *httptest.Server {
return return
} }
var payload = &cm.Notification{ var payload = &notification.Notification{
Events: []cm.Event{}, Events: []notification.Event{},
} }
if err := json.Unmarshal(data, payload); err != nil { if err := json.Unmarshal(data, payload); err != nil {