Skip to content

Commit

Permalink
Generate client using GraphQL schema
Browse files Browse the repository at this point in the history
Most notably:
- Removes dependency on API client in github.com/humio/cli. Instead we call GraphQL directly from `ClientConfig` using generated Go code based on the GraphQL schema.
- Bump minimum supported LogScale version to 1.130.0.

Other changes:
- Remove unused operator-sdk GitHub Action.
- Moves some exported functions to an internal package as they are not meant for external consumption.
- Bump gosec and staticcheck that is used by CI GitHub Actions workflow.
  • Loading branch information
SaaldjorMike committed Dec 17, 2024
1 parent faa6439 commit 40d73c9
Show file tree
Hide file tree
Showing 107 changed files with 43,224 additions and 3,660 deletions.
24 changes: 0 additions & 24 deletions .github/action/operator-sdk/Dockerfile

This file was deleted.

12 changes: 0 additions & 12 deletions .github/action/operator-sdk/entrypoint.sh

This file was deleted.

7 changes: 3 additions & 4 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,12 @@ jobs:
- name: Run Gosec Security Scanner
run: |
export PATH=$PATH:$(go env GOPATH)/bin
go get github.com/securego/gosec/cmd/gosec
go install github.com/securego/gosec/cmd/gosec
gosec ./...
go install github.com/securego/gosec/v2/cmd/gosec@latest
gosec -exclude-dir images/logscale-dummy -exclude-generated ./...
- name: Run Staticcheck
uses: dominikh/[email protected]
with:
version: "2023.1.7"
version: "2024.1.1"
install-go: false
- name: operator image
run: make docker-build-operator IMG=humio/humio-operator:${{ github.sha }}
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ RUN go mod download
COPY main.go main.go
COPY api/ api/
COPY controllers/ controllers/
COPY pkg/ pkg/
COPY internal/ internal/

# Build
RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH GO111MODULE=on go build -ldflags="-s -w -X 'main.version=$RELEASE_VERSION' -X 'main.commit=$RELEASE_COMMIT' -X 'main.date=$RELEASE_DATE'" -a -o manager main.go
Expand Down
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
SCHEMA_CLUSTER?=${HUMIO_ENDPOINT}
SCHEMA_CLUSTER_API_TOKEN?=${HUMIO_TOKEN}

# Image URL to use all building/pushing image targets
IMG ?= humio/humio-operator:latest
Expand Down Expand Up @@ -39,7 +41,12 @@ manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and Cust
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
hack/gen-crds.sh # NOTE: This line was custom added for the humio-operator project.

update-schema:
go run github.com/suessflorian/gqlfetch/gqlfetch@607d6757018016bba0ba7fd1cb9fed6aefa853b5 --endpoint ${SCHEMA_CLUSTER}/graphql --header "Authorization=Bearer ${SCHEMA_CLUSTER_API_TOKEN}" > internal/api/humiographql/schema/_schema.graphql
printf "# Fetched from version %s" $$(curl --silent --location '${SCHEMA_CLUSTER}/api/v1/status' | jq -r ".version") >> internal/api/humiographql/schema/_schema.graphql

generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
go generate ./...
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."

fmt: ## Run go fmt against code.
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha1/humioaggregatealert_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ type HumioAggregateAlertSpec struct {
// ThrottleTimeSeconds is the throttle time in seconds. An aggregate alert is triggered at most once per the throttle time
ThrottleTimeSeconds int `json:"throttleTimeSeconds,omitempty"`
// ThrottleField is the field on which to throttle
ThrottleField string `json:"throttleField,omitempty"`
ThrottleField *string `json:"throttleField,omitempty"`
// Aggregate Alert trigger mode
TriggerMode string `json:"triggerMode,omitempty"`
// Enabled will set the AggregateAlert to enabled when set to true
Expand Down
3 changes: 2 additions & 1 deletion api/v1alpha1/humioalert_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,15 @@ type HumioAlertSpec struct {
//+required
ViewName string `json:"viewName"`
// Query defines the desired state of the Humio query
//+required
Query HumioQuery `json:"query"`
// Description is the description of the Alert
//+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"`
// ThrottleField is the field on which to throttle
ThrottleField string `json:"throttleField,omitempty"`
ThrottleField *string `json:"throttleField,omitempty"`
// Silenced will set the Alert to enabled when set to false
Silenced bool `json:"silenced,omitempty"`
// Actions is the list of Humio Actions by name that will be triggered by this Alert
Expand Down
6 changes: 5 additions & 1 deletion api/v1alpha1/humiofilteralert_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,13 @@ type HumioFilterAlertSpec struct {
//+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
ThrottleTimeSeconds int `json:"throttleTimeSeconds,omitempty"`
// ThrottleField is the field on which to throttle
ThrottleField string `json:"throttleField,omitempty"`
//+kubebuilder:validation:MinLength=1
//+required
ThrottleField *string `json:"throttleField,omitempty"`
// Enabled will set the FilterAlert to enabled when set to true
Enabled bool `json:"enabled,omitempty"`
// Actions is the list of Humio Actions by name that will be triggered by this filter alert
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha1/humioingesttoken_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type HumioIngestTokenSpec struct {
// ParserName is the name of the parser which will be assigned to the ingest token.
//+kubebuilder:validation:MinLength=1
//+required
ParserName string `json:"parserName,omitempty"`
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
Expand Down
12 changes: 9 additions & 3 deletions api/v1alpha1/humiorepository_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,15 @@ 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
IngestSizeInGB int32 `json:"ingestSizeInGB,omitempty"`
StorageSizeInGB int32 `json:"storageSizeInGB,omitempty"`
TimeInDays int32 `json:"timeInDays,omitempty"`
//+kubebuilder:validation:Minimum=1
//+optional
IngestSizeInGB *int32 `json:"ingestSizeInGB,omitempty"`
//+kubebuilder:validation:Minimum=1
//+optional
StorageSizeInGB *int32 `json:"storageSizeInGB,omitempty"`
//+kubebuilder:validation:Minimum=1
//+optional
TimeInDays *int32 `json:"timeInDays,omitempty"`
}

// HumioRepositorySpec defines the desired state of HumioRepository
Expand Down
15 changes: 8 additions & 7 deletions api/v1alpha1/humioview_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
package v1alpha1

import (
humioapi "github.com/humio/cli/api"
"github.com/humio/humio-operator/internal/api/humiographql"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down Expand Up @@ -97,13 +97,14 @@ func init() {
SchemeBuilder.Register(&HumioView{}, &HumioViewList{})
}

func (hv *HumioView) GetViewConnections() []humioapi.ViewConnection {
viewConnections := make([]humioapi.ViewConnection, 0)

func (hv *HumioView) GetViewConnections() []humiographql.GetSearchDomainSearchDomainViewConnectionsViewConnection {
viewConnections := make([]humiographql.GetSearchDomainSearchDomainViewConnectionsViewConnection, 0)
for _, connection := range hv.Spec.Connections {
viewConnections = append(viewConnections, humioapi.ViewConnection{
RepoName: connection.RepositoryName,
Filter: connection.Filter,
viewConnections = append(viewConnections, humiographql.GetSearchDomainSearchDomainViewConnectionsViewConnection{
Repository: humiographql.GetSearchDomainSearchDomainViewConnectionsViewConnectionRepository{
Name: connection.RepositoryName,
},
Filter: connection.Filter,
})
}
return viewConnections
Expand Down
37 changes: 36 additions & 1 deletion api/v1alpha1/zz_generated.deepcopy.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,12 @@ spec:
type: string
throttleField:
description: ThrottleField is the field on which to throttle
minLength: 1
type: string
throttleTimeSeconds:
description: ThrottleTimeSeconds is the throttle time in seconds.
A filter alert is triggered at most once per the throttle time
minimum: 60
type: integer
viewName:
description: ViewName is the name of the Humio View under which the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,15 @@ spec:
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
format: int32
minimum: 1
type: integer
storageSizeInGB:
format: int32
minimum: 1
type: integer
timeInDays:
format: int32
minimum: 1
type: integer
type: object
required:
Expand Down
2 changes: 2 additions & 0 deletions config/crd/bases/core.humio.com_humiofilteralerts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,12 @@ spec:
type: string
throttleField:
description: ThrottleField is the field on which to throttle
minLength: 1
type: string
throttleTimeSeconds:
description: ThrottleTimeSeconds is the throttle time in seconds.
A filter alert is triggered at most once per the throttle time
minimum: 60
type: integer
viewName:
description: ViewName is the name of the Humio View under which the
Expand Down
3 changes: 3 additions & 0 deletions config/crd/bases/core.humio.com_humiorepositories.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,15 @@ spec:
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
format: int32
minimum: 1
type: integer
storageSizeInGB:
format: int32
minimum: 1
type: integer
timeInDays:
format: int32
minimum: 1
type: integer
type: object
required:
Expand Down
Loading

0 comments on commit 40d73c9

Please sign in to comment.