Skip to content

Commit

Permalink
clean up code (#557)
Browse files Browse the repository at this point in the history
Signed-off-by: Ziming Zhang <zziming@vmware.com>
  • Loading branch information
bitsf committed Apr 19, 2021
1 parent d07de09 commit e50adfe
Show file tree
Hide file tree
Showing 28 changed files with 37 additions and 102 deletions.
4 changes: 2 additions & 2 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ builds:
- -X github.com/goharbor/harbor-operator.OperatorVersion={{ if .Tag }}{{ .Tag }}{{ else }}dev{{ end }}

dockers:
- image_templates:
- holyhope/harbor-operator:{{ .Tag }}
- image_templates:
- goharbor/harbor-operator:{{ .Tag }}

changelog:
sort: asc
Expand Down
4 changes: 2 additions & 2 deletions apis/goharbor.io/v1alpha3/chartmuseum_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@ type ChartMuseumChartSpec struct {

// +kubebuilder:validation:Optional
// +kubebuilder:validation:Pattern="https?://.*"
// The absolute url for .tgzs in index.yaml
// The absolute url for .tgz files in index.yaml
URL string `json:"url,omitempty"`

// +kubebuilder:validation:Optional
// +kubebuilder:default=true
// Allow chart versions to be re-uploaded without ?force querystring
AllowOvewrite *bool `json:"allowOverwrite,omitempty"`
AllowOverwrite *bool `json:"allowOverwrite,omitempty"`

// +kubebuilder:validation:Optional
// +kubebuilder:default=false
Expand Down
5 changes: 0 additions & 5 deletions apis/goharbor.io/v1alpha3/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,4 @@ import "errors"
var (
ErrNoStorageConfiguration = errors.New("no storage configuration")
Err2StorageConfiguration = errors.New("only 1 storage can be configured")

ErrNoMigrationConfiguration = errors.New("no migration source configuration")
Err2MigrationConfiguration = errors.New("only 1 migration source can be configured")

ErrWrongURLFormat = errors.New("wrong url format")
)
4 changes: 0 additions & 4 deletions apis/goharbor.io/v1alpha3/exporter_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,6 @@ type ExporterCoreSpec struct {
URL string `json:"url"`
}

const (
ExporterDatabaseType = "postgresql"
)

type ExporterDatabaseSpec struct {
harbormetav1.PostgresConnectionWithParameters `json:",inline"`

Expand Down
19 changes: 0 additions & 19 deletions apis/goharbor.io/v1alpha3/harbor_secret_format.go

This file was deleted.

2 changes: 0 additions & 2 deletions apis/goharbor.io/v1alpha3/harbor_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -641,8 +641,6 @@ func (r *HarborInternalTLSSpec) IsEnabled() bool {
return r != nil && r.Enabled
}

const CertificateAuthoritySecretConfigKey = "certificate-authority-secret"

func (r *HarborInternalTLSSpec) GetScheme() string {
if !r.IsEnabled() {
return "http"
Expand Down
2 changes: 0 additions & 2 deletions apis/goharbor.io/v1alpha3/harborcluster_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ func (hc *HarborCluster) SetupWebhookWithManager(ctx context.Context, mgr ctrl.M
Complete()
}

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!

// +kubebuilder:webhook:path=/mutate-goharbor-io-v1alpha3-harborcluster,mutating=true,failurePolicy=fail,groups=goharbor.io,resources=harborclusters,verbs=create;update,versions=v1alpha3,name=mharborcluster.kb.io,admissionReviewVersions={"v1beta1"},sideEffects=None

var _ webhook.Defaulter = &HarborCluster{}
Expand Down
6 changes: 0 additions & 6 deletions apis/goharbor.io/v1alpha3/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,3 @@ package v1alpha3
const (
HarborClassAnnotation = "goharbor.io/harbor-class"
)

const (
WarningLabel = "goharbor-io/warning"
OperatorNameLabel = "goharbor-io/controller"
OperatorVersionLabel = "goharbor-io/version"
)
5 changes: 0 additions & 5 deletions apis/goharbor.io/v1alpha3/notaryserver_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,6 @@ type NotaryServerSpec struct {
MigrationEnabled *bool `json:"migrationEnabled,omitempty"`
}

const (
NotaryServerTrustRemoteType = "remote"
NotaryServerTrustLocalType = "local"
)

type NotaryServerTrustServiceSpec struct {
// +kubebuilder:validation:Optional
Remote *NotaryServerTrustServiceRemoteSpec `json:"remote,omitempty"`
Expand Down
5 changes: 0 additions & 5 deletions apis/goharbor.io/v1alpha3/registry_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

const (
RegistryCorePublicURLKey = "REGISTRY_HTTP_HOST"
RegistryAuthURLKey = "REGISTRY_AUTH_TOKEN_REALM" // RegistryCorePublicURLKey + "/service/token"
)

// +genclient

// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
Expand Down
4 changes: 2 additions & 2 deletions apis/goharbor.io/v1alpha3/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions apis/meta/v1alpha1/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,6 @@ func (p *PostgresConnectTimeout) Add(query url.Values) {
// in the client (LC_CTYPE environment variable on Unix systems).
type PostgresClientEncoding string

const PostgresClientEncodingKey = "client_encoding"

func (p *PostgresClientEncoding) Add(query url.Values) {
if p == nil {
return
Expand Down
2 changes: 1 addition & 1 deletion config/config/assets/chartmuseum-config.yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ tls:
port: 8080
{{- end }}

allow.overwrite: {{ .Spec.Chart.AllowOvewrite }}
allow.overwrite: {{ .Spec.Chart.AllowOverwrite }}

auth:
anonymous.get: {{ .Spec.Authentication.AnonymousGet }}
Expand Down
4 changes: 2 additions & 2 deletions controllers/goharbor/harbor/chartmuseum.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (r *Reconciler) GetChartMuseum(ctx context.Context, harbor *goharborv1.Harb

publicURL, err := url.Parse(harbor.Spec.ExternalURL)
if err != nil {
return nil, errors.Wrap(err, "cannot parseexternalURL")
return nil, errors.Wrap(err, "cannot parse externalURL")
}

chartServerURL := ""
Expand Down Expand Up @@ -109,7 +109,7 @@ func (r *Reconciler) GetChartMuseum(ctx context.Context, harbor *goharborv1.Harb
Redis: &redis,
},
Chart: goharborv1.ChartMuseumChartSpec{
AllowOvewrite: &varTrue,
AllowOverwrite: &varTrue,
Storage: goharborv1.ChartMuseumChartStorageSpec{
ChartMuseumChartStorageDriverSpec: r.ChartMuseumStorage(ctx, harbor),
MaxStorageObjects: &maxStorageObjects,
Expand Down
5 changes: 0 additions & 5 deletions controllers/goharbor/harbor/harbor.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package harbor
import (
"context"
"net/url"
"time"

goharborv1 "github.com/goharbor/harbor-operator/apis/goharbor.io/v1alpha3"
"github.com/goharbor/harbor-operator/controllers"
Expand All @@ -20,10 +19,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/controller"
)

const (
DefaultRequeueWait = 2 * time.Second
)

// Reconciler reconciles a Harbor object.
type Reconciler struct {
*commonCtrl.Controller
Expand Down
4 changes: 1 addition & 3 deletions controllers/goharbor/harbor/ingresses.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ import (
)

const (
DefaultIngressAnnotationsEnabled = true
IngressAnnotationsEnabledCOnfigKey = "ingress-annotations-enabled"
NCPIngressValueTrue = "true"
NCPIngressValueTrue = "true"
)

type CoreIngress graph.Resource
Expand Down
10 changes: 4 additions & 6 deletions controllers/goharbor/harbor/notary.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
"github.com/pkg/errors"
)

const NotaryMigrationGithubCredentialsConfigKey = "notary-migration-github-credentials"

const NotaryMigrationGithubSourceConfigKey = "notary-migration-github-source"

type GithubSource struct {
Expand All @@ -28,9 +26,9 @@ func (r *Reconciler) GetDefaultNotaryMigrationSource() (*GithubSource, error) {
item, err := configstore.Filter().
Slice(NotaryMigrationGithubSourceConfigKey).
Unmarshal(func() interface{} {
copy := defaultSource
c := defaultSource

return &copy
return &c
}).
GetFirstItem()
if err != nil {
Expand All @@ -41,10 +39,10 @@ func (r *Reconciler) GetDefaultNotaryMigrationSource() (*GithubSource, error) {
return nil, err
}

config, err := item.Unmarshaled()
c, err := item.Unmarshaled()
if err != nil {
return nil, errors.Wrap(err, "invalid")
}

return config.(*GithubSource), nil
return c.(*GithubSource), nil
}
2 changes: 1 addition & 1 deletion controllers/goharbor/harbor/notarysigner.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func (r *Reconciler) GetNotarySignerEncryptionKey(ctx context.Context, harbor *g
name := r.NormalizeName(ctx, harbor.GetName(), controllers.NotarySigner.String(), "encryption-key")
namespace := harbor.GetNamespace()

secret, err := password.Generate(CoreSecretPasswordLength, CoreSecretPasswordNumDigits, CoreSecretPasswordNumSpecials, false, true)
secret, err := password.Generate(NotarySignerEncryptionKeyLength, NotarySignerEncryptionKeyNumDigits, NotarySignerEncryptionKeyNumSpecials, false, true)
if err != nil {
return nil, errors.Wrap(err, "cannot generate secret")
}
Expand Down
4 changes: 2 additions & 2 deletions manifests/cluster/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1154,7 +1154,7 @@ spec:
type: object
type: object
url:
description: The absolute url for .tgzs in index.yaml
description: The absolute url for .tgz files in index.yaml
pattern: https?://.*
type: string
required:
Expand Down Expand Up @@ -21011,7 +21011,7 @@ data:
port: 8080
{{- end }}

allow.overwrite: {{ .Spec.Chart.AllowOvewrite }}
allow.overwrite: {{ .Spec.Chart.AllowOverwrite }}

auth:
anonymous.get: {{ .Spec.Authentication.AnonymousGet }}
Expand Down
6 changes: 3 additions & 3 deletions manifests/harbor/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1151,7 +1151,7 @@ spec:
type: object
type: object
url:
description: The absolute url for .tgzs in index.yaml
description: The absolute url for .tgz files in index.yaml
pattern: https?://.*
type: string
required:
Expand Down Expand Up @@ -13414,7 +13414,7 @@ data:
port: 8080
{{- end }}

allow.overwrite: {{ .Spec.Chart.AllowOvewrite }}
allow.overwrite: {{ .Spec.Chart.AllowOverwrite }}

auth:
anonymous.get: {{ .Spec.Authentication.AnonymousGet }}
Expand Down Expand Up @@ -13770,7 +13770,7 @@ spec:
fieldPath: metadata.namespace
- name: CONFIGURATION_FROM
value: env,file:/etc/harbor-operator/config.yaml
image: goharbor/harbor-operator:latest
image: goharbor/harbor-operator:dev_master
livenessProbe:
httpGet:
path: /healthz
Expand Down
2 changes: 1 addition & 1 deletion manifests/harbor/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ resources:
images:
- name: goharbor/harbor-operator
newName: goharbor/harbor-operator
newTag: latest
newTag: dev_master
6 changes: 0 additions & 6 deletions pkg/controller/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package controller

import (
"context"
"time"

serrors "github.com/goharbor/harbor-operator/pkg/controller/errors"
"github.com/goharbor/harbor-operator/pkg/factories/application"
Expand All @@ -13,11 +12,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
)

const (
RetryDuration = 30 * time.Second
RetryDelay = time.Second
)

var force = true

func (c *Controller) Apply(ctx context.Context, res *Resource) error {
Expand Down
16 changes: 8 additions & 8 deletions pkg/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const (
)

func New(ctx context.Context, scheme *runtime.Scheme) (manager.Manager, error) {
var mgrConfig manager.Options = ctrl.Options{
mgrConfig := ctrl.Options{
MetricsBindAddress: fmt.Sprintf(":%d", MetricsPort),
LeaderElection: false,
Port: WebHookPort,
Expand All @@ -37,22 +37,22 @@ func New(ctx context.Context, scheme *runtime.Scheme) (manager.Manager, error) {
Slice(ManagerConfigKey).
Unmarshal(func() interface{} {
// Duplicate mgrConfig
config := mgrConfig
c := mgrConfig

return &config
return &c
}).
GetFirstItem()
if err != nil {
if !config.IsNotFound(err, ManagerConfigKey) {
return nil, errors.Wrap(err, "cannot get configuration")
}
} else {
config, err := item.Unmarshaled()
c, err := item.Unmarshaled()
if err != nil {
return nil, errors.Wrap(err, "unable to get configuration")
}

mgrConfig = *config.(*manager.Options)
mgrConfig = *c.(*manager.Options)
}

logger.Get(ctx).Info(
Expand All @@ -65,16 +65,16 @@ func New(ctx context.Context, scheme *runtime.Scheme) (manager.Manager, error) {
"LeaderElection.ID", mgrConfig.LeaderElectionID,
)

config, err := ctrl.GetConfig()
c, err := ctrl.GetConfig()
if err != nil {
return nil, errors.Wrap(err, "unable to get rest configuration")
}

config.WrapTransport = transport.Wrappers(func(rt http.RoundTripper) http.RoundTripper {
c.WrapTransport = transport.Wrappers(func(rt http.RoundTripper) http.RoundTripper {
return &nettracing.Transport{RoundTripper: rt}
})

mgr, err := ctrl.NewManager(config, mgrConfig)
mgr, err := ctrl.NewManager(c, mgrConfig)

return mgr, errors.Wrap(err, "unable to get the manager")
}
4 changes: 2 additions & 2 deletions pkg/setup/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
"github.com/goharbor/harbor-operator/controllers/goharbor/harbor"
"github.com/goharbor/harbor-operator/controllers/goharbor/harborcluster"
"github.com/goharbor/harbor-operator/controllers/goharbor/jobservice"
notaryserver "github.com/goharbor/harbor-operator/controllers/goharbor/notaryserver"
notarysigner "github.com/goharbor/harbor-operator/controllers/goharbor/notarysigner"
"github.com/goharbor/harbor-operator/controllers/goharbor/notaryserver"
"github.com/goharbor/harbor-operator/controllers/goharbor/notarysigner"
"github.com/goharbor/harbor-operator/controllers/goharbor/portal"
"github.com/goharbor/harbor-operator/controllers/goharbor/registry"
"github.com/goharbor/harbor-operator/controllers/goharbor/registryctl"
Expand Down
2 changes: 1 addition & 1 deletion pkg/template/generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/opentracing/opentracing-go"
"github.com/pkg/errors"
runtime "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/template/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"

corev1 "k8s.io/api/core/v1"
runtime "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
)

Expand Down

0 comments on commit e50adfe

Please sign in to comment.