Skip to content

Commit

Permalink
Merge pull request #207 from Ajpantuso/apantuso/status_controller_cle…
Browse files Browse the repository at this point in the history
…anup

Apantuso/status controller cleanup
  • Loading branch information
Ajpantuso authored May 17, 2023
2 parents 5079d7e + 6d54bd9 commit 9bd7161
Show file tree
Hide file tree
Showing 10 changed files with 181 additions and 113 deletions.
27 changes: 13 additions & 14 deletions cmd/reference-addon-manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (
"github.com/go-logr/logr"
av1alpha1 "github.com/openshift/addon-operator/apis/addons/v1alpha1"
refapis "github.com/openshift/reference-addon/apis"
"github.com/openshift/reference-addon/internal/controllers/addoninstance"
ractrl "github.com/openshift/reference-addon/internal/controllers/referenceaddon"
"github.com/openshift/reference-addon/internal/controllers/status"
"github.com/openshift/reference-addon/internal/metrics"
"github.com/openshift/reference-addon/internal/pprof"
opsv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
Expand All @@ -31,7 +31,7 @@ func main() {
ParameterSecretname: "addon-reference-addon-parameters",
ProbeAddr: ":8081",
AddonInstanceName: "addon-instance",
RetryAfterTime: 10 * time.Second,
HeartbeatInterval: 10 * time.Second,
Zap: zap.Options{
Development: true,
},
Expand Down Expand Up @@ -135,22 +135,21 @@ func setupManager(log logr.Logger, opts options) (ctrl.Manager, error) {
return nil, fmt.Errorf("setting up reference addon controller: %w", err)
}

// status controller
statusctlr, statuserr := addoninstance.NewStatusControllerReconciler(
statusctlr, err := status.NewStatusControllerReconciler(
client,
addoninstance.WithLog{Log: ctrl.Log.WithName("controller").WithName("addoninstance")},
addoninstance.WithAddonInstanceNamespace(opts.Namespace),
addoninstance.WithAddonInstanceName(opts.AddonInstanceName),
addoninstance.WithReferenceAddonNamespace(opts.Namespace),
addoninstance.WithReferenceAddonName(opts.OperatorName),
addoninstance.WithRetryAfterTime(opts.RetryAfterTime),
status.WithLog{Log: ctrl.Log.WithName("controller").WithName("status")},
status.WithAddonInstanceNamespace(opts.AddonInstanceNamespace),
status.WithAddonInstanceName(opts.AddonInstanceName),
status.WithReferenceAddonNamespace(opts.Namespace),
status.WithReferenceAddonName(opts.OperatorName),
status.WithHeartbeatInterval(opts.HeartbeatInterval),
)
if statuserr != nil {
return nil, fmt.Errorf("initializing addon instance controller: %w", statuserr)
if err != nil {
return nil, fmt.Errorf("initializing status controller: %w", err)
}

if statuserr := statusctlr.SetupWithManager(mgr); statuserr != nil {
return nil, fmt.Errorf("setting up addon instance controller: %w", statuserr)
if err := statusctlr.SetupWithManager(mgr); err != nil {
return nil, fmt.Errorf("setting up status controller: %w", err)
}

return mgr, nil
Expand Down
18 changes: 13 additions & 5 deletions cmd/reference-addon-manager/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ type options struct {
ProbeAddr string
AddonInstanceName string
AddonInstanceNamespace string
RetryAfterTime time.Duration
HeartbeatInterval time.Duration
Zap zap.Options
}

func (o *options) Process() error {
o.processFlags()
o.processSecrets()
o.applyValuesFromOptions()

return o.validate()
}
Expand Down Expand Up @@ -114,10 +115,11 @@ func (o *options) processFlags() {
"The namespace addon instance exists in.",
)

flags.Duration(
"retry-after-time",
o.RetryAfterTime,
"Time between retries for addon instance",
flags.DurationVar(
&o.HeartbeatInterval,
"heartbeat-interval",
o.HeartbeatInterval,
"Time between heartbeats sent to addon instance",
)

o.Zap.BindFlags(flags)
Expand All @@ -143,6 +145,12 @@ func (o *options) processSecrets() {
}
}

func (o *options) applyValuesFromOptions() {
if o.AddonInstanceNamespace == "" {
o.AddonInstanceNamespace = o.Namespace
}
}

var ErrEmptyValue = errors.New("empty value")

func (o *options) validate() error {
Expand Down
5 changes: 1 addition & 4 deletions config/deploy/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,12 @@ rules:
resources:
- addoninstances
- addoninstances/status
- addoninstances/finalizers
verbs:
- get
- watch
- list
- create
- update
- patch
- delete
- update
- apiGroups:
- ""
resources:
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ go 1.19

require (
github.com/go-logr/logr v1.2.4
github.com/magefile/mage v1.14.0
github.com/magefile/mage v1.15.0
github.com/mt-sre/go-ci v0.6.5
github.com/onsi/ginkgo/v2 v2.9.5
github.com/onsi/gomega v1.27.6
github.com/openshift/addon-operator v1.10.1
github.com/openshift/addon-operator/apis v0.0.0-20230505081548-bce54f373482
github.com/operator-framework/api v0.17.5
github.com/otiai10/copy v1.11.0
github.com/prometheus/client_golang v1.15.0
github.com/prometheus/client_golang v1.15.1
github.com/stretchr/testify v1.8.2
go.uber.org/multierr v1.11.0
gopkg.in/yaml.v3 v3.0.1
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/magefile/mage v1.14.0 h1:6QDX3g6z1YvJ4olPhT1wksUcSa/V0a1B+pJb73fBjyo=
github.com/magefile/mage v1.14.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
github.com/magefile/mage v1.15.0 h1:BvGheCMAsG3bWUDbZ8AyXXpCNwU9u5CB6sM+HNb9HYg=
github.com/magefile/mage v1.15.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo=
Expand Down Expand Up @@ -151,8 +151,8 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.63.0 h1:efsW3CfymG5bZUpeIsYfdihB33YItCn7uHBOEbnHQG8=
github.com/prometheus/client_golang v1.15.0 h1:5fCgGYogn0hFdhyhLbw7hEsWxufKtY9klyvdNfFlFhM=
github.com/prometheus/client_golang v1.15.0/go.mod h1:e9yaBhRPU2pPNsZwE+JdQl0KEt1N9XgF6zxWmaC0xOk=
github.com/prometheus/client_golang v1.15.1 h1:8tXpTmJbyH5lydzFPoxSIJ0J46jdh3tylbvM1xCv0LI=
github.com/prometheus/client_golang v1.15.1/go.mod h1:e9yaBhRPU2pPNsZwE+JdQl0KEt1N9XgF6zxWmaC0xOk=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/prometheus/client_model v0.3.0 h1:UBgGFHqYdG/TPFD1B1ogZywDqEkwp3fBMvqdiQ7Xew4=
github.com/prometheus/client_model v0.3.0/go.mod h1:LDGWKZIo7rky3hgvBe+caln+Dr3dPggB5dvjtD7w9+w=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package integration

import (
"context"
"fmt"
"os/exec"
"time"

Expand All @@ -27,6 +28,7 @@ var _ = Describe("Status Controller", func() {
namespaceGen = nameGenerator("ref-test-namespace")
operatorName string
operatorNameGen = nameGenerator("ref-test-name")
heartbeatInterval = 1 * time.Second
)

BeforeEach(func() {
Expand All @@ -46,6 +48,7 @@ var _ = Describe("Status Controller", func() {
"-delete-label", deleteLabel,
"-operator-name", operatorName,
"-kubeconfig", _kubeConfigPath,
"-heartbeat-interval", heartbeatInterval.String(),
)

session, err := Start(manager, GinkgoWriter, GinkgoWriter)
Expand Down Expand Up @@ -98,6 +101,10 @@ var _ = Describe("Status Controller", func() {

return addonInstance.Status.Conditions
}, 10*time.Second).Should(ContainElements(EqualCondition(expectedCondition)))

fmt.Printf("%+v\n", addonInstance)

Expect(addonInstance.Spec.HeartbeatUpdatePeriod.Duration).To(Equal(heartbeatInterval))
})
})
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package addoninstance
package status

import (
"time"
Expand Down Expand Up @@ -36,8 +36,8 @@ func (w WithReferenceAddonName) ConfigureStatusControllerReconciler(c *StatusCon
c.ReferenceAddonName = string(w)
}

type WithRetryAfterTime int
type WithHeartbeatInterval time.Duration

func (w WithRetryAfterTime) ConfigureStatusControllerReconciler(c *StatusControllerReconcilerConfig) {
c.RetryAfterTime = time.Duration(w)
func (w WithHeartbeatInterval) ConfigureStatusControllerReconciler(c *StatusControllerReconcilerConfig) {
c.HeartBeatInterval = time.Duration(w)
}
Loading

0 comments on commit 9bd7161

Please sign in to comment.