Skip to content

Commit

Permalink
fix: make expose core ingress optional
Browse files Browse the repository at this point in the history
#955

Signed-off-by: Shou-En Hsiao <shouenhsiao@google.com>
  • Loading branch information
ShouEnHsiao authored and bitsf committed Nov 29, 2022
1 parent d17a102 commit 30d6d29
Show file tree
Hide file tree
Showing 14 changed files with 33 additions and 61 deletions.
9 changes: 6 additions & 3 deletions apis/goharbor.io/v1alpha3/harborcluster_conversion.go
Expand Up @@ -356,7 +356,8 @@ func Convert_v1alpha3_HarborExposeSpec_To_v1beta1_HarborExposeSpec(src *HarborEx

func Convert_v1alpha3_HarborExposeComponentSpec_To_v1beta1_HarborExposeComponentSpec(src *HarborExposeComponentSpec, dst *v1beta1.HarborExposeComponentSpec) { //nolint
if src.Ingress != nil {
Convert_v1alpha3_HarborExposeIngressSpec_To_v1beta1_HarborExposeIngressSpec(src.Ingress, &dst.Ingress)
dst.Ingress = &v1beta1.HarborExposeIngressSpec{}
Convert_v1alpha3_HarborExposeIngressSpec_To_v1beta1_HarborExposeIngressSpec(src.Ingress, dst.Ingress)
}

if src.TLS != nil {
Expand Down Expand Up @@ -755,8 +756,10 @@ func Convert_v1beta1_HarborExposeSpec_To_v1alpha3_HarborExposeSpec(src *v1beta1.
}

func Convert_v1beta1_HarborExposeComponentSpec_To_v1alpha3_HarborExposeComponentSpec(src *v1beta1.HarborExposeComponentSpec, dst *HarborExposeComponentSpec) { //nolint
dst.Ingress = &HarborExposeIngressSpec{}
Convert_v1beta1_HarborExposeIngressSpec_To_v1alpha3_HarborExposeIngressSpec(&src.Ingress, dst.Ingress)
if src.Ingress != nil {
dst.Ingress = &HarborExposeIngressSpec{}
Convert_v1beta1_HarborExposeIngressSpec_To_v1alpha3_HarborExposeIngressSpec(src.Ingress, dst.Ingress)
}

if src.TLS != nil {
dst.TLS = src.TLS
Expand Down
4 changes: 2 additions & 2 deletions apis/goharbor.io/v1beta1/harbor_types.go
Expand Up @@ -741,8 +741,8 @@ type HarborExposeComponentSpec struct {
// +kubebuilder:validation:Optional
TLS *harbormetav1.ComponentsTLSSpec `json:"tls,omitempty"`

// +kubebuilder:validation:Required
Ingress HarborExposeIngressSpec `json:"ingress"`
// +kubebuilder:validation:Optional
Ingress *HarborExposeIngressSpec `json:"ingress,omitempty"`
}

type HarborExposeIngressSpec struct {
Expand Down
4 changes: 2 additions & 2 deletions apis/goharbor.io/v1beta1/harborcluster_webhook.go
Expand Up @@ -229,8 +229,8 @@ func (harborcluster *HarborCluster) validateStorage() *field.Error { //nolint:go
}

if redirect != nil && redirect.Enable {
if redirect.Expose == nil {
return required(rp.Child("expose"))
if redirect.Expose == nil || redirect.Expose.Ingress == nil {
return required(rp.Child("ingress"))
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion apis/goharbor.io/v1beta1/zz_generated.deepcopy.go

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

12 changes: 0 additions & 12 deletions charts/harbor-operator/templates/crds.yaml
Expand Up @@ -9693,8 +9693,6 @@ spec:
pattern: '[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*'
type: string
type: object
required:
- ingress
type: object
notary:
description: The ingress of the notary, required when notary component
Expand Down Expand Up @@ -9728,8 +9726,6 @@ spec:
pattern: '[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*'
type: string
type: object
required:
- ingress
type: object
required:
- core
Expand Down Expand Up @@ -10786,8 +10782,6 @@ spec:
pattern: '[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*'
type: string
type: object
required:
- ingress
type: object
required:
- enable
Expand Down Expand Up @@ -11195,8 +11189,6 @@ spec:
pattern: '[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*'
type: string
type: object
required:
- ingress
type: object
required:
- enable
Expand Down Expand Up @@ -14693,8 +14685,6 @@ spec:
pattern: '[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*'
type: string
type: object
required:
- ingress
type: object
notary:
description: The ingress of the notary, required when notary component
Expand Down Expand Up @@ -14728,8 +14718,6 @@ spec:
pattern: '[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*'
type: string
type: object
required:
- ingress
type: object
required:
- core
Expand Down
4 changes: 3 additions & 1 deletion controllers/goharbor/harbor/core.go
Expand Up @@ -405,7 +405,9 @@ func (r *Reconciler) GetCore(ctx context.Context, harbor *goharborv1.Harbor) (*g
harbormetav1.NetworkPoliciesAnnotationName: harbormetav1.NetworkPoliciesAnnotationDisabled,
}

annotation[harbormetav1.IngressControllerAnnotationName] = string(harbor.Spec.Expose.Core.Ingress.Controller)
if harbor.Spec.Expose.Core.Ingress != nil {
annotation[harbormetav1.IngressControllerAnnotationName] = string(harbor.Spec.Expose.Core.Ingress.Controller)
}

return &goharborv1.Core{
ObjectMeta: metav1.ObjectMeta{
Expand Down
6 changes: 5 additions & 1 deletion controllers/goharbor/harbor/ingresses.go
Expand Up @@ -32,6 +32,10 @@ func (r *Reconciler) AddCoreIngress(ctx context.Context, harbor *goharborv1.Harb
}

func (r *Reconciler) GetCoreIngress(ctx context.Context, harbor *goharborv1.Harbor) (*netv1.Ingress, error) {
if harbor.Spec.Expose.Core.Ingress == nil {
return nil, nil
}

var tls []netv1.IngressTLS

if harbor.Spec.Expose.Core.TLS.Enabled() {
Expand Down Expand Up @@ -113,7 +117,7 @@ func (r *Reconciler) GetNotaryServerIngress(ctx context.Context, harbor *goharbo
return nil, nil
}

if harbor.Spec.Expose.Notary == nil {
if harbor.Spec.Expose.Notary.Ingress == nil {
return nil, nil
}

Expand Down
4 changes: 3 additions & 1 deletion controllers/goharbor/harbor/notaryserver.go
Expand Up @@ -195,7 +195,9 @@ func (r *Reconciler) GetNotaryServer(ctx context.Context, harbor *goharborv1.Har
harbormetav1.NetworkPoliciesAnnotationName: harbormetav1.NetworkPoliciesAnnotationDisabled,
}

annotation[harbormetav1.IngressControllerAnnotationName] = string(harbor.Spec.Expose.Core.Ingress.Controller)
if harbor.Spec.Expose.Core.Ingress != nil {
annotation[harbormetav1.IngressControllerAnnotationName] = string(harbor.Spec.Expose.Core.Ingress.Controller)
}

return &goharborv1.NotaryServer{
ObjectMeta: metav1.ObjectMeta{
Expand Down
4 changes: 3 additions & 1 deletion controllers/goharbor/harbor/portal.go
Expand Up @@ -59,7 +59,9 @@ func (r *Reconciler) GetPortal(ctx context.Context, harbor *goharborv1.Harbor) (
harbormetav1.NetworkPoliciesAnnotationName: harbormetav1.NetworkPoliciesAnnotationDisabled,
}

annotation[harbormetav1.IngressControllerAnnotationName] = string(harbor.Spec.Expose.Core.Ingress.Controller)
if harbor.Spec.Expose.Core.Ingress != nil {
annotation[harbormetav1.IngressControllerAnnotationName] = string(harbor.Spec.Expose.Core.Ingress.Controller)
}

return &goharborv1.Portal{
ObjectMeta: metav1.ObjectMeta{
Expand Down
9 changes: 0 additions & 9 deletions controllers/goharbor/harbor_test.go
Expand Up @@ -147,15 +147,6 @@ func setupValidHarbor(ctx context.Context, ns string) (Resource, client.ObjectKe
ExternalURL: publicURL.String(),
HarborAdminPasswordRef: adminSecretName,
Version: test.GetVersion(),
Expose: goharborv1.HarborExposeSpec{
Core: goharborv1.HarborExposeComponentSpec{
TLS: nil,
Ingress: goharborv1.HarborExposeIngressSpec{
Host: "core.goharbor.io",
},
},
Notary: nil,
},
ImageChartStorage: &goharborv1.HarborStorageImageChartStorageSpec{
FileSystem: &goharborv1.HarborStorageImageChartStorageFileSystemSpec{
RegistryPersistentVolume: goharborv1.HarborStorageRegistryPersistentVolumeSpec{
Expand Down
12 changes: 0 additions & 12 deletions manifests/cluster/deployment.yaml
Expand Up @@ -9712,8 +9712,6 @@ spec:
pattern: '[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*'
type: string
type: object
required:
- ingress
type: object
notary:
description: The ingress of the notary, required when notary component
Expand Down Expand Up @@ -9747,8 +9745,6 @@ spec:
pattern: '[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*'
type: string
type: object
required:
- ingress
type: object
required:
- core
Expand Down Expand Up @@ -10805,8 +10801,6 @@ spec:
pattern: '[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*'
type: string
type: object
required:
- ingress
type: object
required:
- enable
Expand Down Expand Up @@ -11214,8 +11208,6 @@ spec:
pattern: '[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*'
type: string
type: object
required:
- ingress
type: object
required:
- enable
Expand Down Expand Up @@ -14717,8 +14709,6 @@ spec:
pattern: '[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*'
type: string
type: object
required:
- ingress
type: object
notary:
description: The ingress of the notary, required when notary component
Expand Down Expand Up @@ -14752,8 +14742,6 @@ spec:
pattern: '[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*'
type: string
type: object
required:
- ingress
type: object
required:
- core
Expand Down
12 changes: 0 additions & 12 deletions manifests/harbor/deployment.yaml
Expand Up @@ -9712,8 +9712,6 @@ spec:
pattern: '[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*'
type: string
type: object
required:
- ingress
type: object
notary:
description: The ingress of the notary, required when notary component
Expand Down Expand Up @@ -9747,8 +9745,6 @@ spec:
pattern: '[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*'
type: string
type: object
required:
- ingress
type: object
required:
- core
Expand Down Expand Up @@ -10805,8 +10801,6 @@ spec:
pattern: '[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*'
type: string
type: object
required:
- ingress
type: object
required:
- enable
Expand Down Expand Up @@ -11214,8 +11208,6 @@ spec:
pattern: '[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*'
type: string
type: object
required:
- ingress
type: object
required:
- enable
Expand Down Expand Up @@ -14717,8 +14709,6 @@ spec:
pattern: '[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*'
type: string
type: object
required:
- ingress
type: object
notary:
description: The ingress of the notary, required when notary component
Expand Down Expand Up @@ -14752,8 +14742,6 @@ spec:
pattern: '[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*'
type: string
type: object
required:
- ingress
type: object
required:
- core
Expand Down
4 changes: 2 additions & 2 deletions pkg/cluster/controllers/storage/ingress.go
Expand Up @@ -31,8 +31,8 @@ func (m *MinIOController) applyIngress(ctx context.Context, harborcluster *gohar
m.Log.Info("Redirect of MinIO is not enabled")

return m.cleanupIngress(ctx, harborcluster)
} else if redirect.Expose == nil {
err := errors.New("Expose should be defined when redirect enabled")
} else if redirect.Expose == nil || redirect.Expose.Ingress == nil {
err := errors.New("Expose.Ingress should be defined when redirect enabled")

return minioNotReadyStatus(UpdateIngressError, err.Error()), err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/cluster/controllers/storage/tenant.go
Expand Up @@ -82,8 +82,8 @@ func (m *MinIOController) getMinIOProperties(ctx context.Context, harborcluster
if redirect != nil && redirect.Enable {
storageSpec.Redirect.Disable = false

if redirect.Expose == nil {
return nil, errors.New("Expose should be defined when redirect enabled")
if redirect.Expose == nil || redirect.Expose.Ingress == nil {
return nil, errors.New("Expose.Ingress should be defined when redirect enabled")
}

tls = redirect.Expose.TLS
Expand Down

0 comments on commit 30d6d29

Please sign in to comment.