|
| 1 | +/* |
| 2 | +Copyright 2022. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package v1alpha2 |
| 18 | + |
| 19 | +import ( |
| 20 | + "encoding/json" |
| 21 | + "github.com/open-feature/open-feature-operator/pkg/utils" |
| 22 | + corev1 "k8s.io/api/core/v1" |
| 23 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 24 | +) |
| 25 | + |
| 26 | +// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! |
| 27 | +// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. |
| 28 | + |
| 29 | +// FeatureFlagConfigurationSpec defines the desired state of FeatureFlagConfiguration |
| 30 | +type FeatureFlagConfigurationSpec struct { |
| 31 | + // INSERT ADDITIONAL SPEC FIELDS - desired state of cluster |
| 32 | + // Important: Run "make" to regenerate code after modifying this file |
| 33 | + // +optional |
| 34 | + // +nullable |
| 35 | + ServiceProvider *FeatureFlagServiceProvider `json:"serviceProvider"` |
| 36 | + // +optional |
| 37 | + // +nullable |
| 38 | + SyncProvider *FeatureFlagSyncProvider `json:"syncProvider"` |
| 39 | + // +optional |
| 40 | + // +nullable |
| 41 | + FlagDSpec *FlagDSpec `json:"flagDSpec"` |
| 42 | + // FeatureFlagSpec is the structured representation of the feature flag specification |
| 43 | + FeatureFlagSpec FeatureFlagSpec `json:"featureFlagSpec,omitempty"` |
| 44 | +} |
| 45 | + |
| 46 | +type FlagDSpec struct { |
| 47 | + // +optional |
| 48 | + Envs []corev1.EnvVar `json:"envs"` |
| 49 | +} |
| 50 | + |
| 51 | +type FeatureFlagSpec struct { |
| 52 | + Flags map[string]FlagSpec `json:"flags"` |
| 53 | + // +optional |
| 54 | + // +kubebuilder:validation:Schemaless |
| 55 | + // +kubebuilder:pruning:PreserveUnknownFields |
| 56 | + // +kubebuilder:validation:Type=object |
| 57 | + Evaluators json.RawMessage `json:"$evaluators,omitempty"` |
| 58 | +} |
| 59 | + |
| 60 | +type FlagSpec struct { |
| 61 | + // +kubebuilder:validation:Enum=ENABLED;DISABLED |
| 62 | + State string `json:"state"` |
| 63 | + // +kubebuilder:validation:Schemaless |
| 64 | + // +kubebuilder:pruning:PreserveUnknownFields |
| 65 | + // +kubebuilder:validation:Type=object |
| 66 | + Variants json.RawMessage `json:"variants"` |
| 67 | + DefaultVariant string `json:"defaultVariant"` |
| 68 | + // +optional |
| 69 | + // +kubebuilder:validation:Schemaless |
| 70 | + // +kubebuilder:pruning:PreserveUnknownFields |
| 71 | + // +kubebuilder:validation:Type=object |
| 72 | + // Targeting is the json targeting rule |
| 73 | + Targeting json.RawMessage `json:"targeting,omitempty"` |
| 74 | +} |
| 75 | + |
| 76 | +type FeatureFlagSyncProvider struct { |
| 77 | + Name string `json:"name"` |
| 78 | +} |
| 79 | + |
| 80 | +func (ffsp FeatureFlagSyncProvider) IsKubernetes() bool { |
| 81 | + return ffsp.Name == "kubernetes" |
| 82 | +} |
| 83 | + |
| 84 | +type FeatureFlagServiceProvider struct { |
| 85 | + // +kubebuilder:validation:Enum=flagd |
| 86 | + Name string `json:"name"` |
| 87 | + // +optional |
| 88 | + // +nullable |
| 89 | + Credentials *corev1.ObjectReference `json:"credentials"` |
| 90 | +} |
| 91 | + |
| 92 | +// FeatureFlagConfigurationStatus defines the observed state of FeatureFlagConfiguration |
| 93 | +type FeatureFlagConfigurationStatus struct { |
| 94 | + // INSERT ADDITIONAL STATUS FIELD - define observed state of cluster |
| 95 | + // Important: Run "make" to regenerate code after modifying this file |
| 96 | +} |
| 97 | + |
| 98 | +//+kubebuilder:object:root=true |
| 99 | +//+kubebuilder:subresource:status |
| 100 | + |
| 101 | +// FeatureFlagConfiguration is the Schema for the featureflagconfigurations API |
| 102 | +type FeatureFlagConfiguration struct { |
| 103 | + metav1.TypeMeta `json:",inline"` |
| 104 | + metav1.ObjectMeta `json:"metadata,omitempty"` |
| 105 | + |
| 106 | + Spec FeatureFlagConfigurationSpec `json:"spec,omitempty"` |
| 107 | + Status FeatureFlagConfigurationStatus `json:"status,omitempty"` |
| 108 | +} |
| 109 | + |
| 110 | +//+kubebuilder:object:root=true |
| 111 | + |
| 112 | +// FeatureFlagConfigurationList contains a list of FeatureFlagConfiguration |
| 113 | +type FeatureFlagConfigurationList struct { |
| 114 | + metav1.TypeMeta `json:",inline"` |
| 115 | + metav1.ListMeta `json:"metadata,omitempty"` |
| 116 | + Items []FeatureFlagConfiguration `json:"items"` |
| 117 | +} |
| 118 | + |
| 119 | +func init() { |
| 120 | + SchemeBuilder.Register(&FeatureFlagConfiguration{}, &FeatureFlagConfigurationList{}) |
| 121 | +} |
| 122 | + |
| 123 | +func GetFfReference(ff *FeatureFlagConfiguration) metav1.OwnerReference { |
| 124 | + return metav1.OwnerReference{ |
| 125 | + APIVersion: ff.APIVersion, |
| 126 | + Kind: ff.Kind, |
| 127 | + Name: ff.Name, |
| 128 | + UID: ff.UID, |
| 129 | + Controller: utils.TrueVal(), |
| 130 | + } |
| 131 | +} |
0 commit comments