Skip to content

Commit ff2e9be

Browse files
authored
feat: add feature rules (#92)
1 parent 3a6bad0 commit ff2e9be

File tree

9 files changed

+687
-16
lines changed

9 files changed

+687
-16
lines changed

api/v1beta1/growthbookfeature_types.go

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ type GrowthbookFeatureSpec struct {
3131
Environments []Environment `json:"environments,omitempty"`
3232
}
3333

34+
// +kubebuilder:validation:Enum=boolean;string;number;json
3435
type FeatureValueType string
3536

3637
var (
@@ -40,6 +41,71 @@ var (
4041
FeatureValueTypeJSON FeatureValueType = "json"
4142
)
4243

44+
// +kubebuilder:validation:Enum=all;none;any
45+
type SavedGroupTargetingMatch string
46+
47+
var (
48+
SavedGroupTargetingMatchAll SavedGroupTargetingMatch = "all"
49+
SavedGroupTargetingMatchNone SavedGroupTargetingMatch = "none"
50+
SavedGroupTargetingMatchAny SavedGroupTargetingMatch = "any"
51+
)
52+
53+
// +kubebuilder:validation:Enum=force;rollout;experiment
54+
type FeatureRuleType string
55+
56+
var (
57+
FeatureRuleTypeForce FeatureRuleType = "force"
58+
FeatureRuleTypeRollout FeatureRuleType = "rollout"
59+
FeatureRuleTypeExperiment FeatureRuleType = "experiment"
60+
)
61+
62+
type FeatureRule struct {
63+
Type FeatureRuleType `json:"type,omitempty"`
64+
Description string `json:"description,omitempty"`
65+
Condition string `json:"condition,omitempty"`
66+
Enabled bool `json:"enabled,omitempty"`
67+
ScheduleRules []ScheduleRule `json:"scheduleRules,omitempty"`
68+
SavedGroups []SavedGroupTargeting `json:"savedGroups,omitempty"`
69+
Prerequisites []FeaturePrerequisite `json:"prerequisites,omitempty"`
70+
Value string `json:"value,omitempty"`
71+
Coverage string `json:"coverage,omitempty"`
72+
HashAttribute string `json:"hashAttribute,omitempty"`
73+
TrackingKey string `json:"trackingKey,omitempty"`
74+
FallbackAttribute *string `json:"fallbackAttribute,omitempty"`
75+
DisableStickyBucketing *bool `json:"disableStickyBucketing,omitempty"`
76+
BucketVersion *int64 `json:"bucketVersion,omitempty"`
77+
MinBucketVersion *int64 `json:"minBucketVersion,omitempty"`
78+
Namespace *NamespaceValue `json:"namespace,omitempty"`
79+
Values []ExperimentValue `json:"values,omitempty"`
80+
}
81+
82+
type FeaturePrerequisite struct {
83+
ID string `json:"id,omitempty"`
84+
Condition string `json:"condition,omitempty"`
85+
}
86+
87+
type ScheduleRule struct {
88+
Timestamp string `json:"timestamp,omitempty"`
89+
Enabled bool `json:"enabled,omitempty"`
90+
}
91+
92+
type SavedGroupTargeting struct {
93+
Match SavedGroupTargetingMatch `json:"match,omitempty"`
94+
IDs []string `json:"ids,omitempty"`
95+
}
96+
97+
type ExperimentValue struct {
98+
Value string `json:"value,omitempty"`
99+
Weight int64 `json:"weight,omitempty"`
100+
Name *string `json:"name,omitempty"`
101+
}
102+
103+
type NamespaceValue struct {
104+
Enabled bool `json:"enabled,omitempty"`
105+
Name string `json:"name,omitempty"`
106+
Range []int64 `json:"range,omitempty"`
107+
}
108+
43109
// GetID returns the feature ID which is the resource name if not overwritten by spec.ID
44110
func (f *GrowthbookFeature) GetID() string {
45111
if f.Spec.ID == "" {
@@ -51,8 +117,9 @@ func (f *GrowthbookFeature) GetID() string {
51117

52118
// Environment defines a grothbook environment
53119
type Environment struct {
54-
Name string `json:"name,omitempty"`
55-
Enabled bool `json:"enabled,omitempty"`
120+
Name string `json:"name,omitempty"`
121+
Enabled bool `json:"enabled,omitempty"`
122+
Rules []FeatureRule `json:"rules,omitempty"`
56123
}
57124

58125
// +kubebuilder:object:root=true

api/v1beta1/zz_generated.deepcopy.go

Lines changed: 164 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)