mirror of
https://github.com/goharbor/harbor.git
synced 2025-02-17 04:11:24 +01:00
refactor preheat model (#14858)
Move the notification to preheat models Signed-off-by: Wang Yan <wangyan@vmware.com>
This commit is contained in:
parent
17dd48e5a3
commit
ad9569da26
@ -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"
|
@ -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: ¬ification.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)
|
||||||
|
@ -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 = ¬ification.Notification{
|
||||||
Events: []cm.Event{},
|
Events: []notification.Event{},
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := json.Unmarshal(data, payload); err != nil {
|
if err := json.Unmarshal(data, payload); err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user