Skip to content

Commit

Permalink
Merge branch 'main' into feat/support-for-account-extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronschweig committed Apr 25, 2024
2 parents 1935d60 + 5d53ef3 commit 3a5d3c6
Show file tree
Hide file tree
Showing 19 changed files with 29 additions and 21 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
bin/*
Dockerfile.cross
.secret
.env

# Test binary, built with `go test -c`
*.test
Expand Down
2 changes: 1 addition & 1 deletion .testcoverage.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
exclude:
paths:
- ^internal/subroutines/mocks # exclude generated mock files
- ^pkg/subroutines/mocks # exclude generated mock files
- api/v1alpha1 # skipping generated files and crd type definitions
- main\.go$ # skip covering main.go

Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ COPY main.go main.go
COPY cmd/ cmd/
COPY api/ api/
COPY internal/ internal/
COPY pkg/ pkg/


# Build
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha1/account_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type AccountSpec struct {
Description *string `json:"description,omitempty"`

// The initial creator of this account
Creator string `json:"creator"`
Creator *string `json:"creator,omitempty"`

Extensions []Extension `json:"extensions,omitempty"`
}
Expand Down
5 changes: 5 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

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

1 change: 0 additions & 1 deletion chart/crds/core.openmfp.io_accounts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ spec:
- account
type: string
required:
- creator
- displayName
- type
type: object
Expand Down
2 changes: 1 addition & 1 deletion cmd/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func RunController(cmd *cobra.Command, args []string) { // coverage-ignore
}

accountReconciler := controller.NewAccountReconciler(log, mgr, cfg)
if err := accountReconciler.SetupWithManager(mgr, cfg); err != nil {
if err := accountReconciler.SetupWithManager(mgr, cfg, log); err != nil {
log.Fatal().Err(err).Str("controller", "Account").Msg("unable to create controller")
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.22.0

require (
github.com/Masterminds/sprig/v3 v3.2.3
github.com/openmfp/golang-commons v0.16.0
github.com/openmfp/golang-commons v0.21.0
github.com/rs/zerolog v1.32.0
github.com/spf13/cobra v1.7.0
github.com/stretchr/testify v1.9.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ github.com/onsi/ginkgo/v2 v2.14.0 h1:vSmGj2Z5YPb9JwCWT6z6ihcUvDhuXLc3sJiqd3jMKAY
github.com/onsi/ginkgo/v2 v2.14.0/go.mod h1:JkUdW7JkN0V6rFvsHcJ478egV3XH9NxpD27Hal/PhZw=
github.com/onsi/gomega v1.30.0 h1:hvMK7xYz4D3HapigLTeGdId/NcfQx1VHMJc60ew99+8=
github.com/onsi/gomega v1.30.0/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ=
github.com/openmfp/golang-commons v0.16.0 h1:8FAS3Gw6tFOXJOlBcwDrzopppn9Tj4itnoLcXODttqQ=
github.com/openmfp/golang-commons v0.16.0/go.mod h1:7yzpBpF7KZLq4i/iVOsPwVPkVnCYiZ685PMC1AF7fZk=
github.com/openmfp/golang-commons v0.21.0 h1:WOyV4jxNZj301XarzTncuYvAcgOorUD/MUxMUrsfV5Q=
github.com/openmfp/golang-commons v0.21.0/go.mod h1:AE1DH+O57gAIKOKD6waJPAxXRo47nbDQp4V08mJ+Ux8=
github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4=
github.com/pingcap/errors v0.11.4/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
Expand Down
8 changes: 4 additions & 4 deletions internal/controller/account_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

corev1alpha1 "github.com/openmfp/account-operator/api/v1alpha1"
"github.com/openmfp/account-operator/internal/config"
"github.com/openmfp/account-operator/internal/subroutines"
"github.com/openmfp/account-operator/pkg/subroutines"
"github.com/openmfp/golang-commons/controller/lifecycle"
"github.com/openmfp/golang-commons/logger"
)
Expand All @@ -51,14 +51,14 @@ func NewAccountReconciler(log *logger.Logger, mgr ctrl.Manager, cfg config.Confi
subs = append(subs, subroutines.NewExtensionReadySubroutine(mgr.GetClient()))
}
return &AccountReconciler{
lifecycle: lifecycle.NewLifecycleManager(log, operatorName, accountReconcilerName, mgr.GetClient(), subs).WithSpreadingReconciles(),
lifecycle: lifecycle.NewLifecycleManager(log, operatorName, accountReconcilerName, mgr.GetClient(), subs).WithSpreadingReconciles().WithConditionManagement(),
}
}

func (r *AccountReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
return r.lifecycle.Reconcile(ctx, req, &corev1alpha1.Account{})
}

func (r *AccountReconciler) SetupWithManager(mgr ctrl.Manager, cfg config.Config, eventPredicates ...predicate.Predicate) error {
return r.lifecycle.SetupWithManager(mgr, cfg.MaxConcurrentReconciles, accountReconcilerName, &corev1alpha1.Account{}, cfg.DebugLabelValue, r, eventPredicates...)
func (r *AccountReconciler) SetupWithManager(mgr ctrl.Manager, cfg config.Config, log *logger.Logger, eventPredicates ...predicate.Predicate) error {
return r.lifecycle.SetupWithManager(mgr, cfg.MaxConcurrentReconciles, accountReconcilerName, &corev1alpha1.Account{}, cfg.DebugLabelValue, r, log, eventPredicates...)
}
4 changes: 2 additions & 2 deletions internal/controller/account_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (

corev1alpha1 "github.com/openmfp/account-operator/api/v1alpha1"
"github.com/openmfp/account-operator/internal/config"
"github.com/openmfp/account-operator/internal/subroutines"
"github.com/openmfp/account-operator/pkg/subroutines"
openmfpcontext "github.com/openmfp/golang-commons/context"
"github.com/openmfp/golang-commons/logger"
networkv1 "k8s.io/api/networking/v1"
Expand Down Expand Up @@ -84,7 +84,7 @@ func (suite *AccountTestSuite) SetupSuite() {
suite.Nil(err)

accountReconciler := NewAccountReconciler(log, suite.kubernetesManager, cfg)
err = accountReconciler.SetupWithManager(suite.kubernetesManager, cfg)
err = accountReconciler.SetupWithManager(suite.kubernetesManager, cfg, log)
suite.Nil(err)

go suite.startController()
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"testing"

"github.com/openmfp/account-operator/api/v1alpha1"
"github.com/openmfp/account-operator/internal/subroutines"
"github.com/openmfp/account-operator/internal/subroutines/mocks"
"github.com/openmfp/account-operator/pkg/subroutines"
"github.com/openmfp/account-operator/pkg/subroutines/mocks"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
kerrors "k8s.io/apimachinery/pkg/api/errors"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"testing"

"github.com/openmfp/account-operator/api/v1alpha1"
"github.com/openmfp/account-operator/internal/subroutines"
"github.com/openmfp/account-operator/internal/subroutines/mocks"
"github.com/openmfp/account-operator/pkg/subroutines"
"github.com/openmfp/account-operator/pkg/subroutines/mocks"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -541,6 +541,7 @@ func TestExtensionSubroutine_Finalize(t *testing.T) {
}

func TestRenderExtensionSpec(t *testing.T) {
creator := "user"
us := unstructured.Unstructured{
Object: map[string]interface{}{},
}
Expand All @@ -553,7 +554,7 @@ func TestRenderExtensionSpec(t *testing.T) {
},
}, &v1alpha1.Account{
Spec: v1alpha1.AccountSpec{
Creator: "user",
Creator: &creator,
},
}, &us, []string{"spec"})
assert.NoError(t, err)
Expand All @@ -570,21 +571,22 @@ func TestRenderExtensionSpec(t *testing.T) {
},
}, &v1alpha1.Account{
Spec: v1alpha1.AccountSpec{
Creator: "user",
Creator: &creator,
},
}, &us, []string{"spec"})
assert.NoError(t, err)
}

func TestRenderExtensionSpecInvalidTemplate(t *testing.T) {
creator := ""
us := unstructured.Unstructured{
Object: map[string]interface{}{},
}
err := subroutines.RenderExtensionSpec(context.Background(), map[string]any{
"foo": "{{ .Account }",
}, &v1alpha1.Account{
Spec: v1alpha1.AccountSpec{
Creator: "user",
Creator: &creator,
},
}, &us, []string{"spec"})
assert.Error(t, err)
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"

corev1alpha1 "github.com/openmfp/account-operator/api/v1alpha1"
"github.com/openmfp/account-operator/internal/subroutines/mocks"
"github.com/openmfp/account-operator/pkg/subroutines/mocks"
)

const defaultExpectedTestNamespace = "account-test"
Expand Down

0 comments on commit 3a5d3c6

Please sign in to comment.