Skip to content

Commit

Permalink
Fix #214 Upgrade CRD to v1 and remove Legacy Ingress
Browse files Browse the repository at this point in the history
Signed-off-by: Ricardo Zanini <[email protected]>
  • Loading branch information
ricardozanini committed Sep 4, 2021
1 parent f8f095f commit 845234b
Show file tree
Hide file tree
Showing 17 changed files with 4,297 additions and 4,664 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)
# Image URL to use all building/pushing image targets
IMG ?= controller:latest
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
CRD_OPTIONS ?= "crd:trivialVersions=true"
CRD_OPTIONS ?= "crd:trivialVersions=true,crdVersions=v1"

# Image URL for the operator final image
OPERATOR_IMG ?= quay.io/m88i/nexus-operator:$(VERSION)
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,12 @@ If you have any questions please either [open an issue](https://github.com/m88i/
## Pre Requisites

- [`kubectl` installed](https://kubernetes.io/docs/tasks/tools/install-kubectl/)
- Kubernetes or OpenShift cluster available (minishift, minikube or crc also supported)
- Kubernetes (1.12+) or OpenShift (4.5+) cluster available (minikube or crc also supported)
- Cluster admin credentials to install the Operator

> Note: since version 0.6.0 we do not support OpenShift 3.11 or Kubernetes 1.11 anymore.
> If you need to install in these clusters, please use version [0.5.0](https://github.com/m88i/nexus-operator/releases/tag/v0.5.0) instead.
## Quick Install

The installation procedure will create a Namespace named `nexus-operator-system` and will install every resources needed for the operator to run:
Expand All @@ -77,7 +80,7 @@ Use these examples as a starting point to customize the server to meet your requ

### Openshift

If you're running the Operator on Openshift (3.11 or 4.x+) and **you're not using Red Hat image with persistence enabled**, that's anything other than `spec.useRedHatImage: true` and `spec.persistence.persistent: true`,
If you're running the Operator on Openshift (4.5+) and **you're not using Red Hat image with persistence enabled**, that's anything other than `spec.useRedHatImage: true` and `spec.persistence.persistent: true`,
it's also necessary to configure a [Security Context Constraints](https://docs.openshift.com/container-platform/3.11/admin_guide/manage_scc.html) (SCC) resource.

This is necessary because the Nexus image requires its container to be ran as UID 200.
Expand Down
2,383 changes: 1,191 additions & 1,192 deletions bundle/manifests/apps.m88i.io_nexus.yaml

Large diffs are not rendered by default.

3,734 changes: 1,885 additions & 1,849 deletions config/crd/bases/apps.m88i.io_nexus.yaml

Large diffs are not rendered by default.

79 changes: 0 additions & 79 deletions controllers/nexus/resource/networking/legacy_ingress.go

This file was deleted.

92 changes: 0 additions & 92 deletions controllers/nexus/resource/networking/legacy_ingress_test.go

This file was deleted.

47 changes: 5 additions & 42 deletions controllers/nexus/resource/networking/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/RHsyseng/operator-utils/pkg/resource/compare"
routev1 "github.com/openshift/api/route/v1"
networkingv1 "k8s.io/api/networking/v1"
networkingv1beta1 "k8s.io/api/networking/v1beta1"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/m88i/nexus-operator/api/v1alpha1"
Expand All @@ -46,7 +45,7 @@ type Manager struct {
managedObjectsRef map[string]resource.KubernetesResource
shouldIgnoreUpdates bool

routeAvailable, ingressAvailable, legacyIngressAvailable bool
routeAvailable, ingressAvailable bool
}

// NewManager creates a networking resources manager
Expand All @@ -69,17 +68,9 @@ func NewManager(nexus *v1alpha1.Nexus, client client.Client) (*Manager, error) {
return nil, fmt.Errorf(discFailureFormat, "ingresses", err)
}

legacyIngressAvailable, err := discovery.IsLegacyIngressAvailable()
if err != nil {
return nil, fmt.Errorf(discFailureFormat, "v1beta1 ingresses", err)
}

if ingressAvailable {
mgr.ingressAvailable = true
mgr.managedObjectsRef[kind.IngressKind] = &networkingv1.Ingress{}
} else if legacyIngressAvailable {
mgr.legacyIngressAvailable = true
mgr.managedObjectsRef[kind.IngressKind] = &networkingv1beta1.Ingress{}
}

if routeAvailable {
Expand Down Expand Up @@ -110,7 +101,7 @@ func (m *Manager) GetRequiredResources() ([]resource.KubernetesResource, error)
resources = append(resources, route)

case v1alpha1.IngressExposeType:
if !m.ingressAvailable && !m.legacyIngressAvailable {
if !m.ingressAvailable {
return nil, fmt.Errorf(resUnavailableFormat, "ingresses")
}

Expand All @@ -130,14 +121,6 @@ func (m *Manager) createRoute() *routev1.Route {
}

func (m *Manager) createIngress() resource.KubernetesResource {
// we're only here if either ingress is available, no need to check if legacy is
if !m.ingressAvailable {
builder := newLegacyIngressBuilder(m.nexus)
if len(m.nexus.Spec.Networking.TLS.SecretName) > 0 {
builder = builder.withCustomTLS()
}
return builder.build()
}
builder := newIngressBuilder(m.nexus)
if len(m.nexus.Spec.Networking.TLS.SecretName) > 0 {
builder = builder.withCustomTLS()
Expand All @@ -159,8 +142,6 @@ func (m *Manager) GetCustomComparator(t reflect.Type) func(deployed resource.Kub
}

switch t {
case reflect.TypeOf(&networkingv1beta1.Ingress{}):
return legacyIngressEqual
case reflect.TypeOf(&networkingv1.Ingress{}):
return ingressEqual
default:
Expand All @@ -174,32 +155,14 @@ func (m *Manager) GetCustomComparators() map[reflect.Type]func(deployed resource
if m.shouldIgnoreUpdates {
m.log.Debug("Nexus configured to ignore Networking updates, won't compare current state and desired state for Ingress/Route")
return map[reflect.Type]func(deployed resource.KubernetesResource, requested resource.KubernetesResource) bool{
reflect.TypeOf(networkingv1beta1.Ingress{}): framework.AlwaysTrueComparator(),
reflect.TypeOf(networkingv1.Ingress{}): framework.AlwaysTrueComparator(),
reflect.TypeOf(routev1.Route{}): framework.AlwaysTrueComparator(),
reflect.TypeOf(networkingv1.Ingress{}): framework.AlwaysTrueComparator(),
reflect.TypeOf(routev1.Route{}): framework.AlwaysTrueComparator(),
}
}

return map[reflect.Type]func(deployed resource.KubernetesResource, requested resource.KubernetesResource) bool{
reflect.TypeOf(networkingv1beta1.Ingress{}): legacyIngressEqual,
reflect.TypeOf(networkingv1.Ingress{}): ingressEqual,
}
}

func legacyIngressEqual(deployed resource.KubernetesResource, requested resource.KubernetesResource) bool {
ingress1 := deployed.(*networkingv1beta1.Ingress)
ingress2 := requested.(*networkingv1beta1.Ingress)
var pairs [][2]interface{}
pairs = append(pairs, [2]interface{}{ingress1.Name, ingress2.Name})
pairs = append(pairs, [2]interface{}{ingress1.Namespace, ingress2.Namespace})
pairs = append(pairs, [2]interface{}{ingress1.Spec, ingress2.Spec})
pairs = append(pairs, [2]interface{}{ingress1.Annotations, ingress2.Annotations})

equal := compare.EqualPairs(pairs)
if !equal {
logger.GetLogger("networking_manager").Info("Resources are not equal", "deployed", deployed, "requested", requested)
reflect.TypeOf(networkingv1.Ingress{}): ingressEqual,
}
return equal
}

func ingressEqual(deployed resource.KubernetesResource, requested resource.KubernetesResource) bool {
Expand Down
Loading

0 comments on commit 845234b

Please sign in to comment.