Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closes #140 - Upgrading to kubebuilder format and SDK 1.0.1 #175

Merged
merged 3 commits into from
Oct 16, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ test: generate-installer fmt vet bundle
sed -i "/pipefail/d" ${ENVTEST_ASSETS_DIR}/setup-envtest.sh
source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test ./... -coverprofile cover.out

# Run the OLM test on CI
ci-olm-test:
./hack/ci/load-operator-image.sh
./hack/ci/operator-olm-test.sh

generate-installer: generate manifests kustomize
cd config/manager && $(KUSTOMIZE) edit set image controller=$(OPERATOR_IMG)
$(KUSTOMIZE) build config/default > nexus-operator.yaml
Expand Down Expand Up @@ -146,3 +141,16 @@ bundle: manifests
.PHONY: bundle-build
bundle-build:
$(BUILDER) build -f bundle.Dockerfile -t $(BUNDLE_IMG) .


#################### CUSTOM NEXUS OPERATOR TASKS ######################
# Run the OLM test on CI
ci-olm-test:
./hack/ci/load-operator-image.sh
./hack/ci/operator-olm-test.sh

.PHONY: pr-prep
create_namespace=true
run_with_image=true
pr-prep:
CREATE_NAMESPACE=$(create_namespace) RUN_WITH_IMAGE=$(run_with_image) ./hack/pr-prep.sh
4 changes: 2 additions & 2 deletions controllers/nexus/resource/deployment/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ func NewManager(nexus *v1alpha1.Nexus, client client.Client) *Manager {

// GetRequiredResources returns the resources initialized by the manager
func (m *Manager) GetRequiredResources() ([]resource.KubernetesResource, error) {
m.log.Debug("Generating required", "resource", framework.DeploymentKind)
m.log.Debug("Generating required", "resource", framework.ServiceKind)
m.log.Debug("Generating required resource", "kind", framework.DeploymentKind)
m.log.Debug("Generating required resource", "kind", framework.ServiceKind)
return []resource.KubernetesResource{newDeployment(m.nexus), newService(m.nexus)}, nil
}

Expand Down
4 changes: 2 additions & 2 deletions controllers/nexus/resource/networking/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (m *Manager) GetRequiredResources() ([]resource.KubernetesResource, error)
return nil, fmt.Errorf(resUnavailableFormat, "routes")
}

m.log.Debug("Generating required", "resources", framework.RouteKind)
m.log.Debug("Generating required resource", "kind", framework.RouteKind)
route := m.createRoute()
resources = append(resources, route)

Expand All @@ -106,7 +106,7 @@ func (m *Manager) GetRequiredResources() ([]resource.KubernetesResource, error)
return nil, fmt.Errorf(resUnavailableFormat, "ingresses")
}

m.log.Debug("Generating required", "resources", framework.IngressKind)
m.log.Debug("Generating required resource", "kind", framework.IngressKind)
ingress := m.createIngress()
resources = append(resources, ingress)
}
Expand Down
2 changes: 1 addition & 1 deletion controllers/nexus/resource/persistence/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (m *Manager) GetRequiredResources() ([]resource.KubernetesResource, error)
return resources, nil
}

m.log.Debug("Generating required", "resource", framework.PVCKind)
m.log.Debug("Generating required resource", "kind", framework.PVCKind)
pvc := newPVC(m.nexus)
resources = append(resources, pvc)

Expand Down
4 changes: 2 additions & 2 deletions controllers/nexus/resource/security/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ func NewManager(nexus *v1alpha1.Nexus, client client.Client) *Manager {

// GetRequiredResources returns the resources initialized by the Manager
func (m *Manager) GetRequiredResources() ([]resource.KubernetesResource, error) {
m.log.Debug("Generating required", "resource", framework.SvcAccountKind)
m.log.Debug("Generating required", "resource", framework.SecretKind)
m.log.Debug("Generating required resource", "kind", framework.SvcAccountKind)
m.log.Debug("Generating required resource", "kind", framework.SecretKind)
return []resource.KubernetesResource{defaultServiceAccount(m.nexus), defaultSecret(m.nexus)}, nil
}

Expand Down
14 changes: 7 additions & 7 deletions controllers/nexus/resource/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,32 +87,32 @@ func (v *Validator) validateNetworking(nexus *v1alpha1.Nexus) error {
}

if !v.ingressAvailable && nexus.Spec.Networking.ExposeAs == v1alpha1.IngressExposeType {
v.log.Info("Ingresses are not available on your cluster. Make sure to be running Kubernetes > 1.14 or if you're running Openshift set ", "spec.networking.exposeAs", v1alpha1.IngressExposeType, "Also try", v1alpha1.NodePortExposeType)
v.log.Warn("Ingresses are not available on your cluster. Make sure to be running Kubernetes > 1.14 or if you're running Openshift set ", "spec.networking.exposeAs", v1alpha1.IngressExposeType, "Also try", v1alpha1.NodePortExposeType)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So you went with warnings, huh? Up to you, but I still think we should log it as error. Shouldn't cause too much trouble after #174 anyways

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Take a look in the next line, you will see that there's an error being raised.

return fmt.Errorf("ingress expose required, but unavailable")
}

if !v.routeAvailable && nexus.Spec.Networking.ExposeAs == v1alpha1.RouteExposeType {
v.log.Info("Routes are not available on your cluster. If you're running Kubernetes 1.14 or higher try setting ", "'spec.networking.exposeAs'", v1alpha1.IngressExposeType, "Also try", v1alpha1.NodePortExposeType)
v.log.Warn("Routes are not available on your cluster. If you're running Kubernetes 1.14 or higher try setting ", "'spec.networking.exposeAs'", v1alpha1.IngressExposeType, "Also try", v1alpha1.NodePortExposeType)
return fmt.Errorf("route expose required, but unavailable")
}

if nexus.Spec.Networking.ExposeAs == v1alpha1.NodePortExposeType && nexus.Spec.Networking.NodePort == 0 {
v.log.Info("NodePort networking requires a port. Check the Nexus resource 'spec.networking.nodePort' parameter")
v.log.Warn("NodePort networking requires a port. Check the Nexus resource 'spec.networking.nodePort' parameter")
return fmt.Errorf("nodeport expose required, but no port informed")
}

if nexus.Spec.Networking.ExposeAs == v1alpha1.IngressExposeType && len(nexus.Spec.Networking.Host) == 0 {
v.log.Info("Ingress networking requires a host. Check the Nexus resource 'spec.networking.host' parameter")
v.log.Warn("Ingress networking requires a host. Check the Nexus resource 'spec.networking.host' parameter")
return fmt.Errorf("ingress expose required, but no host informed")
}

if len(nexus.Spec.Networking.TLS.SecretName) > 0 && nexus.Spec.Networking.ExposeAs != v1alpha1.IngressExposeType {
v.log.Info("'spec.networking.tls.secretName' is only available when using an Ingress. Try setting ", "spec.networking.exposeAs'", v1alpha1.IngressExposeType)
v.log.Warn("'spec.networking.tls.secretName' is only available when using an Ingress. Try setting ", "spec.networking.exposeAs'", v1alpha1.IngressExposeType)
return fmt.Errorf("tls secret name informed, but using route")
}

if nexus.Spec.Networking.TLS.Mandatory && nexus.Spec.Networking.ExposeAs != v1alpha1.RouteExposeType {
v.log.Info("'spec.networking.tls.mandatory' is only available when using a Route. Try setting ", "spec.networking.exposeAs'", v1alpha1.RouteExposeType)
v.log.Warn("'spec.networking.tls.mandatory' is only available when using a Route. Try setting ", "spec.networking.exposeAs'", v1alpha1.RouteExposeType)
return fmt.Errorf("tls set to mandatory, but using ingress")
}

Expand Down Expand Up @@ -211,7 +211,7 @@ func (v *Validator) setUpdateDefaults(nexus *v1alpha1.Nexus) {
v.log.Debug("Automatic Updates are enabled, but no minor was informed. Fetching the most recent...")
minor, err := update.GetLatestMinor()
if err != nil {
v.log.Error(err, "Unable to fetch the most recent minor: %v. Disabling automatic updates.")
v.log.Error(err, "Unable to fetch the most recent minor. Disabling automatic updates.")
nexus.Spec.AutomaticUpdate.Disabled = true
createChangedNexusEvent(nexus, v.scheme, v.client, "spec.automaticUpdate.disabled")
return
Expand Down
2 changes: 1 addition & 1 deletion controllers/nexus/server/nexus.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func handleServerOperations(nexus *v1alpha1.Nexus, client client.Client, nexusAP
if nexus.Spec.GenerateRandomAdminPassword {
return *s.status, nil
}
log.Debug("Initializing server operations", "instance", nexus.Name)
log.Debug("Initializing server operations")
if s.isServerReady() {
internalEndpoint, err := s.getNexusEndpoint()
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions controllers/nexus/update/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ const (
func createUpdateSuccessEvent(nexus *v1alpha1.Nexus, scheme *runtime.Scheme, c client.Client, tag string) {
err := kubernetes.RaiseInfoEventf(nexus, scheme, c, successfulUpdateReason, "Successfully updated to %s", tag)
if err != nil {
log.Error(err, "Unable to raise event for successful update", "instance", nexus.Name, "tag", tag)
log.Error(err, "Unable to raise event for successful update", "tag", tag)
}
}

func createUpdateFailureEvent(nexus *v1alpha1.Nexus, scheme *runtime.Scheme, c client.Client, tag string) {
err := kubernetes.RaiseWarnEventf(nexus, scheme, c, failedUpdateReason, "Failed to update to %s. Human intervention may be required", tag)
if err != nil {
log.Error(err, "Unable to raise event for failed update", "instance", nexus.Name, "tag", tag)
log.Error(err, "Unable to raise event for failed update", "tag", tag)
}
}
2 changes: 1 addition & 1 deletion controllers/nexus/update/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func HandleUpdate(nexus *v1alpha1.Nexus, deployed, required *appsv1.Deployment,
}

if condition.Type == appsv1.DeploymentProgressing && condition.Reason == "NewReplicaSetAvailable" {
log.Info("Successfully updated to", "tag", targetTag)
log.Info("Successfully updated", "tag", targetTag)
// the Nexus status update can be delayed, let's leave it to the reconciler
nexus.Status.UpdateConditions = append(nexus.Status.UpdateConditions, fmt.Sprintf(updateOKFormat, previousTag, targetTag))
createUpdateSuccessEvent(nexus, scheme, c, targetTag)
Expand Down
10 changes: 5 additions & 5 deletions controllers/nexus/update/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const (
communityNexusRegistry = "https://registry.hub.docker.com"
communityNexusRepo = "sonatype/nexus3"
tagParseFailureFormat = "unable to parse tag \"%s\": %v"
unableToCheckUpdatesFormat = "Unable to check for updates"
unableToCheckUpdatesMsg = "Unable to check for updates"
)

const (
Expand Down Expand Up @@ -104,13 +104,13 @@ func fetchUpdates() {
tags, err := getTags()
if err != nil {
lastErr = time.Now()
log.Error(err, unableToCheckUpdatesFormat)
log.Error(err, unableToCheckUpdatesMsg)
return
}
lastQuery = time.Now()

if err = parseTagsAndUpdate(tags); err != nil {
log.Error(err, unableToCheckUpdatesFormat)
log.Error(err, unableToCheckUpdatesMsg)
return
}
}
Expand All @@ -122,8 +122,8 @@ func getTags() ([]string, error) {
}
// redirect the lib's logging to ours
reg.Logf = func(format string, args ...interface{}) {
format = fmt.Sprintf("Registry: %s", format)
log.Info(format, args...)
format = fmt.Sprintf(fmt.Sprintf("Registry: %s", format), args)
ricardozanini marked this conversation as resolved.
Show resolved Hide resolved
log.Info(format)
}

repo := communityNexusRepo
Expand Down