-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: odubajDT <[email protected]>
- Loading branch information
Showing
14 changed files
with
1,332 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
/* | ||
Copyright 2022. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package v1beta1 | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
"github.com/open-feature/open-feature-operator/pkg/utils" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
// FeatureFlagConfigurationSpec defines the desired state of FeatureFlagConfiguration | ||
type FeatureFlagConfigurationSpec struct { | ||
// FeatureFlagSpec is the structured representation of the feature flag specification | ||
FeatureFlagSpec FeatureFlagSpec `json:"featureFlagSpec,omitempty"` | ||
// Resources defines flagd sidecar resources. Default to operator sidecar-cpu-* and sidecar-ram-* flags. | ||
// +optional | ||
Resources corev1.ResourceRequirements `json:"resources"` | ||
} | ||
|
||
type FlagDSpec struct { | ||
// +optional | ||
Envs []corev1.EnvVar `json:"envs"` | ||
} | ||
|
||
type FeatureFlagSpec struct { | ||
Flags map[string]FlagSpec `json:"flags"` | ||
// +optional | ||
// +kubebuilder:validation:Schemaless | ||
// +kubebuilder:pruning:PreserveUnknownFields | ||
// +kubebuilder:validation:Type=object | ||
Evaluators json.RawMessage `json:"$evaluators,omitempty"` | ||
} | ||
|
||
type FlagSpec struct { | ||
// +kubebuilder:validation:Enum=ENABLED;DISABLED | ||
State string `json:"state"` | ||
// +kubebuilder:validation:Schemaless | ||
// +kubebuilder:pruning:PreserveUnknownFields | ||
// +kubebuilder:validation:Type=object | ||
Variants json.RawMessage `json:"variants"` | ||
DefaultVariant string `json:"defaultVariant"` | ||
// +optional | ||
// +kubebuilder:validation:Schemaless | ||
// +kubebuilder:pruning:PreserveUnknownFields | ||
// +kubebuilder:validation:Type=object | ||
// Targeting is the json targeting rule | ||
Targeting json.RawMessage `json:"targeting,omitempty"` | ||
} | ||
|
||
type FeatureFlagSyncProvider struct { | ||
Name string `json:"name"` | ||
// +optional | ||
// +nullable | ||
HttpSyncConfiguration *HttpSyncConfiguration `json:"httpSyncConfiguration"` | ||
} | ||
|
||
// HttpSyncConfiguration defines the desired configuration for a http sync | ||
type HttpSyncConfiguration struct { | ||
// Target is the target url for flagd to poll | ||
Target string `json:"target"` | ||
// +optional | ||
BearerToken string `json:"bearerToken,omitempty"` | ||
} | ||
|
||
type FeatureFlagServiceProvider struct { | ||
// +kubebuilder:validation:Enum=flagd | ||
Name string `json:"name"` | ||
// +optional | ||
// +nullable | ||
Credentials *corev1.ObjectReference `json:"credentials"` | ||
} | ||
|
||
// FeatureFlagConfigurationStatus defines the observed state of FeatureFlagConfiguration | ||
type FeatureFlagConfigurationStatus struct { | ||
} | ||
|
||
//+kubebuilder:resource:shortName="ff" | ||
//+kubebuilder:object:root=true | ||
//+kubebuilder:subresource:status | ||
|
||
// FeatureFlagConfiguration is the Schema for the featureflagconfigurations API | ||
type FeatureFlagConfiguration struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ObjectMeta `json:"metadata,omitempty"` | ||
|
||
Spec FeatureFlagConfigurationSpec `json:"spec,omitempty"` | ||
Status FeatureFlagConfigurationStatus `json:"status,omitempty"` | ||
} | ||
|
||
//+kubebuilder:object:root=true | ||
|
||
// FeatureFlagConfigurationList contains a list of FeatureFlagConfiguration | ||
type FeatureFlagConfigurationList struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ListMeta `json:"metadata,omitempty"` | ||
Items []FeatureFlagConfiguration `json:"items"` | ||
} | ||
|
||
func init() { | ||
SchemeBuilder.Register(&FeatureFlagConfiguration{}, &FeatureFlagConfigurationList{}) | ||
} | ||
|
||
func (ff *FeatureFlagConfiguration) GetReference() metav1.OwnerReference { | ||
return metav1.OwnerReference{ | ||
APIVersion: ff.APIVersion, | ||
Kind: ff.Kind, | ||
Name: ff.Name, | ||
UID: ff.UID, | ||
Controller: utils.TrueVal(), | ||
} | ||
} | ||
|
||
func (p *FeatureFlagServiceProvider) IsSet() bool { | ||
return p != nil && p.Name != "" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,184 @@ | ||
/* | ||
Copyright 2022. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package v1beta1 | ||
|
||
import ( | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
const ( | ||
SyncProviderKubernetes SyncProviderType = "kubernetes" | ||
SyncProviderFilepath SyncProviderType = "filepath" | ||
SyncProviderHttp SyncProviderType = "http" | ||
SyncProviderGrpc SyncProviderType = "grpc" | ||
SyncProviderFlagdProxy SyncProviderType = "flagd-proxy" | ||
) | ||
|
||
type SyncProviderType string | ||
|
||
// FlagSourceConfigurationSpec defines the desired state of FlagSourceConfiguration | ||
type FlagSourceConfigurationSpec struct { | ||
// MetricsPort defines the port to serve metrics on, defaults to 8014 | ||
// +optional | ||
MetricsPort int32 `json:"metricsPort"` | ||
|
||
// Port defines the port to listen on, defaults to 8013 | ||
// +optional | ||
Port int32 `json:"port"` | ||
|
||
// SocketPath defines the unix socket path to listen on | ||
// +optional | ||
SocketPath string `json:"socketPath"` | ||
|
||
// Evaluator sets an evaluator, defaults to 'json' | ||
// +optional | ||
Evaluator string `json:"evaluator"` | ||
|
||
// Image allows for the sidecar image to be overridden, defaults to 'ghcr.io/open-feature/flagd' | ||
// +optional | ||
Image string `json:"image"` | ||
|
||
// Tag to be appended to the sidecar image, defaults to 'main' | ||
// +optional | ||
Tag string `json:"tag"` | ||
|
||
// SyncProviders define the syncProviders and associated configuration to be applied to the sidecar | ||
// +kubebuilder:validation:MinItems=1 | ||
Sources []Source `json:"sources"` | ||
|
||
// EnvVars define the env vars to be applied to the sidecar, any env vars in FeatureFlagConfiguration CRs | ||
// are added at the lowest index, all values will have the EnvVarPrefix applied, default FLAGD | ||
// +optional | ||
EnvVars []corev1.EnvVar `json:"envVars"` | ||
|
||
// SyncProviderArgs are string arguments passed to all sync providers, defined as key values separated by = | ||
// +optional | ||
SyncProviderArgs []string `json:"syncProviderArgs"` | ||
|
||
// DefaultSyncProvider defines the default sync provider | ||
// +optional | ||
DefaultSyncProvider string `json:"defaultSyncProvider"` | ||
|
||
// LogFormat allows for the sidecar log format to be overridden, defaults to 'json' | ||
// +optional | ||
LogFormat string `json:"logFormat"` | ||
|
||
// EnvVarPrefix defines the prefix to be applied to all environment variables applied to the sidecar, default FLAGD | ||
// +optional | ||
EnvVarPrefix string `json:"envVarPrefix"` | ||
|
||
// RolloutOnChange dictates whether annotated deployments will be restarted when configuration changes are | ||
// detected in this CR, defaults to false | ||
// +optional | ||
RolloutOnChange *bool `json:"rolloutOnChange"` | ||
|
||
// ProbesEnabled defines whether to enable liveness and readiness probes of flagd sidecar. Default true (enabled). | ||
// +optional | ||
ProbesEnabled *bool `json:"probesEnabled"` | ||
|
||
// DebugLogging defines whether to enable --debug flag of flagd sidecar. Default false (disabled). | ||
// +optional | ||
DebugLogging *bool `json:"debugLogging"` | ||
|
||
// OtelCollectorUri defines whether to enable --otel-collector-uri flag of flagd sidecar. Default false (disabled). | ||
// +optional | ||
OtelCollectorUri string `json:"otelCollectorUri"` | ||
|
||
// Resources defines flagd sidecar resources. Default to operator sidecar-cpu-* and sidecar-ram-* flags. | ||
// +optional | ||
Resources corev1.ResourceRequirements `json:"resources"` | ||
} | ||
|
||
type Source struct { | ||
// Source is a URI of the flag sources | ||
Source string `json:"source"` | ||
|
||
// Provider type - kubernetes, http(s), grpc(s) or filepath | ||
// +optional | ||
Provider SyncProviderType `json:"provider"` | ||
|
||
// HttpSyncBearerToken is a bearer token. Used by http(s) sync provider only | ||
// +optional | ||
HttpSyncBearerToken string `json:"httpSyncBearerToken"` | ||
|
||
// TLS - Enable/Disable secure TLS connectivity. Currently used only by GRPC sync | ||
// +optional | ||
TLS bool `json:"tls"` | ||
|
||
// CertPath is a path of a certificate to be used by grpc TLS connection | ||
// +optional | ||
CertPath string `json:"certPath"` | ||
|
||
// ProviderID is an identifier to be used in grpc provider | ||
// +optional | ||
ProviderID string `json:"providerID"` | ||
|
||
// Selector is a flag configuration selector used by grpc provider | ||
// +optional | ||
Selector string `json:"selector,omitempty"` | ||
} | ||
|
||
// FlagSourceConfigurationStatus defines the observed state of FlagSourceConfiguration | ||
type FlagSourceConfigurationStatus struct { | ||
} | ||
|
||
//+kubebuilder:resource:shortName="fsc" | ||
//+kubebuilder:object:root=true | ||
//+kubebuilder:subresource:status | ||
|
||
// FlagSourceConfiguration is the Schema for the FlagSourceConfigurations API | ||
type FlagSourceConfiguration struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ObjectMeta `json:"metadata,omitempty"` | ||
|
||
Spec FlagSourceConfigurationSpec `json:"spec,omitempty"` | ||
Status FlagSourceConfigurationStatus `json:"status,omitempty"` | ||
} | ||
|
||
//+kubebuilder:object:root=true | ||
|
||
// FlagSourceConfigurationList contains a list of FlagSourceConfiguration | ||
type FlagSourceConfigurationList struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ListMeta `json:"metadata,omitempty"` | ||
Items []FlagSourceConfiguration `json:"items"` | ||
} | ||
|
||
func init() { | ||
SchemeBuilder.Register(&FlagSourceConfiguration{}, &FlagSourceConfigurationList{}) | ||
} | ||
|
||
func (s SyncProviderType) IsKubernetes() bool { | ||
return s == SyncProviderKubernetes | ||
} | ||
|
||
func (s SyncProviderType) IsHttp() bool { | ||
return s == SyncProviderHttp | ||
} | ||
|
||
func (s SyncProviderType) IsFilepath() bool { | ||
return s == SyncProviderFilepath | ||
} | ||
|
||
func (s SyncProviderType) IsGrpc() bool { | ||
return s == SyncProviderGrpc | ||
} | ||
|
||
func (s SyncProviderType) IsFlagdProxy() bool { | ||
return s == SyncProviderFlagdProxy | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
Copyright 2022. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
// Package v1beta1 contains API Schema definitions for the core v1beta1 API group | ||
//+kubebuilder:object:generate=true | ||
//+groupName=core.openfeature.dev | ||
package v1beta1 | ||
|
||
import ( | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
"sigs.k8s.io/controller-runtime/pkg/scheme" | ||
) | ||
|
||
var ( | ||
// GroupVersion is group version used to register these objects | ||
GroupVersion = schema.GroupVersion{Group: "core.openfeature.dev", Version: "v1beta1"} | ||
|
||
// SchemeBuilder is used to add go types to the GroupVersionKind scheme | ||
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion} | ||
|
||
// AddToScheme adds the types in this group-version to the given scheme. | ||
AddToScheme = SchemeBuilder.AddToScheme | ||
) |
Oops, something went wrong.