move gc to lib and add in registry config

Signed-off-by: Meina Zhou <meinaz@vmware.com>
This commit is contained in:
Meina Zhou 2019-02-11 17:26:21 +08:00
parent c41fe12746
commit 761599198c
23 changed files with 262 additions and 56 deletions

121
src/portal/cust.yaml Normal file
View File

@ -0,0 +1,121 @@
# Default values for docker-registry.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.
replicaCount: 1
updateStrategy:
# type: RollingUpdate
# rollingUpdate:
# maxSurge: 1
# maxUnavailable: 0
podAnnotations: {}
image:
repository: registry
tag: 2.6.2
pullPolicy: IfNotPresent
# imagePullSecrets:
# - name: docker
service:
name: registry
type: NodePort
# clusterIP:
#port: 5000
nodePort: 30001
annotations: {}
# foo.io/bar: "true"
ingress:
enabled: false
path: /
# Used to create an Ingress record.
hosts:
- chart-example.local
annotations:
# kubernetes.io/ingress.class: nginx
# kubernetes.io/tls-acme: "true"
labels: {}
tls:
# Secrets must be manually created in the namespace.
# - secretName: chart-example-tls
# hosts:
# - chart-example.local
resources: {}
# We usually recommend not to specify default resources and to leave this as a conscious
# choice for the user. This also increases chances charts run on environments with little
# resources, such as Minikube. If you do want to specify resources, uncomment the following
# lines, adjust them as necessary, and remove the curly braces after 'resources:'.
# limits:
# cpu: 100m
# memory: 128Mi
# requests:
# cpu: 100m
# memory: 128Mi
persistence:
accessMode: 'ReadWriteOnce'
enabled: false
size: 10Gi
# storageClass: '-'
# set the type of filesystem to use: filesystem, s3
storage: filesystem
# Set this to name of secret for tls certs
# tlsSecretName: registry.docker.example.com
secrets:
haSharedSecret: ""
htpasswd: ""
# Secrets for Azure
# azure:
# accountName: ""
# accountKey: ""
# container: ""
# Secrets for S3 access and secret keys
# s3:
# accessKey: ""
# secretKey: ""
# Secrets for Swift username and password
# swift:
# username: ""
# password: ""
# Options for s3 storage type:
# s3:
# region: us-east-1
# bucket: my-bucket
# encrypt: false
# secure: true
# Options for swift storage type:
# swift:
# authurl: http://swift.example.com/
# container: my-container
configData:
version: 0.1
log:
fields:
service: registry
storage:
cache:
blobdescriptor: inmemory
http:
addr: :5000
headers:
X-Content-Type-Options: [nosniff]
health:
storagedriver:
enabled: true
interval: 10s
threshold: 3
securityContext:
enabled: true
runAsUser: 1000
fsGroup: 1000
priorityClassName: ""
nodeSelector: {}
tolerations: []

View File

@ -1,47 +1,62 @@
import { Injectable } from '@angular/core';
import { Injectable, Inject } from '@angular/core';
import { Http } from '@angular/http';
import { throwError as observableThrowError, Observable } from 'rxjs';
import { catchError, map } from 'rxjs/operators';
import { SERVICE_CONFIG, IServiceConfig } from "../../service.config";
export abstract class GcApiRepository {
abstract postSchedule(param): Observable<any>;
abstract putSchedule(param): Observable<any>;
abstract getSchedule(): Observable<any>;
abstract getLog(id): Observable<any>;
abstract getStatus(id): Observable<any>;
abstract getJobs(): Observable<any>;
}
@Injectable()
export class GcApiRepository {
export class GcApiDefaultRepository extends GcApiRepository {
constructor(
private http: Http,
@Inject(SERVICE_CONFIG) private config: IServiceConfig
) {
super();
}
public postSchedule(param): Observable<any> {
return this.http.post("/api/system/gc/schedule", param)
return this.http.post(`${this.config.gcEndpoint}/schedule`, param)
.pipe(catchError(error => observableThrowError(error)));
}
public putSchedule(param): Observable<any> {
return this.http.put("/api/system/gc/schedule", param)
return this.http.put(`${this.config.gcEndpoint}/schedule`, param)
.pipe(catchError(error => observableThrowError(error)));
}
public getSchedule(): Observable<any> {
return this.http.get("/api/system/gc/schedule")
return this.http.get(`${this.config.gcEndpoint}/schedule`)
.pipe(catchError(error => observableThrowError(error)))
.pipe(map(response => response.json()));
}
public getLog(id): Observable<any> {
return this.http.get("/api/system/gc/" + id + "/log")
return this.http.get(`${this.config.gcEndpoint}/${id}/log`)
.pipe(catchError(error => observableThrowError(error)));
}
public getStatus(id): Observable<any> {
return this.http.get("/api/system/gc/" + id)
return this.http.get(`${this.config.gcEndpoint}/id`)
.pipe(catchError(error => observableThrowError(error)))
.pipe(map(response => response.json()));
}
public getJobs(): Observable<any> {
return this.http.get("/api/system/gc")
return this.http.get(`${this.config.gcEndpoint}`)
.pipe(catchError(error => observableThrowError(error)))
.pipe(map(response => response.json()));
}

View File

@ -0,0 +1,61 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { GcComponent } from './gc.component';
import { SERVICE_CONFIG, IServiceConfig } from '../../service.config';
import { GcApiRepository, GcApiDefaultRepository} from './gc.api.repository';
import { GcRepoService } from './gc.service';
import { SharedModule } from "../../shared/shared.module";
import { ErrorHandler } from '../../error-handler/error-handler';
import { GcViewModelFactory } from './gc.viewmodel.factory';
import { GcUtility } from './gc.utility';
import { of } from 'rxjs';
describe('GcComponent', () => {
let component: GcComponent;
let fixture: ComponentFixture<GcComponent>;
let gcRepoService: GcRepoService;
let config: IServiceConfig = {
systemInfoEndpoint: "/api/system/gc"
};
let mockSchedule = [];
let mockJobs = [
{
id: 22222,
schedule: null,
job_status: 'string',
creation_time: new Date(),
update_time: new Date(),
}
];
let spySchedule: jasmine.Spy;
let spyJobs: jasmine.Spy;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
SharedModule
],
declarations: [ GcComponent ],
providers: [
{ provide: GcApiRepository, useClass: GcApiDefaultRepository },
{ provide: SERVICE_CONFIG, useValue: config },
GcRepoService,
ErrorHandler,
GcViewModelFactory,
GcUtility
]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(GcComponent);
component = fixture.componentInstance;
gcRepoService = fixture.debugElement.injector.get(GcRepoService);
spySchedule = spyOn(gcRepoService, "getSchedule").and.returnValues(of(mockSchedule));
spyJobs = spyOn(gcRepoService, "getJobs").and.returnValues(of(mockJobs));
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -5,7 +5,7 @@ import { GcViewModelFactory } from "./gc.viewmodel.factory";
import { GcRepoService } from "./gc.service";
import { WEEKDAYS, SCHEDULE_TYPE, ONE_MINITUE, THREE_SECONDS} from './gc.const';
import { GcUtility } from './gc.utility';
import { ErrorHandler } from '@harbor/ui';
import { ErrorHandler } from '../../error-handler/index';
@Component({
selector: 'gc-config',

View File

@ -3,9 +3,10 @@ import { Http } from '@angular/http';
import { Observable, Subscription, Subject, of } from 'rxjs';
import { catchError, map } from 'rxjs/operators';
import { GcApiRepository } from './gc.api.repository';
import { ErrorHandler } from '@harbor/ui';
import { ErrorHandler } from '../../error-handler/index';
import { GcJobData } from './gcLog';
@Injectable()
export class GcRepoService {

View File

@ -0,0 +1,7 @@
export * from "./gc.component";
export * from "./gc.const";
export * from "./gc.api.repository";
export * from "./gc.service";
export * from "./gc.utility";
export * from "./gc.viewmodel.factory";
export * from "./gcLog";

View File

@ -4,15 +4,19 @@ import { ReplicationConfigComponent } from './replication/replication-config.com
import { SystemSettingsComponent } from './system/system-settings.component';
import { VulnerabilityConfigComponent } from './vulnerability/vulnerability-config.component';
import { RegistryConfigComponent } from './registry-config.component';
import { GcComponent } from './gc/gc.component';
export * from './config';
export * from './replication/replication-config.component';
export * from './system/system-settings.component';
export * from './vulnerability/vulnerability-config.component';
export * from './registry-config.component';
export * from './gc/index';
export const CONFIGURATION_DIRECTIVES: Type<any>[] = [
ReplicationConfigComponent,
GcComponent,
SystemSettingsComponent,
VulnerabilityConfigComponent,
RegistryConfigComponent

View File

@ -13,5 +13,11 @@
<vulnerability-config *ngIf="withClair" #vulnerabilityConfig [(vulnerabilityConfig)]="config" [showSubTitle]="true"></vulnerability-config>
</clr-tab-content>
</clr-tab>
<clr-tab>
<button id="config-gc" clrTabLink>{{'CONFIG.GC' | translate}}</button>
<clr-tab-content id="gc" *clrIfActive>
<gc-config #gcConfig></gc-config>
</clr-tab-content>
</clr-tab>
</clr-tabs>
<confirmation-dialog #cfgConfirmationDialog (confirmAction)="confirmCancel($event)"></confirmation-dialog>

View File

@ -8,6 +8,7 @@ import { SystemSettingsComponent } from './system/system-settings.component';
import { VulnerabilityConfigComponent } from './vulnerability/vulnerability-config.component';
import { RegistryConfigComponent } from './registry-config.component';
import { ConfirmationDialogComponent } from '../confirmation-dialog/confirmation-dialog.component';
import { GcComponent } from './gc/gc.component';
import {
ConfigurationService,
@ -62,7 +63,8 @@ describe('RegistryConfigComponent (inline template)', () => {
SystemSettingsComponent,
VulnerabilityConfigComponent,
RegistryConfigComponent,
ConfirmationDialogComponent
ConfirmationDialogComponent,
GcComponent
],
providers: [
ErrorHandler,

View File

@ -13,7 +13,7 @@ import {
clone
} from '../utils';
import { ErrorHandler } from '../error-handler/index';
import { SystemSettingsComponent, VulnerabilityConfigComponent} from './index';
import { SystemSettingsComponent, VulnerabilityConfigComponent, GcComponent} from './index';
import { Configuration } from './config';
@Component({
@ -30,6 +30,7 @@ export class RegistryConfigComponent implements OnInit {
@ViewChild("systemSettings") systemSettings: SystemSettingsComponent;
@ViewChild("vulnerabilityConfig") vulnerabilityCfg: VulnerabilityConfigComponent;
@ViewChild("gc") gc: GcComponent;
@ViewChild("cfgConfirmationDialog") confirmationDlg: ConfirmationDialogComponent;
constructor(

View File

@ -58,6 +58,10 @@ import {
RetagService,
RetagDefaultService
} from './service/index';
import { GcRepoService } from './config/gc/gc.service';
import { GcUtility } from './config/gc/gc.utility';
import {GcViewModelFactory} from './config/gc/gc.viewmodel.factory';
import {GcApiRepository, GcApiDefaultRepository} from './config/gc/gc.api.repository';
import {
ErrorHandler,
DefaultErrorHandler
@ -97,7 +101,8 @@ export const DefaultServiceConfig: IServiceConfig = {
scanJobEndpoint: "/api/jobs/scan",
labelEndpoint: "/api/labels",
helmChartEndpoint: "/api/chartrepo",
downloadChartEndpoint: "/chartrepo"
downloadChartEndpoint: "/chartrepo",
gcEndpoint: "/api/system/gc"
};
/**
@ -151,6 +156,9 @@ export interface HarborModuleConfig {
// Service implementation for helmchart
helmChartService?: Provider;
// Service implementation for gc
gcApiRepository?: Provider;
}
/**
@ -248,8 +256,9 @@ export class HarborLibraryModule {
config.configService || { provide: ConfigurationService, useClass: ConfigurationDefaultService },
config.jobLogService || { provide: JobLogService, useClass: JobLogDefaultService },
config.projectPolicyService || { provide: ProjectService, useClass: ProjectDefaultService },
config.labelService || {provide: LabelService, useClass: LabelDefaultService},
config.helmChartService || {provide: HelmChartService, useClass: HelmChartDefaultService},
config.labelService || { provide: LabelService, useClass: LabelDefaultService },
config.helmChartService || { provide: HelmChartService, useClass: HelmChartDefaultService },
config.gcApiRepository || {provide: GcApiRepository, useClass: GcApiDefaultRepository},
// Do initializing
TranslateServiceInitializer,
{
@ -259,7 +268,10 @@ export class HarborLibraryModule {
multi: true
},
ChannelService,
OperationService
OperationService,
GcRepoService,
GcViewModelFactory,
GcUtility
]
};
}
@ -283,8 +295,12 @@ export class HarborLibraryModule {
config.projectPolicyService || { provide: ProjectService, useClass: ProjectDefaultService },
config.labelService || {provide: LabelService, useClass: LabelDefaultService},
config.helmChartService || {provide: HelmChartService, useClass: HelmChartDefaultService},
config.gcApiRepository || {provide: GcApiRepository, useClass: GcApiDefaultRepository},
ChannelService,
OperationService
OperationService,
GcRepoService,
GcViewModelFactory,
GcUtility
]
};
}

View File

@ -26,3 +26,4 @@ export * from './repository-gridview/index';
export * from './operation/index';
export * from './_animations/index';
export * from './helm-chart/index';

View File

@ -237,4 +237,6 @@ export interface IServiceConfig {
* * {string}
*/
downloadChartEndpoint?: string;
gcEndpoint?: string;
}

View File

@ -15,8 +15,7 @@ import { Component, OnInit, OnDestroy, ViewChild } from '@angular/core';
import { Subscription } from "rxjs";
import {
Configuration, StringValueItem, SystemSettingsComponent, VulnerabilityConfigComponent,
isEmpty, clone, getChanges
} from '@harbor/ui';
isEmpty, clone, getChanges, GcComponent, GcRepoService } from '@harbor/ui';
import { ConfirmationTargets, ConfirmationState } from '../shared/shared.const';
import { SessionService } from '../shared/session.service';
@ -26,7 +25,6 @@ import { MessageHandlerService } from '../shared/message-handler/message-handler
import { AppConfigService } from '../app-config.service';
import { ConfigurationAuthComponent } from './auth/config-auth.component';
import { ConfigurationEmailComponent } from './email/config-email.component';
import { GcComponent } from './gc/gc.component';
import { ConfigurationService } from './config.service';

View File

@ -11,6 +11,7 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import { NgModule } from '@angular/core';
import { CoreModule } from '../core/core.module';
import { SharedModule } from '../shared/shared.module';
@ -20,12 +21,6 @@ import { ConfigurationService } from './config.service';
import { ConfirmMessageHandler } from './config.msg.utils';
import { ConfigurationAuthComponent } from './auth/config-auth.component';
import { ConfigurationEmailComponent } from './email/config-email.component';
import { GcComponent } from './gc/gc.component';
import { GcRepoService } from './gc/gc.service';
import { GcApiRepository } from './gc/gc.api.repository';
import { GcViewModelFactory } from './gc/gc.viewmodel.factory';
import { GcUtility } from './gc/gc.utility';
@NgModule({
imports: [
@ -35,10 +30,10 @@ import { GcUtility } from './gc/gc.utility';
declarations: [
ConfigurationComponent,
ConfigurationAuthComponent,
ConfigurationEmailComponent,
GcComponent
ConfigurationEmailComponent
],
exports: [ConfigurationComponent],
providers: [ConfigurationService, GcRepoService, GcApiRepository, GcViewModelFactory, GcUtility, ConfirmMessageHandler]
providers: [ConfigurationService, ConfirmMessageHandler]
})
export class ConfigurationModule { }

View File

@ -1,25 +0,0 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { GcComponent } from './gc.component';
describe('GcComponent', () => {
let component: GcComponent;
let fixture: ComponentFixture<GcComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ GcComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(GcComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -74,7 +74,8 @@ const uiLibConfig: IServiceConfig = {
scanJobEndpoint: "/api/jobs/scan",
labelEndpoint: "/api/labels",
helmChartEndpoint: "/api/chartrepo",
downloadChartEndpoint: "/chartrepo"
downloadChartEndpoint: "/chartrepo",
gcEndpoint: "/api/system/gc"
};
@NgModule({