Skip to content

Commit

Permalink
API for feature toggles (#429)
Browse files Browse the repository at this point in the history
* API for feature toggles

* Update toolchainconfig_types.go

Co-authored-by: Matous Jobanek <mjobanek@redhat.com>

* regenerate

* feature toggle annotation key

* Update api/v1alpha1/toolchainconfig_types.go

Co-authored-by: Matous Jobanek <mjobanek@redhat.com>

---------

Co-authored-by: Matous Jobanek <mjobanek@redhat.com>
  • Loading branch information
alexeykazakov and MatousJobanek authored Jun 20, 2024
1 parent 92c6051 commit a29b6c6
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 1 deletion.
43 changes: 43 additions & 0 deletions api/v1alpha1/toolchainconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ const (
ToolchainConfigSyncComplete ConditionType = "SyncComplete"
ToolchainConfigRegServiceDeploy ConditionType = "RegServiceDeploy"

// FeatureToggleNameAnnotationKey is used for referring tier template objects to feature toggles defined in configuration
FeatureToggleNameAnnotationKey = LabelKeyPrefix + "feature"

// Status condition reasons
// ToolchainConfigSyncedReason when the MemberOperatorConfigs were successfully synced to the member clusters
ToolchainConfigSyncedReason = "Synced"
Expand Down Expand Up @@ -459,6 +462,14 @@ type TiersConfig struct {
// +optional
DefaultSpaceTier *string `json:"defaultSpaceTier,omitempty"`

// FeatureToggles specifies the list of feature toggles/flags
// +optional
// +patchMergeKey=name
// +patchStrategy=merge
// +listType=map
// +listMapKey=name
FeatureToggles []FeatureToggle `json:"featureToggles,omitempty" patchStrategy:"merge" patchMergeKey:"name"`

// DurationBeforeChangeTierRequestDeletion specifies the duration before a ChangeTierRequest resource is deleted
// +optional
DurationBeforeChangeTierRequestDeletion *string `json:"durationBeforeChangeTierRequestDeletion,omitempty"`
Expand All @@ -469,6 +480,38 @@ type TiersConfig struct {
TemplateUpdateRequestMaxPoolSize *int `json:"templateUpdateRequestMaxPoolSize,omitempty"`
}

// FeatureToggle defines a feature toggle/flag. Each feature is supposed to have a unique name.
// Features are represented by kube object manifests in space and user templates.
// Such manifests must have an annotation which refers to the corresponding feature name.
// For example a manifest for a RoleBinding object in a space tier template with the following annotation:
// "toolchain.dev.openshift.com/feature: os-lightspeed" would refer to a feature with "os-lightspeed" name.
// When that template is applied for a new space then that RoleBinding object would be applied conditionally,
// according to its weight.
// +k8s:openapi-gen=true
type FeatureToggle struct {
// A unique name of the feature
Name string `json:"name"`
// Rollout weight of the feature. An integer between 0-100.
// If not set then 100 is used by default.
// 0 means the corresponding feature should not be enabled at all, which means
// that corresponding template objects should not be applied at all.
// 100 means the feature should be always enabled (the template is always applied).
// The features are weighted independently of each other.
// For example if there are two features:
// - feature1, weight=5
// - feature2, weight=90
// And tiers (one or many) contain the following object manifests:
// - RoleBinding with "toolchain.dev.openshift.com/feature: feature1" annotation
// - ConfigMap with "toolchain.dev.openshift.com/feature: feature2" annotation
// Then the RoleBinding will be created for the corresponding tiers with probability of 0.05 (around 5 out of every 100 spaces would have it)
// And the ConfigMap will be created with probability of 0.9 (around 90 out of every 100 spaces would have it)
// +optional
// +kubebuilder:validation:Minimum=0
// +kubebuilder:validation:Maximum=100
// +kubebuilder:default=100
Weight *uint `json:"weight,omitempty"`
}

// UsersConfig contains all configuration parameters related to users
// +k8s:openapi-gen=true
type UsersConfig struct {
Expand Down
27 changes: 27 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.

58 changes: 57 additions & 1 deletion api/v1alpha1/zz_generated.openapi.go

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

0 comments on commit a29b6c6

Please sign in to comment.