mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-22 18:25:56 +01:00
Update the migration sql
1. Update the migration sql 2. Rename the ResourceRepository from repository to image Signed-off-by: Wenkai Yin <yinw@vmware.com>
This commit is contained in:
parent
6e0d892963
commit
547c2337de
@ -62,15 +62,16 @@ UPDATE registry SET credential_type='basic';
|
||||
/*upgrade the replication_policy*/
|
||||
ALTER TABLE replication_policy ADD COLUMN creator varchar(256);
|
||||
ALTER TABLE replication_policy ADD COLUMN src_registry_id int;
|
||||
ALTER TABLE replication_policy ADD COLUMN src_namespaces varchar(256);
|
||||
/*if harbor is integrated with the external project service, the src_namespaces will be empty,
|
||||
which means the repilcation policy cannot work as expected*/
|
||||
UPDATE replication_policy r SET src_namespaces=(SELECT p.name FROM project p WHERE p.project_id=r.project_id);
|
||||
/*The predefined filters will be cleared and replaced by "project_name/"+double star.
|
||||
if harbor is integrated with the external project service, we cannot get the project name by ID,
|
||||
which means the repilcation policy will match all resources.*/
|
||||
UPDATE replication_policy r SET filters=(SELECT CONCAT('[{"type":"name","value":"', p.name,'/**"}]') FROM project p WHERE p.project_id=r.project_id);
|
||||
ALTER TABLE replication_policy RENAME COLUMN target_id TO dest_registry_id;
|
||||
ALTER TABLE replication_policy ALTER COLUMN dest_registry_id DROP NOT NULL;
|
||||
ALTER TABLE replication_policy ADD COLUMN dest_namespace varchar(256);
|
||||
ALTER TABLE replication_policy ADD COLUMN override boolean;
|
||||
ALTER TABLE replication_policy DROP COLUMN project_id;
|
||||
ALTER TABLE replication_policy RENAME COLUMN cron_str TO trigger;
|
||||
|
||||
DROP TRIGGER replication_immediate_trigger_update_time_at_modtime ON replication_immediate_trigger;
|
||||
DROP TABLE replication_immediate_trigger;
|
||||
@ -119,10 +120,11 @@ BEGIN
|
||||
LOOP
|
||||
/*insert one execution record*/
|
||||
INSERT INTO replication_execution (policy_id, start_time) VALUES (job.policy_id, job.creation_time) RETURNING id INTO execid;
|
||||
/*insert one task record*/
|
||||
/*insert one task record
|
||||
doesn't record the tags info in "src_resource" and "dst_resource" as the length
|
||||
of the tags may longer than the capability of the column*/
|
||||
INSERT INTO replication_task (execution_id, resource_type, src_resource, dst_resource, operation, job_id, status, start_time, end_time)
|
||||
VALUES (execid, 'image', CONCAT(job.repository,':[', job.tags,']'), CONCAT(job.repository,':[', job.tags,']'),
|
||||
job.operation, job.job_uuid, job.status, job.creation_time, job.update_time);
|
||||
VALUES (execid, 'image', job.repository, job.repository, job.operation, job.job_uuid, job.status, job.creation_time, job.update_time);
|
||||
END LOOP;
|
||||
END $$;
|
||||
UPDATE replication_task SET status='Pending' WHERE status='pending';
|
||||
|
@ -331,7 +331,7 @@ func (ra *RepositoryAPI) Delete() {
|
||||
e := &event.Event{
|
||||
Type: event.EventTypeImagePush,
|
||||
Resource: &model.Resource{
|
||||
Type: model.ResourceTypeRepository,
|
||||
Type: model.ResourceTypeImage,
|
||||
Metadata: &model.ResourceMetadata{
|
||||
Repository: &model.Repository{
|
||||
Name: repoName,
|
||||
|
@ -117,7 +117,7 @@ func (n *NotificationHandler) Post() {
|
||||
e := &rep_event.Event{
|
||||
Type: rep_event.EventTypeImagePush,
|
||||
Resource: &model.Resource{
|
||||
Type: model.ResourceTypeRepository,
|
||||
Type: model.ResourceTypeImage,
|
||||
Metadata: &model.ResourceMetadata{
|
||||
Repository: &model.Repository{
|
||||
Name: repository,
|
||||
|
@ -25,8 +25,8 @@ import (
|
||||
|
||||
// import chart transfer
|
||||
_ "github.com/goharbor/harbor/src/replication/transfer/chart"
|
||||
// import repository transfer
|
||||
_ "github.com/goharbor/harbor/src/replication/transfer/repository"
|
||||
// import image transfer
|
||||
_ "github.com/goharbor/harbor/src/replication/transfer/image"
|
||||
// register the Harbor adapter
|
||||
_ "github.com/goharbor/harbor/src/replication/adapter/harbor"
|
||||
// register the DockerHub adapter
|
||||
|
@ -58,7 +58,7 @@ func (a *adapter) Info() (*model.RegistryInfo, error) {
|
||||
return &model.RegistryInfo{
|
||||
Type: model.RegistryTypeDockerHub,
|
||||
SupportedResourceTypes: []model.ResourceType{
|
||||
model.ResourceTypeRepository,
|
||||
model.ResourceTypeImage,
|
||||
},
|
||||
SupportedResourceFilters: []*model.FilterStyle{
|
||||
{
|
||||
@ -307,7 +307,7 @@ func (a *adapter) FetchImages(filters []*model.Filter) ([]*model.Resource, error
|
||||
}
|
||||
|
||||
resources = append(resources, &model.Resource{
|
||||
Type: model.ResourceTypeRepository,
|
||||
Type: model.ResourceTypeImage,
|
||||
Registry: a.registry,
|
||||
Metadata: &model.ResourceMetadata{
|
||||
Repository: &model.Repository{
|
||||
|
@ -92,7 +92,7 @@ func (a *adapter) Info() (*model.RegistryInfo, error) {
|
||||
info := &model.RegistryInfo{
|
||||
Type: model.RegistryTypeHarbor,
|
||||
SupportedResourceTypes: []model.ResourceType{
|
||||
model.ResourceTypeRepository,
|
||||
model.ResourceTypeImage,
|
||||
},
|
||||
SupportedResourceFilters: []*model.FilterStyle{
|
||||
{
|
||||
|
@ -45,7 +45,7 @@ func TestInfo(t *testing.T) {
|
||||
assert.Equal(t, 2, len(info.SupportedResourceFilters))
|
||||
assert.Equal(t, 3, len(info.SupportedTriggers))
|
||||
assert.Equal(t, 2, len(info.SupportedResourceTypes))
|
||||
assert.Equal(t, model.ResourceTypeRepository, info.SupportedResourceTypes[0])
|
||||
assert.Equal(t, model.ResourceTypeImage, info.SupportedResourceTypes[0])
|
||||
assert.Equal(t, model.ResourceTypeChart, info.SupportedResourceTypes[1])
|
||||
server.Close()
|
||||
|
||||
@ -69,7 +69,7 @@ func TestInfo(t *testing.T) {
|
||||
assert.Equal(t, 2, len(info.SupportedResourceFilters))
|
||||
assert.Equal(t, 3, len(info.SupportedTriggers))
|
||||
assert.Equal(t, 1, len(info.SupportedResourceTypes))
|
||||
assert.Equal(t, model.ResourceTypeRepository, info.SupportedResourceTypes[0])
|
||||
assert.Equal(t, model.ResourceTypeImage, info.SupportedResourceTypes[0])
|
||||
server.Close()
|
||||
}
|
||||
|
||||
|
@ -89,7 +89,7 @@ func (a *adapter) FetchImages(filters []*model.Filter) ([]*model.Resource, error
|
||||
vtags = append(vtags, tag.Name)
|
||||
}
|
||||
resources = append(resources, &model.Resource{
|
||||
Type: model.ResourceTypeRepository,
|
||||
Type: model.ResourceTypeImage,
|
||||
Registry: a.registry,
|
||||
Metadata: &model.ResourceMetadata{
|
||||
Repository: &model.Repository{
|
||||
|
@ -70,7 +70,7 @@ func TestFetchImages(t *testing.T) {
|
||||
resources, err := adapter.FetchImages(nil)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, 1, len(resources))
|
||||
assert.Equal(t, model.ResourceTypeRepository, resources[0].Type)
|
||||
assert.Equal(t, model.ResourceTypeImage, resources[0].Type)
|
||||
assert.Equal(t, "library/hello-world", resources[0].Metadata.Repository.Name)
|
||||
assert.Equal(t, 2, len(resources[0].Metadata.Vtags))
|
||||
assert.Equal(t, "1.0", resources[0].Metadata.Vtags[0])
|
||||
@ -89,7 +89,7 @@ func TestFetchImages(t *testing.T) {
|
||||
resources, err = adapter.FetchImages(filters)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, 1, len(resources))
|
||||
assert.Equal(t, model.ResourceTypeRepository, resources[0].Type)
|
||||
assert.Equal(t, model.ResourceTypeImage, resources[0].Type)
|
||||
assert.Equal(t, "library/hello-world", resources[0].Metadata.Repository.Name)
|
||||
assert.Equal(t, 1, len(resources[0].Metadata.Vtags))
|
||||
assert.Equal(t, "1.0", resources[0].Metadata.Vtags[0])
|
||||
|
@ -40,7 +40,7 @@ func (adapter Adapter) Info() (*model.RegistryInfo, error) {
|
||||
registryInfo := model.RegistryInfo{
|
||||
Type: huawei,
|
||||
Description: "Adapter for SWR -- The image registry of Huawei Cloud",
|
||||
SupportedResourceTypes: []model.ResourceType{model.ResourceTypeRepository},
|
||||
SupportedResourceTypes: []model.ResourceType{model.ResourceTypeImage},
|
||||
SupportedResourceFilters: []*model.FilterStyle{},
|
||||
SupportedTriggers: []model.TriggerType{},
|
||||
}
|
||||
|
@ -96,7 +96,7 @@ func parseRepoQueryResultToResource(repo hwRepoQueryResult) *model.Resource {
|
||||
}
|
||||
resource.Deleted = false
|
||||
resource.Override = false
|
||||
resource.Type = model.ResourceTypeRepository
|
||||
resource.Type = model.ResourceTypeImage
|
||||
|
||||
return &resource
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ func (native) Info() (info *model.RegistryInfo, err error) {
|
||||
return &model.RegistryInfo{
|
||||
Type: registryTypeNative,
|
||||
SupportedResourceTypes: []model.ResourceType{
|
||||
model.ResourceTypeRepository,
|
||||
model.ResourceTypeImage,
|
||||
},
|
||||
SupportedResourceFilters: []*model.FilterStyle{
|
||||
{
|
||||
|
@ -47,7 +47,7 @@ func Test_native_Info(t *testing.T) {
|
||||
assert.Equal(t, 1, len(info.SupportedResourceTypes))
|
||||
assert.Equal(t, 2, len(info.SupportedResourceFilters))
|
||||
assert.Equal(t, 2, len(info.SupportedTriggers))
|
||||
assert.Equal(t, model.ResourceTypeRepository, info.SupportedResourceTypes[0])
|
||||
assert.Equal(t, model.ResourceTypeImage, info.SupportedResourceTypes[0])
|
||||
}
|
||||
|
||||
func Test_native_PrepareForPush(t *testing.T) {
|
||||
|
@ -52,7 +52,7 @@ func (n native) FetchImages(filters []*model.Filter) ([]*model.Resource, error)
|
||||
continue
|
||||
}
|
||||
resources = append(resources, &model.Resource{
|
||||
Type: model.ResourceTypeRepository,
|
||||
Type: model.ResourceTypeImage,
|
||||
Registry: n.registry,
|
||||
Metadata: &model.ResourceMetadata{
|
||||
Repository: &model.Repository{
|
||||
|
@ -13,8 +13,7 @@ type RepPolicy struct {
|
||||
DestNamespace string `orm:"column(dest_namespace)" json:"dest_namespace"`
|
||||
Override bool `orm:"column(override)" json:"override"`
|
||||
Enabled bool `orm:"column(enabled)" json:"enabled"`
|
||||
// TODO rename the db column to trigger
|
||||
Trigger string `orm:"column(cron_str)" json:"trigger"`
|
||||
Trigger string `orm:"column(trigger)" json:"trigger"`
|
||||
Filters string `orm:"column(filters)" json:"filters"`
|
||||
ReplicateDeletion bool `orm:"column(replicate_deletion)" json:"replicate_deletion"`
|
||||
CreationTime time.Time `orm:"column(creation_time);auto_now_add" json:"creation_time"`
|
||||
|
@ -16,7 +16,7 @@ package model
|
||||
|
||||
// the resource type
|
||||
const (
|
||||
ResourceTypeRepository ResourceType = "repository"
|
||||
ResourceTypeImage ResourceType = "image"
|
||||
ResourceTypeChart ResourceType = "chart"
|
||||
)
|
||||
|
||||
|
@ -123,7 +123,7 @@ func (f *fakedAdapter) Info() (*model.RegistryInfo, error) {
|
||||
return &model.RegistryInfo{
|
||||
Type: model.RegistryTypeHarbor,
|
||||
SupportedResourceTypes: []model.ResourceType{
|
||||
model.ResourceTypeRepository,
|
||||
model.ResourceTypeImage,
|
||||
model.ResourceTypeChart,
|
||||
},
|
||||
SupportedTriggers: []model.TriggerType{model.TriggerTypeManual},
|
||||
@ -139,7 +139,7 @@ func (f *fakedAdapter) HealthCheck() (model.HealthStatus, error) {
|
||||
func (f *fakedAdapter) FetchImages(namespace []string, filters []*model.Filter) ([]*model.Resource, error) {
|
||||
return []*model.Resource{
|
||||
{
|
||||
Type: model.ResourceTypeRepository,
|
||||
Type: model.ResourceTypeImage,
|
||||
Metadata: &model.ResourceMetadata{
|
||||
Repository: &model.Repository{
|
||||
Name: "library/hello-world",
|
||||
@ -217,7 +217,7 @@ func TestStartReplication(t *testing.T) {
|
||||
},
|
||||
}
|
||||
resource := &model.Resource{
|
||||
Type: model.ResourceTypeRepository,
|
||||
Type: model.ResourceTypeImage,
|
||||
Metadata: &model.ResourceMetadata{
|
||||
Repository: &model.Repository{
|
||||
Name: "library/hello-world",
|
||||
|
@ -81,7 +81,7 @@ func fetchResources(adapter adp.Adapter, policy *model.Policy) ([]*model.Resourc
|
||||
for _, typ := range resTypes {
|
||||
var res []*model.Resource
|
||||
var err error
|
||||
if typ == model.ResourceTypeRepository {
|
||||
if typ == model.ResourceTypeImage {
|
||||
// images
|
||||
reg, ok := adapter.(adp.ImageRegistry)
|
||||
if !ok {
|
||||
|
@ -39,7 +39,7 @@ func (f *fakedAdapter) Info() (*model.RegistryInfo, error) {
|
||||
return &model.RegistryInfo{
|
||||
Type: model.RegistryTypeHarbor,
|
||||
SupportedResourceTypes: []model.ResourceType{
|
||||
model.ResourceTypeRepository,
|
||||
model.ResourceTypeImage,
|
||||
model.ResourceTypeChart,
|
||||
},
|
||||
SupportedTriggers: []model.TriggerType{model.TriggerTypeManual},
|
||||
@ -55,7 +55,7 @@ func (f *fakedAdapter) HealthCheck() (model.HealthStatus, error) {
|
||||
func (f *fakedAdapter) FetchImages(filters []*model.Filter) ([]*model.Resource, error) {
|
||||
return []*model.Resource{
|
||||
{
|
||||
Type: model.ResourceTypeRepository,
|
||||
Type: model.ResourceTypeImage,
|
||||
Metadata: &model.ResourceMetadata{
|
||||
Repository: &model.Repository{
|
||||
Name: "library/hello-world",
|
||||
@ -211,7 +211,7 @@ func TestFetchResources(t *testing.T) {
|
||||
func TestFilterResources(t *testing.T) {
|
||||
resources := []*model.Resource{
|
||||
{
|
||||
Type: model.ResourceTypeRepository,
|
||||
Type: model.ResourceTypeImage,
|
||||
Metadata: &model.ResourceMetadata{
|
||||
Repository: &model.Repository{
|
||||
Name: "library/hello-world",
|
||||
|
@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package repository
|
||||
package image
|
||||
|
||||
import (
|
||||
"errors"
|
||||
@ -33,7 +33,7 @@ var (
|
||||
)
|
||||
|
||||
func init() {
|
||||
if err := trans.RegisterFactory(model.ResourceTypeRepository, factory); err != nil {
|
||||
if err := trans.RegisterFactory(model.ResourceTypeImage, factory); err != nil {
|
||||
log.Errorf("failed to register transfer factory: %v", err)
|
||||
}
|
||||
}
|
@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package repository
|
||||
package image
|
||||
|
||||
import (
|
||||
"bytes"
|
@ -24,6 +24,9 @@ import (
|
||||
|
||||
// Match returns whether the str matches the pattern
|
||||
func Match(pattern, str string) (bool, error) {
|
||||
if len(pattern) == 0 {
|
||||
return true, nil
|
||||
}
|
||||
return doublestar.Match(pattern, str)
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,7 @@ func TestMatch(t *testing.T) {
|
||||
}{
|
||||
{
|
||||
pattern: "",
|
||||
str: "",
|
||||
str: "library",
|
||||
match: true,
|
||||
},
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user