Skip to content

Commit

Permalink
Merge pull request #84 from RedHatInsights/psav/fix_lint
Browse files Browse the repository at this point in the history
Add lint
  • Loading branch information
adamrdrew authored Jan 3, 2023
2 parents 292b634 + 50d71b5 commit 6ceb8dc
Show file tree
Hide file tree
Showing 12 changed files with 165 additions and 62 deletions.
59 changes: 59 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Go

on:
- pull_request

permissions:
contents: read
# Optional: allow read access to pull request. Use with 'only-new-issues' option.
# pull-requests: read
jobs:
golangci:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Display build environment
run: printenv

- uses: actions/setup-go@v3
name: Set up Go 1.x
with:
go-version: 1.18

- uses: actions/checkout@v3
name: Checkout frontend-operator

- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: latest

args: >
--enable=errcheck,gocritic,gofmt,goimports,gosec,gosimple,govet,ineffassign,revive,staticcheck,typecheck,unused,bodyclose
--fix=false
--max-same-issues=20
--out-${NO_FUTURE}format=colored-line-number
--print-issued-lines=true
--print-linter-name=true
--sort-results=true
--timeout=5m0s
--uniq-by-line=false
# Optional: working directory, useful for monorepos
# working-directory: somedir

# Optional: golangci-lint command line arguments.
# args: --issues-exit-code=0

# Optional: show only new issues if it's a pull request. The default value is `false`.
only-new-issues: false

# Optional: if set to true then the all caching functionality will be complete disabled,
# takes precedence over all other caching options.
# skip-cache: true

# Optional: if set to true then the action don't cache or restore ~/go/pkg.
# skip-pkg-cache: true

# Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
# skip-build-cache: true
6 changes: 6 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
issues:
exclude-rules:
- path: api/v1alpha1/groupversion_info.go
linters:
- gofmt
- goimports
6 changes: 3 additions & 3 deletions api/v1alpha1/bundle_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type BundlePermission struct {
// EmbeddedRoutes allow deeply nested navs to have support for routes
type EmbeddedRoute struct {
Title string `json:"title,omitempty" yaml:"title,omitempty"`
AppId string `json:"appId,omitempty" yaml:"appId,omitempty"`
AppID string `json:"appId,omitempty" yaml:"appId,omitempty"`
Href string `json:"href,omitempty" yaml:"href,omitempty"`
Product string `json:"product,omitempty" yaml:"product,omitempty"`
}
Expand All @@ -40,7 +40,7 @@ type BundleNavItem struct {
GroupID string `json:"groupId,omitempty" yaml:"groupId,omitempty"`
Icon string `json:"icon,omitempty" yaml:"icon,omitempty"`
NavItems []LeafBundleNavItem `json:"navItems,omitempty" yaml:"navItems,omitempty"`
AppId string `json:"appId,omitempty" yaml:"appId,omitempty"`
AppID string `json:"appId,omitempty" yaml:"appId,omitempty"`
Href string `json:"href,omitempty" yaml:"href,omitempty"`
Product string `json:"product,omitempty" yaml:"product,omitempty"`
IsExternal bool `json:"isExternal,omitempty" yaml:"isExternal,omitempty"`
Expand All @@ -54,7 +54,7 @@ type BundleNavItem struct {
type LeafBundleNavItem struct {
Title string `json:"title" yaml:"title"`
GroupID string `json:"groupId,omitempty" yaml:"groupId,omitempty"`
AppId string `json:"appId,omitempty" yaml:"appId,omitempty"`
AppID string `json:"appId,omitempty" yaml:"appId,omitempty"`
Href string `json:"href,omitempty" yaml:"href,omitempty"`
Product string `json:"product,omitempty" yaml:"product,omitempty"`
IsExternal bool `json:"isExternal,omitempty" yaml:"isExternal,omitempty"`
Expand Down
10 changes: 5 additions & 5 deletions api/v1alpha1/frontend_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
)

type ApiInfo struct {
type APIInfo struct {
Versions []string `json:"versions" yaml:"versions"`
}

Expand All @@ -46,7 +46,7 @@ type FrontendSpec struct {
EnvName string `json:"envName" yaml:"envName"`
Title string `json:"title" yaml:"title"`
DeploymentRepo string `json:"deploymentRepo" yaml:"deploymentRepo"`
API ApiInfo `json:"API" yaml:"API"`
API APIInfo `json:"API" yaml:"API"`
Frontend FrontendInfo `json:"frontend" yaml:"frontend"`
Image string `json:"image,omitempty" yaml:"image,omitempty"`
Service string `json:"service,omitempty" yaml:"service,omitempty"`
Expand Down Expand Up @@ -80,7 +80,7 @@ type FedModule struct {
}

type Module struct {
Id string `json:"id" yaml:"id"`
ID string `json:"id" yaml:"id"`
Module string `json:"module" yaml:"module"`
Routes []Route `json:"routes" yaml:"routes"`
Dependencies []string `json:"dependencies,omitempty" yaml:"dependencies,omitempty"`
Expand Down Expand Up @@ -153,8 +153,8 @@ func (i *Frontend) GetIdent() string {
return fmt.Sprintf("%v.%v", i.Spec.EnvName, i.Name)
}

func (FEInfo *FrontendInfo) HasPath(lookup string) bool {
for _, a := range FEInfo.Paths {
func (feinfo *FrontendInfo) HasPath(lookup string) bool {
for _, a := range feinfo.Paths {
if a == lookup {
return true
}
Expand Down
4 changes: 2 additions & 2 deletions api/v1alpha1/frontendenvironment_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ type FrontendEnvironmentSpec struct {
// Hostname
Hostname string `json:"hostname,omitempty"`

//Whitelist CIDRs
// Whitelist CIDRs
Whitelist []string `json:"whitelist,omitempty"`

//MonitorMode determines where a ServiceMonitor object will be placed
// MonitorMode determines where a ServiceMonitor object will be placed
// local will add it to the frontend's namespace
// app-interface will add it to "openshift-customer-monitoring"
Monitoring *MonitoringConfig `json:"monitoring,omitempty"`
Expand Down
6 changes: 3 additions & 3 deletions api/v1alpha1/zz_generated.deepcopy.go

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

36 changes: 26 additions & 10 deletions controllers/frontend_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,16 +205,19 @@ func (r *FrontendReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
}

err = reconciliation.run()

if err != nil {
SetFrontendConditions(ctx, r.Client, &frontend, crd.ReconciliationFailed, err)
if sErr := SetFrontendConditions(ctx, r.Client, &frontend, crd.ReconciliationFailed, err); sErr != nil {
return ctrl.Result{Requeue: true}, fmt.Errorf("error setting status after recon error: %w", sErr)
}
return ctrl.Result{Requeue: true}, err
}

cacheErr := cache.ApplyAll()

if cacheErr != nil {
SetFrontendConditions(ctx, r.Client, &frontend, crd.ReconciliationFailed, cacheErr)
if sErr := SetFrontendConditions(ctx, r.Client, &frontend, crd.ReconciliationFailed, cacheErr); sErr != nil {
return ctrl.Result{Requeue: true}, fmt.Errorf("error setting status after cacheapply error: %w", sErr)
}
return ctrl.Result{Requeue: true}, cacheErr
}

Expand All @@ -225,7 +228,9 @@ func (r *FrontendReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
err = cache.Reconcile(frontend.GetUID(), opts...)
if err != nil {
log.Info("Reconcile error", "error", err)
SetFrontendConditions(ctx, r.Client, &frontend, crd.ReconciliationFailed, err)
if sErr := SetFrontendConditions(ctx, r.Client, &frontend, crd.ReconciliationFailed, err); sErr != nil {
return ctrl.Result{Requeue: true}, fmt.Errorf("error setting status after reconcile delete error: %w", sErr)
}
return ctrl.Result{Requeue: true}, err
}

Expand All @@ -251,15 +256,19 @@ func (r *FrontendReconciler) SetupWithManager(mgr ctrl.Manager) error {

cache := mgr.GetCache()

cache.IndexField(
if err := cache.IndexField(
context.TODO(), &crd.Frontend{}, "spec.envName", func(o client.Object) []string {
return []string{o.(*crd.Frontend).Spec.EnvName}
})
}); err != nil {
return err
}

cache.IndexField(
if err := cache.IndexField(
context.TODO(), &crd.Bundle{}, "spec.envName", func(o client.Object) []string {
return []string{o.(*crd.Bundle).Spec.EnvName}
})
}); err != nil {
return err
}

return ctrl.NewControllerManagedBy(mgr).
For(&crd.Frontend{}, builder.WithPredicates(defaultPredicate(r.Log, "frontend"))).
Expand Down Expand Up @@ -331,7 +340,11 @@ func (r *FrontendReconciler) appsToEnqueueUponBundleUpdate(a client.Object) []re
// Get all the ClowdApp resources

frontendList := crd.FrontendList{}
r.Client.List(ctx, &frontendList, client.MatchingFields{"spec.envName": bundle.Spec.EnvName})
err = r.Client.List(ctx, &frontendList, client.MatchingFields{"spec.envName": bundle.Spec.EnvName})
if err != nil {
r.Log.Error(err, "Failed to List Frontends")
return nil
}

// Filter based on base attribute

Expand Down Expand Up @@ -372,7 +385,10 @@ func (r *FrontendReconciler) appsToEnqueueUponFrontendEnvironmentUpdate(a client
// Get all the ClowdApp resources

frontendList := crd.FrontendList{}
r.Client.List(ctx, &frontendList, client.MatchingFields{"spec.envName": fe.Name})
if err := r.Client.List(ctx, &frontendList, client.MatchingFields{"spec.envName": fe.Name}); err != nil {
r.Log.Error(err, "Failed to List Frontends")
return nil
}

// Filter based on base attribute

Expand Down
Loading

0 comments on commit 6ceb8dc

Please sign in to comment.