Skip to content

Commit

Permalink
refactor(konnect): add SDK interface types and theirs mocks (#507)
Browse files Browse the repository at this point in the history
* refactor(konnect): add SDK interface types for each entity type

* tests: add mockery for Konnect SDK

* tests: add mocks for KongService SDK

* Resolve conflict for "refactor(konnect): add SDK interface types and theirs mocks"(#507) (#542)

* feat(cli): configurable certgen images (#516)

* feat(cli): configurable certgen images

Add two new command line options to the manager.

  -webhook-certificate-config-base-image string
    	The base image for the certgen Jobs. (default "registry.k8s.io/ingress-nginx/kube-webhook-certgen:v1.3.0")
  -webhook-certificate-config-shell-image string
    	The shell image for the certgen Jobs. (default "busybox")

Those are optional. If you omit them the defaults will be used which are
the previous hard coded values.

Signed-off-by: Arpad Kunszt <[email protected]>

* feat(cli): cleanup code per review

Removed unnecessary variable assignments.

Signed-off-by: Arpad Kunszt <[email protected]>

* feat(cli): add CHANGELOG entry

Signed-off-by: Arpad Kunszt <[email protected]>

* feat(cli): unit tests handle new arguments

Signed-off-by: Arpad Kunszt <[email protected]>

* feat(cli): move new configuration into Config

Also created a constant for the shell image, so it is no more a hard
coded string hidden in the code.

Signed-off-by: Arpad Kunszt <[email protected]>

* feat(cli): added UT for the new arguments

The new unit test tests only if the command line arguments are set in
the configuration. The other cases, the default configuration, the
environmental variable handling are already tested in previous cases.

The test does not cover if the values from the configuration are
actually used but at the moment there are no tests for that part of the
code at all.

Signed-off-by: Arpad Kunszt <[email protected]>

---------

Signed-off-by: Arpad Kunszt <[email protected]>

* chore(deps): bump github.com/kong/kubernetes-configuration (#523)

Bumps [github.com/kong/kubernetes-configuration](https://github.com/kong/kubernetes-configuration) from 0.0.8 to 0.0.9.
- [Commits](Kong/kubernetes-configuration@v0.0.8...v0.0.9)

---
updated-dependencies:
- dependency-name: github.com/kong/kubernetes-configuration
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* chore(deps): bump github.com/kong/kubernetes-ingress-controller/v3 from 3.2.4 to 3.3.0 (#531)

* chore(deps): bump github.com/kong/kubernetes-ingress-controller/v3

Bumps [github.com/kong/kubernetes-ingress-controller/v3](https://github.com/kong/kubernetes-ingress-controller) from 3.2.4 to 3.3.0.
- [Release notes](https://github.com/kong/kubernetes-ingress-controller/releases)
- [Changelog](https://github.com/Kong/kubernetes-ingress-controller/blob/main/CHANGELOG.md)
- [Commits](Kong/kubernetes-ingress-controller@v3.2.4...v3.3.0)

---
updated-dependencies:
- dependency-name: github.com/kong/kubernetes-ingress-controller/v3
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

* chore: go mod tidy

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Jakub Warczarek <[email protected]>

* `KongPluginBinding` reconciler (#513)

* feat: KongPluginBinding reconciler

Signed-off-by: Mattia Lavacca <[email protected]>

* chore: fix linter

Signed-off-by: Mattia Lavacca <[email protected]>

* chore: CHANGELOG updated

Signed-off-by: Mattia Lavacca <[email protected]>

* Update controller/konnect/ops_kongpluginbinding.go

Co-authored-by: Grzegorz Burzyński <[email protected]>

---------

Signed-off-by: Mattia Lavacca <[email protected]>
Co-authored-by: Grzegorz Burzyński <[email protected]>

* chore(deps): update kong/kubernetes-ingress-controller docker tag to v3.3.0 (#532)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* chore(deps): update kong/kubernetes-ingress-controller docker tag to v3.3.1 (#534)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Add watch for KongPlugin and KongClusterPlugin in KongPluginBinding controller (#535)

* chore(deps): bump github.com/kong/kubernetes-ingress-controller/v3 (#536)

Bumps [github.com/kong/kubernetes-ingress-controller/v3](https://github.com/kong/kubernetes-ingress-controller) from 3.3.0 to 3.3.1.
- [Release notes](https://github.com/kong/kubernetes-ingress-controller/releases)
- [Changelog](https://github.com/Kong/kubernetes-ingress-controller/blob/main/CHANGELOG.md)
- [Commits](Kong/kubernetes-ingress-controller@v3.3.0...v3.3.1)

---
updated-dependencies:
- dependency-name: github.com/kong/kubernetes-ingress-controller/v3
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* chore(deps): bump github.com/Masterminds/sprig/v3 in /hack/generators (#539)

Bumps [github.com/Masterminds/sprig/v3](https://github.com/Masterminds/sprig) from 3.2.3 to 3.3.0.
- [Release notes](https://github.com/Masterminds/sprig/releases)
- [Changelog](https://github.com/Masterminds/sprig/blob/master/CHANGELOG.md)
- [Commits](Masterminds/sprig@v3.2.3...v3.3.0)

---
updated-dependencies:
- dependency-name: github.com/Masterminds/sprig/v3
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* chore(deps): update dependency kubernetes-sigs/controller-tools to v0.16.2 (#538)

* chore(deps): update dependency kubernetes-sigs/controller-tools to v0.16.2

* chore: regenerate

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Jakub Warczarek <[email protected]>

* chore(deps): bump github.com/gruntwork-io/terratest (#541)

Bumps [github.com/gruntwork-io/terratest](https://github.com/gruntwork-io/terratest) from 0.47.0 to 0.47.1.
- [Release notes](https://github.com/gruntwork-io/terratest/releases)
- [Commits](gruntwork-io/terratest@v0.47.0...v0.47.1)

---
updated-dependencies:
- dependency-name: github.com/gruntwork-io/terratest
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* update golangci configuration

---------

Signed-off-by: Arpad Kunszt <[email protected]>
Signed-off-by: dependabot[bot] <[email protected]>
Signed-off-by: Mattia Lavacca <[email protected]>
Co-authored-by: akunszt <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Jakub Warczarek <[email protected]>
Co-authored-by: Mattia Lavacca <[email protected]>
Co-authored-by: Grzegorz Burzyński <[email protected]>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* fix lint

* replace KonnnectControlPlane to KonnectGatewayControlPlane

---------

Signed-off-by: Arpad Kunszt <[email protected]>
Signed-off-by: dependabot[bot] <[email protected]>
Signed-off-by: Mattia Lavacca <[email protected]>
Co-authored-by: Tao Yi <[email protected]>
Co-authored-by: akunszt <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Jakub Warczarek <[email protected]>
Co-authored-by: Mattia Lavacca <[email protected]>
Co-authored-by: Grzegorz Burzyński <[email protected]>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
  • Loading branch information
8 people authored Sep 5, 2024
1 parent 53eb79d commit a3b231e
Show file tree
Hide file tree
Showing 36 changed files with 1,921 additions and 297 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
**/zz_generated*.go linguist-generated=true
pkg/clientset/** linguist-generated=true
controller/konnect/ops/*_mock_test.go linguist-generated=true
7 changes: 7 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ linters-settings:

- pkg: github.com/kong/gateway-operator/internal/types
alias: gwtypes

- pkg: github.com/Kong/sdk-konnect-go/models/components
alias: sdkkonnectcomp
- pkg: github.com/Kong/sdk-konnect-go/models/operations
alias: sdkkonnectops
- pkg: github.com/Kong/sdk-konnect-go/models/sdkerrors
alias: sdkkonnecterrs
revive:
rules:
- name: errorf
Expand Down
15 changes: 15 additions & 0 deletions .mockery.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
quiet: False
inpackage: True
disable-version-string: True
with-expecter: True

filename: "{{ trimSuffix .InterfaceFile \".go\" | base | lower }}_mock_test.go"
dir: "{{ .InterfaceDir }}"
mockname: "Mock{{ .InterfaceName }}"
outpkg: "{{ .PackageName }}"

packages:
github.com/kong/gateway-operator/controller/konnect/ops:
interfaces:
ControlPlaneSDK:
ServicesSDK:
2 changes: 2 additions & 0 deletions .tools_versions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ dlv: "1.23.0"
gotestsum: "1.12.0"
# renovate: datasource=github-releases depName=elastic/crd-ref-docs
crd-ref-docs: "0.1.0"
# renovate: datasource=github-releases depName=vektra/mockery
mockery: "2.44.2"
14 changes: 13 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@ skaffold: mise yq ## Download skaffold locally if necessary.
@$(MISE) plugin install --yes -q skaffold
@$(MISE) install -q skaffold@$(SKAFFOLD_VERSION)

MOCKERY_VERSION = $(shell $(YQ) -r '.mockery' < $(TOOLS_VERSIONS_FILE))
MOCKERY = $(PROJECT_DIR)/bin/installs/mockery/$(MOCKERY_VERSION)/bin/mockery
.PHONY: mockery
mockery: mise yq ## Download mockery locally if necessary.
@$(MISE) plugin install --yes -q mockery https://github.com/cabify/asdf-mockery.git
@$(MISE) install -q mockery@$(MOCKERY_VERSION)

# ------------------------------------------------------------------------------
# Build
# ------------------------------------------------------------------------------
Expand Down Expand Up @@ -191,7 +198,7 @@ verify.generators: verify.repo generate verify.diff
API_DIR ?= api

.PHONY: generate
generate: generate.api generate.clientsets generate.rbacs generate.gateway-api-urls generate.docs generate.k8sio-gomod-replace generate.testcases-registration generate.kic-webhook-config
generate: generate.api generate.clientsets generate.rbacs generate.gateway-api-urls generate.docs generate.k8sio-gomod-replace generate.testcases-registration generate.kic-webhook-config generate.mocks

.PHONY: generate.api
generate.api: controller-gen
Expand Down Expand Up @@ -388,6 +395,11 @@ test.conformance:
test.samples: kustomize
find ./config/samples -not -name "kustomization.*" -type f | sort | xargs -I{} bash -c "kubectl apply -f {}; kubectl delete -f {}"

# https://github.com/vektra/mockery/issues/803#issuecomment-2287198024
.PHONY: generate.mocks
generate.mocks: mockery
GODEBUG=gotypesalias=0 $(MOCKERY)

# ------------------------------------------------------------------------------
# Gateway API
# ------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package konnect
package conditions

// TODO(pmalek): move this to Konnect API directory so that it's part of the API contract.
// https://github.com/Kong/kubernetes-configuration/issues/14
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package konnect
package constraints

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -25,9 +25,9 @@ type SupportedKonnectEntityType interface {
}

// EntityType is an interface that all Konnect entity types must implement.
// Separating this from SupportedKonnectEntityType allows us to use EntityType
// Separating this from constraints.SupportedKonnectEntityType allows us to use EntityType
// where client.Object is required, since it embeds client.Object and uses pointer
// to refer to the SupportedKonnectEntityType.
// to refer to the constraints.SupportedKonnectEntityType.
type EntityType[T SupportedKonnectEntityType] interface {
*T
// Kubernetes Object methods
Expand Down
7 changes: 7 additions & 0 deletions controller/konnect/constraints/entitytypename.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package constraints

// EntityTypeName returns the name of the entity type.
func EntityTypeName[T SupportedKonnectEntityType]() string {
var e T
return e.GetTypeName()
}
6 changes: 0 additions & 6 deletions controller/konnect/entitytypename.go

This file was deleted.

19 changes: 0 additions & 19 deletions controller/konnect/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,6 @@ import (
"k8s.io/apimachinery/pkg/types"
)

// FailedKonnectOpError is an error type that is returned when an operation against
// Konnect API fails.
type FailedKonnectOpError[T SupportedKonnectEntityType] struct {
Op Op
Err error
}

// Error implements the error interface.
func (e FailedKonnectOpError[T]) Error() string {
return fmt.Sprintf("failed to %s %s on Konnect: %v",
e.Op, entityTypeName[T](), e.Err,
)
}

// Unwrap returns the underlying error.
func (e FailedKonnectOpError[T]) Unwrap() error {
return e.Err
}

// ReferencedControlPlaneDoesNotExistError is an error type that is returned when
// a Konnect entity references a KonnectGatewayControlPlane that does not exist.
type ReferencedControlPlaneDoesNotExistError struct {
Expand Down
6 changes: 4 additions & 2 deletions controller/konnect/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package konnect
import (
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/kong/gateway-operator/controller/konnect/constraints"

configurationv1alpha1 "github.com/kong/kubernetes-configuration/api/configuration/v1alpha1"
)

Expand All @@ -14,8 +16,8 @@ type ReconciliationIndexOption struct {
}

// ReconciliationIndexOptionsForEntity returns required index options for controller reconciliing the entity.
func ReconciliationIndexOptionsForEntity[T SupportedKonnectEntityType,
TEnt EntityType[T]](ent TEnt) []ReconciliationIndexOption {
func ReconciliationIndexOptionsForEntity[T constraints.SupportedKonnectEntityType,
TEnt constraints.EntityType[T]](ent TEnt) []ReconciliationIndexOption {
switch any(ent).(type) { //nolint:gocritic // TODO: add index options required for other entities
case *configurationv1alpha1.KongPluginBinding:
return IndexOptionsForKongPluginBinding()
Expand Down
15 changes: 15 additions & 0 deletions controller/konnect/ops/controlplane.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package ops

import (
"context"

sdkkonnectcomp "github.com/Kong/sdk-konnect-go/models/components"
sdkkonnectops "github.com/Kong/sdk-konnect-go/models/operations"
)

// ControlPlaneSDK is the interface for the Konnect ControlPlaneSDK SDK.
type ControlPlaneSDK interface {
CreateControlPlane(ctx context.Context, req sdkkonnectcomp.CreateControlPlaneRequest, opts ...sdkkonnectops.Option) (*sdkkonnectops.CreateControlPlaneResponse, error)
DeleteControlPlane(ctx context.Context, id string, opts ...sdkkonnectops.Option) (*sdkkonnectops.DeleteControlPlaneResponse, error)
UpdateControlPlane(ctx context.Context, id string, req sdkkonnectcomp.UpdateControlPlaneRequest, opts ...sdkkonnectops.Option) (*sdkkonnectops.UpdateControlPlaneResponse, error)
}
Loading

0 comments on commit a3b231e

Please sign in to comment.