Skip to content

Commit

Permalink
Add GitHub Action workflow to run golangci-lint.
Browse files Browse the repository at this point in the history
This also fixes most issues flagged by the default list of linters that
are enabled.

For now, I decided to ignore the handful of places where the gocyclo
rule flags issues, so that we can keep the linter enabled to prevent
us from introducing more code that would be called out by gocyclo. If we
end up fixing those handful of places, we can always remove the nolint
marker.
  • Loading branch information
SaaldjorMike committed Mar 5, 2025
1 parent 0576a12 commit 51ef442
Show file tree
Hide file tree
Showing 39 changed files with 378 additions and 322 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: golangci-lint
on:
push:
branches:
- main
- master
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:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: stable
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.64
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ issues:
linters:
disable-all: true
enable:
- copyloopvar
- dupl
- errcheck
- exportloopref
- ginkgolinter
- goconst
- gocyclo
Expand Down
22 changes: 11 additions & 11 deletions api/v1alpha1/humioaction_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type HumioActionWebhookProperties struct {
Headers map[string]string `json:"headers,omitempty"`
// SecretHeaders specifies what HTTP headers to use and where to fetch the values from.
// If both Headers and SecretHeaders are specified, they will be merged together.
//+kubebuilder:default={}
// +kubebuilder:default={}
SecretHeaders []HeadersSource `json:"secretHeaders,omitempty"`
Method string `json:"method,omitempty"`
// Url specifies what URL to use
Expand All @@ -56,8 +56,8 @@ type HumioActionWebhookProperties struct {
// HeadersSource defines a header and corresponding source for the value of it.
type HeadersSource struct {
// Name is the name of the header.
//+kubebuilder:validation:MinLength=1
//+required
// +kubebuilder:validation:MinLength=1
// +required
Name string `json:"name"`
// ValueFrom defines where to fetch the value of the header from.
ValueFrom VarSource `json:"valueFrom,omitempty"`
Expand All @@ -67,8 +67,8 @@ type HeadersSource struct {
type HumioActionEmailProperties struct {
BodyTemplate string `json:"bodyTemplate,omitempty"`
SubjectTemplate string `json:"subjectTemplate,omitempty"`
//+kubebuilder:validation:MinItems=1
//+required
// +kubebuilder:validation:MinItems=1
// +required
Recipients []string `json:"recipients,omitempty"`
UseProxy bool `json:"useProxy,omitempty"`
}
Expand Down Expand Up @@ -128,9 +128,9 @@ type HumioActionSlackPostMessageProperties struct {
// If both ApiToken and ApiTokenSource are specified, ApiToken will be used.
ApiTokenSource VarSource `json:"apiTokenSource,omitempty"`
Channels []string `json:"channels,omitempty"`
//+kubebuilder:default={}
// +kubebuilder:default={}
Fields map[string]string `json:"fields,omitempty"`
//+kubebuilder:default=false
// +kubebuilder:default=false
UseProxy bool `json:"useProxy,omitempty"`
}

Expand Down Expand Up @@ -162,12 +162,12 @@ type HumioActionSpec struct {
// This conflicts with ManagedClusterName.
ExternalClusterName string `json:"externalClusterName,omitempty"`
// Name is the name of the Action
//+kubebuilder:validation:MinLength=1
//+required
// +kubebuilder:validation:MinLength=1
// +required
Name string `json:"name"`
// ViewName is the name of the Humio View under which the Action will be managed. This can also be a Repository
//+kubebuilder:validation:MinLength=1
//+required
// +kubebuilder:validation:MinLength=1
// +required
ViewName string `json:"viewName"`
// EmailProperties indicates this is an Email Action, and contains the corresponding properties
EmailProperties *HumioActionEmailProperties `json:"emailProperties,omitempty"`
Expand Down
12 changes: 6 additions & 6 deletions api/v1alpha1/humioaggregatealert_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,19 @@ type HumioAggregateAlertSpec struct {
// This conflicts with ManagedClusterName.
ExternalClusterName string `json:"externalClusterName,omitempty"`
// Name is the name of the aggregate alert inside Humio
//+kubebuilder:validation:MinLength=1
//+required
// +kubebuilder:validation:MinLength=1
// +required
Name string `json:"name"`
// ViewName is the name of the Humio View under which the aggregate alert will be managed. This can also be a Repository
//+kubebuilder:validation:MinLength=1
//+required
// +kubebuilder:validation:MinLength=1
// +required
ViewName string `json:"viewName"`
// QueryString defines the desired Humio query string
QueryString string `json:"queryString"`
// QueryTimestampType defines the timestamp type to use for a query
QueryTimestampType string `json:"queryTimestampType,omitempty"`
// Description is the description of the Aggregate alert
//+optional
// +optional
Description string `json:"description,omitempty"`
// Search Interval time in seconds
SearchIntervalSeconds int `json:"searchIntervalSeconds,omitempty"`
Expand All @@ -64,7 +64,7 @@ type HumioAggregateAlertSpec struct {
// Aggregate Alert trigger mode
TriggerMode string `json:"triggerMode,omitempty"`
// Enabled will set the AggregateAlert to enabled when set to true
//+kubebuilder:default=false
// +kubebuilder:default=false
Enabled bool `json:"enabled,omitempty"`
// Actions is the list of Humio Actions by name that will be triggered by this Aggregate alert
Actions []string `json:"actions"`
Expand Down
12 changes: 6 additions & 6 deletions api/v1alpha1/humioalert_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,18 @@ type HumioAlertSpec struct {
// This conflicts with ManagedClusterName.
ExternalClusterName string `json:"externalClusterName,omitempty"`
// Name is the name of the alert inside Humio
//+kubebuilder:validation:MinLength=1
//+required
// +kubebuilder:validation:MinLength=1
// +required
Name string `json:"name"`
// ViewName is the name of the Humio View under which the Alert will be managed. This can also be a Repository
//+kubebuilder:validation:MinLength=1
//+required
// +kubebuilder:validation:MinLength=1
// +required
ViewName string `json:"viewName"`
// Query defines the desired state of the Humio query
//+required
// +required
Query HumioQuery `json:"query"`
// Description is the description of the Alert
//+optional
// +optional
Description string `json:"description,omitempty"`
// ThrottleTimeMillis is the throttle time in milliseconds. An Alert is triggered at most once per the throttle time
ThrottleTimeMillis int `json:"throttleTimeMillis,omitempty"`
Expand Down
26 changes: 13 additions & 13 deletions api/v1alpha1/humiocluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ type HumioClusterSpec struct {
// DigestPartitionsCount is the desired number of digest partitions
DigestPartitionsCount int `json:"digestPartitionsCount,omitempty"`
// License is the kubernetes secret reference which contains the Humio license
//+required
// +required
License HumioClusterLicenseSpec `json:"license,omitempty"`
// IdpCertificateSecretName is the name of the secret that contains the IDP Certificate when using SAML authentication
IdpCertificateSecretName string `json:"idpCertificateSecretName,omitempty"`
Expand Down Expand Up @@ -117,11 +117,11 @@ type HumioNodeSpec struct {

// ImageSource is the reference to an external source identifying the image.
// The value from ImageSource takes precedence over Image.
//+optional
// +optional
ImageSource *HumioImageSource `json:"imageSource,omitempty"`

// NodeCount is the desired number of humio cluster nodes
//+kubebuilder:default=0
// +kubebuilder:default=0
NodeCount int `json:"nodeCount,omitempty"`

// DataVolumePersistentVolumeClaimSpecTemplate is the PersistentVolumeClaimSpec that will be used with for the humio data volume. This conflicts with DataVolumeSource.
Expand All @@ -138,7 +138,7 @@ type HumioNodeSpec struct {

// DisableInitContainer is used to disable the init container completely which collects the availability zone from the Kubernetes worker node.
// This is not recommended, unless you are using auto rebalancing partitions and are running in a single availability zone.
//+kubebuilder:default=false
// +kubebuilder:default=false
DisableInitContainer bool `json:"disableInitContainer,omitempty"`

// EnvironmentVariablesSource is the reference to an external source of environment variables that will be merged with environmentVariables
Expand Down Expand Up @@ -267,7 +267,7 @@ type HumioNodeSpec struct {
UpdateStrategy *HumioUpdateStrategy `json:"updateStrategy,omitempty"`

// PriorityClassName is the name of the priority class that will be used by the Humio pods
//+kubebuilder:default=""
// +kubebuilder:default=""
PriorityClassName string `json:"priorityClassName,omitempty"`

// HumioNodePoolFeatures defines the features that are allowed by the node pool
Expand All @@ -282,7 +282,7 @@ type HumioFeatureFlags struct {
// EnableDownscalingFeature (PREVIEW) is a feature flag for enabling the downscaling functionality of the humio operator for this humio cluster.
// Default: false
// Preview: this feature is in a preview state
//+kubebuilder:default=false
// +kubebuilder:default=false
EnableDownscalingFeature bool `json:"enableDownscalingFeature,omitempty"`
}

Expand All @@ -296,7 +296,7 @@ type HumioUpdateStrategy struct {
// Type controls how Humio pods are updated when changes are made to the HumioCluster resource that results
// in a change to the Humio pods. The available values are: OnDelete, RollingUpdate, ReplaceAllOnUpdate, and
// RollingUpdateBestEffort.
///
//
// When set to OnDelete, no Humio pods will be terminated but new pods will be created with the new spec. Replacing
// existing pods will require each pod to be deleted by the user.
//
Expand All @@ -322,12 +322,12 @@ type HumioUpdateStrategy struct {

// MaxUnavailable is the maximum number of pods that can be unavailable during a rolling update.
// This can be configured to an absolute number or a percentage, e.g. "maxUnavailable: 5" or "maxUnavailable: 25%".
//+kubebuilder:default=1
// +kubebuilder:default=1
MaxUnavailable *intstr.IntOrString `json:"maxUnavailable,omitempty"`
}
type HumioNodePoolSpec struct {
//+kubebuilder:validation:MinLength:=1
//+required
// +kubebuilder:validation:MinLength:=1
// +required
Name string `json:"name"`

HumioNodeSpec `json:"spec,omitempty"`
Expand Down Expand Up @@ -376,7 +376,7 @@ type HumioESHostnameSource struct {
type HumioClusterIngressSpec struct {
// Enabled enables the logic for the Humio operator to create ingress-related objects. Requires one of the following
// to be set: spec.hostname, spec.hostnameSource, spec.esHostname or spec.esHostnameSource
//+kubebuilder:default=false
// +kubebuilder:default=false
Enabled bool `json:"enabled,omitempty"`
// Controller is used to specify the controller used for ingress in the Kubernetes cluster. For now, only nginx is supported.
Controller string `json:"controller,omitempty"`
Expand Down Expand Up @@ -444,8 +444,8 @@ type HumioNodePoolStatusList []HumioNodePoolStatus
// HumioNodePoolStatus shows the status of each node pool
type HumioNodePoolStatus struct {
// Name is the name of the node pool
//+kubebuilder:validation:MinLength=1
//+required
// +kubebuilder:validation:MinLength=1
// +required
Name string `json:"name"`
// State will be empty before the cluster is bootstrapped. From there it can be "Running", "Upgrading", "Restarting" or "Pending"
State string `json:"state,omitempty"`
Expand Down
4 changes: 2 additions & 2 deletions api/v1alpha1/humioexternalcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ const (
// HumioExternalClusterSpec defines the desired state of HumioExternalCluster.
type HumioExternalClusterSpec struct {
// Url is used to connect to the Humio cluster we want to use.
//+kubebuilder:validation:MinLength=1
//+required
// +kubebuilder:validation:MinLength=1
// +required
Url string `json:"url"`
// APITokenSecretName is used to obtain the API token we need to use when communicating with the external Humio cluster.
// It refers to a Kubernetes secret that must be located in the same namespace as the HumioExternalCluster.
Expand Down
20 changes: 10 additions & 10 deletions api/v1alpha1/humiofilteralert_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,28 +41,28 @@ type HumioFilterAlertSpec struct {
// This conflicts with ManagedClusterName.
ExternalClusterName string `json:"externalClusterName,omitempty"`
// Name is the name of the filter alert inside Humio
//+kubebuilder:validation:MinLength=1
//+required
// +kubebuilder:validation:MinLength=1
// +required
Name string `json:"name"`
// ViewName is the name of the Humio View under which the filter alert will be managed. This can also be a Repository
//+kubebuilder:validation:MinLength=1
//+required
// +kubebuilder:validation:MinLength=1
// +required
ViewName string `json:"viewName"`
// QueryString defines the desired Humio query string
QueryString string `json:"queryString"`
// Description is the description of the filter alert
//+optional
// +optional
Description string `json:"description,omitempty"`
// ThrottleTimeSeconds is the throttle time in seconds. A filter alert is triggered at most once per the throttle time
//+kubebuilder:validation:Minimum=60
//+required
// +kubebuilder:validation:Minimum=60
// +required
ThrottleTimeSeconds int `json:"throttleTimeSeconds,omitempty"`
// ThrottleField is the field on which to throttle
//+kubebuilder:validation:MinLength=1
//+required
// +kubebuilder:validation:MinLength=1
// +required
ThrottleField *string `json:"throttleField,omitempty"`
// Enabled will set the FilterAlert to enabled when set to true
//+kubebuilder:default=false
// +kubebuilder:default=false
Enabled bool `json:"enabled,omitempty"`
// Actions is the list of Humio Actions by name that will be triggered by this filter alert
Actions []string `json:"actions"`
Expand Down
12 changes: 6 additions & 6 deletions api/v1alpha1/humioingesttoken_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ type HumioIngestTokenSpec struct {
// This conflicts with ManagedClusterName.
ExternalClusterName string `json:"externalClusterName,omitempty"`
// Name is the name of the ingest token inside Humio
//+kubebuilder:validation:MinLength=1
//+required
// +kubebuilder:validation:MinLength=1
// +required
Name string `json:"name"`
// ParserName is the name of the parser which will be assigned to the ingest token.
//+kubebuilder:validation:MinLength=1
//+required
// +kubebuilder:validation:MinLength=1
// +required
ParserName *string `json:"parserName,omitempty"`
// RepositoryName is the name of the Humio repository under which the ingest token will be created
//+kubebuilder:validation:MinLength=1
//+required
// +kubebuilder:validation:MinLength=1
// +required
RepositoryName string `json:"repositoryName,omitempty"`
// TokenSecretName specifies the name of the Kubernetes secret that will be created
// and contain the ingest token. The key in the secret storing the ingest token is "token".
Expand Down
8 changes: 4 additions & 4 deletions api/v1alpha1/humioparser_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ type HumioParserSpec struct {
// This conflicts with ManagedClusterName.
ExternalClusterName string `json:"externalClusterName,omitempty"`
// Name is the name of the parser inside Humio
//+kubebuilder:validation:MinLength=1
//+required
// +kubebuilder:validation:MinLength=1
// +required
Name string `json:"name"`
// ParserScript contains the code for the Humio parser
ParserScript string `json:"parserScript,omitempty"`
// RepositoryName defines what repository this parser should be managed in
//+kubebuilder:validation:MinLength=1
//+required
// +kubebuilder:validation:MinLength=1
// +required
RepositoryName string `json:"repositoryName,omitempty"`
// TagFields is used to define what fields will be used to define how data will be tagged when being parsed by
// this parser
Expand Down
18 changes: 9 additions & 9 deletions api/v1alpha1/humiorepository_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ const (
type HumioRetention struct {
// perhaps we should migrate to resource.Quantity? the Humio API needs float64, but that is not supported here, see more here:
// https://github.com/kubernetes-sigs/controller-tools/issues/245
//+kubebuilder:validation:Minimum=0
//+optional
// +kubebuilder:validation:Minimum=0
// +optional
IngestSizeInGB *int32 `json:"ingestSizeInGB,omitempty"`
//+kubebuilder:validation:Minimum=0
//+optional
// +kubebuilder:validation:Minimum=0
// +optional
StorageSizeInGB *int32 `json:"storageSizeInGB,omitempty"`
//+kubebuilder:validation:Minimum=1
//+optional
// +kubebuilder:validation:Minimum=1
// +optional
TimeInDays *int32 `json:"timeInDays,omitempty"`
}

Expand All @@ -56,11 +56,11 @@ type HumioRepositorySpec struct {
// This conflicts with ManagedClusterName.
ExternalClusterName string `json:"externalClusterName,omitempty"`
// Name is the name of the repository inside Humio
//+kubebuilder:validation:MinLength=1
//+required
// +kubebuilder:validation:MinLength=1
// +required
Name string `json:"name"`
// Description contains the description that will be set on the repository
//+optional
// +optional
Description string `json:"description,omitempty"`
// Retention defines the retention settings for the repository
Retention HumioRetention `json:"retention,omitempty"`
Expand Down
Loading

0 comments on commit 51ef442

Please sign in to comment.