Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Introduce v1beta1 API version #535

Merged
merged 5 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,20 @@ resources:
kind: FlagSourceConfiguration
path: github.com/open-feature/open-feature-operator/apis/core/v1alpha3
version: v1alpha3
- api:
crdVersion: v1
namespaced: true
domain: openfeature.dev
group: core
kind: FeatureFlag
toddbaert marked this conversation as resolved.
Show resolved Hide resolved
path: github.com/open-feature/open-feature-operator/apis/core/v1beta1
version: v1beta1
- api:
crdVersion: v1
namespaced: true
domain: openfeature.dev
group: core
kind: FeatureFlagSource
path: github.com/open-feature/open-feature-operator/apis/core/v1beta1
version: v1beta1
version: "3"
11 changes: 11 additions & 0 deletions apis/core/v1beta1/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package v1beta1

type SyncProviderType string

const (
SyncProviderKubernetes SyncProviderType = "kubernetes"
SyncProviderFilepath SyncProviderType = "file"
odubajDT marked this conversation as resolved.
Show resolved Hide resolved
SyncProviderHttp SyncProviderType = "http"
SyncProviderGrpc SyncProviderType = "grpc"
SyncProviderFlagdProxy SyncProviderType = "flagd-proxy"
)
85 changes: 85 additions & 0 deletions apis/core/v1beta1/featureflag_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
Kavindu-Dodan marked this conversation as resolved.
Show resolved Hide resolved
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"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// FeatureFlagSpec defines the desired state of FeatureFlag
type FeatureFlagSpec struct {
// FlagSpec is the structured representation of the feature flag specification
FlagSpec FlagSpec `json:"flagSpec,omitempty"`
}

type FlagSpec struct {
Flags map[string]Flag `json:"flags"`
// +optional
// +kubebuilder:validation:Schemaless
// +kubebuilder:pruning:PreserveUnknownFields
// +kubebuilder:validation:Type=object
Evaluators json.RawMessage `json:"$evaluators,omitempty"`
}

type Flag 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"`
}

// FeatureFlagStatus defines the observed state of FeatureFlag
type FeatureFlagStatus struct {
}

// TODO change to `ff` when v1alpha* is removed
odubajDT marked this conversation as resolved.
Show resolved Hide resolved
//+kubebuilder:resource:shortName="ffc"
//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

// FeatureFlag is the Schema for the featureflags API
type FeatureFlag struct {
metav1.TypeMeta `json:",inline"`
odubajDT marked this conversation as resolved.
Show resolved Hide resolved
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec FeatureFlagSpec `json:"spec,omitempty"`
Status FeatureFlagStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

// FeatureFlagList contains a list of FeatureFlag
type FeatureFlagList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []FeatureFlag `json:"items"`
}

func init() {
SchemeBuilder.Register(&FeatureFlag{}, &FeatureFlagList{})
}
174 changes: 174 additions & 0 deletions apis/core/v1beta1/featureflagsource_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
/*
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"
)

// FeatureFlagSourceSpec defines the desired state of FeatureFlagSource
type FeatureFlagSourceSpec 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 SyncProviderType `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"`
}

// FeatureFlagSourceStatus defines the observed state of FeatureFlagSource
type FeatureFlagSourceStatus struct {
}

//+kubebuilder:resource:shortName="ffs"
//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

// FeatureFlagSource is the Schema for the FeatureFlagSources API
type FeatureFlagSource struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec FeatureFlagSourceSpec `json:"spec,omitempty"`
Status FeatureFlagSourceStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

// FeatureFlagSourceList contains a list of FeatureFlagSource
type FeatureFlagSourceList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []FeatureFlagSource `json:"items"`
}

func init() {
SchemeBuilder.Register(&FeatureFlagSource{}, &FeatureFlagSourceList{})
}

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
}
24 changes: 24 additions & 0 deletions apis/core/v1beta1/featureflagsource_types_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package v1beta1

import (
"testing"

"github.com/stretchr/testify/require"
)

func Test_FeatureFlagSource_SyncProvider(t *testing.T) {
k := SyncProviderKubernetes
f := SyncProviderFilepath
h := SyncProviderHttp
g := SyncProviderGrpc

require.True(t, k.IsKubernetes())
require.True(t, f.IsFilepath())
require.True(t, h.IsHttp())
require.True(t, g.IsGrpc())

require.False(t, f.IsKubernetes())
require.False(t, h.IsFilepath())
require.False(t, k.IsGrpc())
require.False(t, g.IsHttp())
}
36 changes: 36 additions & 0 deletions apis/core/v1beta1/groupversion_info.go
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
)
Loading
Loading