Skip to content

Commit

Permalink
✨ Adapt new cluster stack convention
Browse files Browse the repository at this point in the history
Adapt controller with runtime sdk

- API change for hook
- Control loop for new way of cluster addon
- fix hook server
- update packages

Signed-off-by: Aniruddha Basak <aniruddha.basak@syself.com>
  • Loading branch information
aniruddha2000 committed Feb 8, 2024
1 parent d92b652 commit 6ca9f67
Show file tree
Hide file tree
Showing 757 changed files with 83,576 additions and 1,889 deletions.
23 changes: 23 additions & 0 deletions api/v1alpha1/clusteraddon_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ const (
ClusterAddonFinalizer = "clusteraddon.clusterstack.x-k8s.io"
)

// HelmChartStatusConditions defines the status of helm chart in the cluster addon.
type HelmChartStatusConditions string

var (
None = HelmChartStatusConditions("")
WaitingForPreCondition = HelmChartStatusConditions("waitingForPreCondition")
ApplyingOrDeleting = HelmChartStatusConditions("applyingOrDeleting")
WaitingForPostCondition = HelmChartStatusConditions("waitingForPostCondition")
Done = HelmChartStatusConditions("done")
)

// ClusterAddonSpec defines the desired state of a ClusterAddon object.
type ClusterAddonSpec struct {
// ClusterStack is the full string <provider>-<name>-<Kubernetes version>-<version> that will be filled with the cluster stack that
Expand All @@ -38,6 +49,10 @@ type ClusterAddonSpec struct {
// +optional
Version string `json:"version,omitempty"`

// Hook specifies the runtime hook for the Cluster event.
// +optional
Hook string `json:"hook,omitempty"`

// ClusterRef is the reference to the clusterv1.Cluster object that corresponds to the workload cluster where this
// controller applies the cluster addons.
ClusterRef *corev1.ObjectReference `json:"clusterRef"`
Expand All @@ -49,6 +64,14 @@ type ClusterAddonStatus struct {
// +optional
Resources []*Resource `json:"resources,omitempty"`

// CurrentHook specifies the current running Hook.
// +optional
CurrentHook string `json:"currentHook,omitempty"`

// HelmChartStatus defines the status of helm chart in the cluster addon.
// +optional
HelmChartStatus map[string]HelmChartStatusConditions `json:"helmChartStatus,omitempty"`

// +optional
// +kubebuilder:default:=false
Ready bool `json:"ready"`
Expand Down
27 changes: 27 additions & 0 deletions api/v1alpha1/conditions_const.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,25 @@ const (
ControlPlaneNotReadyReason = "ControlPlaneNotReady"
)

const (
// EvaluatedCELCondition reports on whether the CEL expression is evaluated properly.
EvaluatedCELCondition clusterv1.ConditionType = "EvaluatedCEL"

// FailedToEvaluatePreConditionReason is used when some pre CEL expression have been failed to evaluate.
FailedToEvaluatePreConditionReason = "FailedToEvaluatePreCondition"

// FailedToEvaluatePostConditionReason is used when some post CEL expression have been failed to evaluate.
FailedToEvaluatePostConditionReason = "FailedToEvaluatePostCondition"
)

const (
// HelmChartFoundCondition reports when mentioned helm chart is present in the cluster addon tar archive.
HelmChartFoundCondition = "HelmChartFound"

// HelmChartMissingReason is used when mentioned helm chart is missing in the cluster addon tar archive.
HelmChartMissingReason = "HelmChartMissing"
)

const (
// HelmChartAppliedCondition reports on whether the relevant helm chart has been applied.
HelmChartAppliedCondition clusterv1.ConditionType = "HelmChartApplied"
Expand All @@ -37,6 +56,14 @@ const (
ObjectsApplyingOngoingReason = "ObjectsApplyingOngoing"
)

const (
// HelmChartDeletedCondition reports on whether the relevant helm chart has been applied.
HelmChartDeletedCondition clusterv1.ConditionType = "HelmChartDeleted"

// FailedToApplyObjectsReason is used when some objects have been failed to delete.
FailedToDeleteObjectsReason = "FailedToDeleteObjects"
)

const (
// ProviderClusterStackReleasesSyncedCondition reports on whether the ProviderClusterStackReleases are ready.
ProviderClusterStackReleasesSyncedCondition = "ProviderClusterStackReleasesSynced"
Expand Down
7 changes: 7 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.

2 changes: 2 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
_ "k8s.io/client-go/plugin/pkg/client/auth"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
dockerv1beta1 "sigs.k8s.io/cluster-api/test/infrastructure/docker/api/v1beta1"
"sigs.k8s.io/cluster-api/util/record"
ctrl "sigs.k8s.io/controller-runtime"
controllerruntimecontroller "sigs.k8s.io/controller-runtime/pkg/controller"
Expand All @@ -51,6 +52,7 @@ var (
func init() {
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
utilruntime.Must(csov1alpha1.AddToScheme(scheme))
utilruntime.Must(dockerv1beta1.AddToScheme(scheme))
utilruntime.Must(clusterv1.AddToScheme(scheme))
//+kubebuilder:scaffold:scheme
}
Expand Down
14 changes: 14 additions & 0 deletions config/crd/bases/clusterstack.x-k8s.io_clusteraddons.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ spec:
the respective cluster uses currently. It always matches cluster.spec.topology.class
if the work of this controller is done.
type: string
hook:
description: Hook specifies the runtime hook for the Cluster event.
type: string
version:
description: Version is the version of the cluster addons that have
been applied in the workload cluster.
Expand Down Expand Up @@ -152,6 +155,17 @@ spec:
- type
type: object
type: array
currentHook:
description: CurrentHook specifies the current running Hook.
type: string
helmChartStatus:
additionalProperties:
description: HelmChartStatusConditions defines the status of helm
chart in the cluster addon.
type: string
description: HelmChartStatus defines the status of helm chart in the
cluster addon.
type: object
ready:
default: false
type: boolean
Expand Down
7 changes: 4 additions & 3 deletions extension/go.mod
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
module github.com/SovereignCloudStack/cluster-stack-operator/extension

go 1.19
go 1.21

toolchain go1.21.6

replace github.com/SovereignCloudStack/cluster-stack-operator => ../

require (
github.com/SovereignCloudStack/cluster-stack-operator v0.1.0-alpha.2
github.com/spf13/pflag v1.0.5
github.com/sovereigncloudstack/cluster-stack-operator v0.0.0-00010101000000-000000000000
k8s.io/apimachinery v0.29.0
k8s.io/component-base v0.28.4
k8s.io/klog/v2 v2.110.1
Expand All @@ -15,7 +17,6 @@ require (
)

require (
github.com/SovereignCloudStack/cluster-stack-operator v0.1.0-alpha.2 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
Expand Down
10 changes: 4 additions & 6 deletions extension/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ github.com/Masterminds/semver/v3 v3.2.0 h1:3MEsd0SM6jqZojhjLWWeBY+Kcjy9i6MQAeY7Y
github.com/Masterminds/semver/v3 v3.2.0/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ=
github.com/Masterminds/sprig/v3 v3.2.3 h1:eL2fZNezLomi0uOLqjQoN6BfsDD+fyLtgbJMAj9n6YA=
github.com/Masterminds/sprig/v3 v3.2.3/go.mod h1:rXcFaZ2zZbLRJv/xSysmlgIM1u11eBaRMhvYXJNkGuM=
github.com/SovereignCloudStack/cluster-stack-operator v0.1.0-alpha.2 h1:23sNJB4z0wiguCeG0W+GdusBrRNYGcKsUYLZo01wZNs=
github.com/SovereignCloudStack/cluster-stack-operator v0.1.0-alpha.2/go.mod h1:qXyqN2aZ+JCtVIVMNdr736b+3XNmaOhsXjGZuMUUUp0=
github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230305170008-8188dc5388df h1:7RFfzj4SSt6nnvCPbCqijJi1nWCd+TqAT3bYCStRC18=
github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230305170008-8188dc5388df/go.mod h1:pSwJ0fSY5KhvocuWSx4fz3BA8OrA1bQn+K1Eli3BRwM=
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a h1:idn718Q4B6AGu/h5Sxe66HYVdqdGu2l9Iebqhi/AEoA=
Expand Down Expand Up @@ -115,8 +113,8 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/onsi/ginkgo/v2 v2.13.2 h1:Bi2gGVkfn6gQcjNjZJVO8Gf0FHzMPf2phUei9tejVMs=
github.com/onsi/ginkgo/v2 v2.13.2/go.mod h1:XStQ8QcGwLyF4HdfcZB8SFOS/MWCgDuXMSBe6zrvLgM=
github.com/onsi/ginkgo/v2 v2.13.1 h1:LNGfMbR2OVGBfXjvRZIZ2YCTQdGKtPLvuI1rMCCj3OU=
github.com/onsi/ginkgo/v2 v2.13.1/go.mod h1:XStQ8QcGwLyF4HdfcZB8SFOS/MWCgDuXMSBe6zrvLgM=
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/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
Expand Down Expand Up @@ -162,8 +160,8 @@ github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9dec
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
go.uber.org/goleak v1.2.1 h1:NBol2c7O1ZokfZ0LEU9K6Whx/KnwvepVetCUhtKja4A=
go.uber.org/goleak v1.2.1/go.mod h1:qlT2yGI9QafXHhZZLxlSuNsMw3FFLxBr+tBRlmO1xH4=
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
Expand Down
10 changes: 10 additions & 0 deletions extension/handlers/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ func (e *ExtensionHandler) DoBeforeClusterUpgrade(ctx context.Context, request *
}
}()

clusterAddon.Spec.Hook = "BeforeClusterUpgrade"

if conditions.IsFalse(clusterAddon, csov1alpha1.HelmChartAppliedCondition) {
// wait N seconds
response.SetRetryAfterSeconds(10)
Expand Down Expand Up @@ -110,6 +112,14 @@ func (e *ExtensionHandler) DoAfterControlPlaneInitialized(ctx context.Context, r
}
}()

clusterAddon.Spec.Hook = "AfterControlPlaneInitialized"

if err := e.client.Update(ctx, clusterAddon); err != nil {
response.SetStatus(runtimehooksv1.ResponseStatusFailure)
response.SetMessage(fmt.Sprintf("failed to update cluster addon: %s", err.Error()))
return
}

response.SetStatus(runtimehooksv1.ResponseStatusSuccess)
return
}

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

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

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

2 changes: 0 additions & 2 deletions extension/vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,6 @@ github.com/prometheus/common/model
github.com/prometheus/procfs
github.com/prometheus/procfs/internal/fs
github.com/prometheus/procfs/internal/util
# github.com/sovereigncloudstack/cluster-stack-operator v0.0.0-00010101000000-000000000000
## explicit
# github.com/spf13/cobra v1.8.0
## explicit; go 1.15
github.com/spf13/cobra
Expand Down
18 changes: 12 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.19
require (
github.com/go-logr/logr v1.2.4
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572
github.com/google/cel-go v0.19.0
github.com/google/go-github/v52 v52.0.0
github.com/onsi/ginkgo/v2 v2.11.0
github.com/onsi/gomega v1.27.8
Expand All @@ -25,6 +26,7 @@ require (
require (
github.com/BurntSushi/toml v1.0.0 // indirect
github.com/alessio/shellescape v1.4.1 // indirect
github.com/antlr4-go/antlr/v4 v4.13.0 // indirect
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 // indirect
github.com/google/safetext v0.0.0-20220905092116-b49f7bc46da2 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
Expand All @@ -33,7 +35,11 @@ require (
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/spf13/cobra v1.7.0 // indirect
github.com/stoewer/go-strcase v1.2.0 // indirect
github.com/stretchr/objx v0.5.1 // indirect
golang.org/x/exp v0.0.0-20230515195305-f3d0a9c9a5cc // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240205150955-31a09d347014 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240125205218-1f4bbc51befe // indirect
k8s.io/cluster-bootstrap v0.27.2 // indirect
)

Expand Down Expand Up @@ -84,16 +90,16 @@ require (
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
go.uber.org/zap v1.24.0
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/term v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/crypto v0.16.0 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/term v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.12.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.3.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.31.0 // indirect
google.golang.org/protobuf v1.32.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.1
Expand Down
Loading

0 comments on commit 6ca9f67

Please sign in to comment.