-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This completely reimplements the informer system. It now avoids the issues using the cache informer watcher which occasionally ommits errors - to my best reckoning it is due to partial object updates not deserialising properly. Signed-off-by: Alex Jones <alexsimonjones@gmail.com>
- Loading branch information
1 parent
84e32b7
commit 837b0c6
Showing
5 changed files
with
251 additions
and
261 deletions.
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
149 changes: 0 additions & 149 deletions
149
pkg/sync/kubernetes/featureflagconfiguration/clientset.go
This file was deleted.
Oops, something went wrong.
77 changes: 0 additions & 77 deletions
77
pkg/sync/kubernetes/featureflagconfiguration/featureflagconfiguration.go
This file was deleted.
Oops, something went wrong.
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,113 @@ | ||
package kubernetes | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
|
||
"github.com/open-feature/open-feature-operator/apis/core/v1alpha1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
"k8s.io/apimachinery/pkg/runtime/serializer" | ||
"k8s.io/apimachinery/pkg/watch" | ||
"k8s.io/client-go/kubernetes/scheme" | ||
"k8s.io/client-go/rest" | ||
) | ||
|
||
type ClientInterface interface { | ||
List(opts metav1.ListOptions) (*v1alpha1.FeatureFlagConfigurationList, error) | ||
Get(name string, options metav1.GetOptions) (*v1alpha1.FeatureFlagConfiguration, error) | ||
Create(*v1alpha1.FeatureFlagConfiguration) (*v1alpha1.FeatureFlagConfiguration, error) | ||
Watch(opts metav1.ListOptions) (watch.Interface, error) | ||
} | ||
|
||
type FeatureFlagConfigurationInterface interface { | ||
FeatureFlagConfigurations(namespace string) ClientInterface | ||
} | ||
|
||
type FeatureFlagConfigurationImpl struct { | ||
restClient rest.Interface | ||
ns string | ||
} | ||
|
||
type FeatureFlagConfigurationRestClient struct { | ||
restClient rest.Interface | ||
} | ||
|
||
func (c *FeatureFlagConfigurationImpl) List(opts metav1.ListOptions) (*v1alpha1.FeatureFlagConfigurationList, error) { | ||
result := v1alpha1.FeatureFlagConfigurationList{} | ||
err := c.restClient. | ||
Get(). | ||
Resource(featureFlagConfigurationName). | ||
Do(context.Background()). | ||
Into(&result) | ||
|
||
return &result, err | ||
} | ||
|
||
func (c *FeatureFlagConfigurationImpl) Get(name string, | ||
opts metav1.GetOptions, | ||
) (*v1alpha1.FeatureFlagConfiguration, error) { | ||
result := v1alpha1.FeatureFlagConfiguration{} | ||
err := c.restClient. | ||
Get(). | ||
Namespace(c.ns). | ||
Resource(featureFlagConfigurationName). | ||
Name(name). | ||
VersionedParams(&opts, scheme.ParameterCodec). | ||
Do(context.Background()). | ||
Into(&result) | ||
|
||
return &result, err | ||
} | ||
|
||
func (c *FeatureFlagConfigurationImpl) Create(project *v1alpha1.FeatureFlagConfiguration) (*v1alpha1. | ||
FeatureFlagConfiguration, error, | ||
) { | ||
result := v1alpha1.FeatureFlagConfiguration{} | ||
err := c.restClient. | ||
Post(). | ||
Namespace(c.ns). | ||
Resource(featureFlagConfigurationName). | ||
Body(project). | ||
Do(context.Background()). | ||
Into(&result) | ||
|
||
return &result, err | ||
} | ||
|
||
func (c *FeatureFlagConfigurationImpl) Watch(opts metav1.ListOptions) (watch.Interface, error) { | ||
opts.Watch = true | ||
return c.restClient. | ||
Get(). | ||
Namespace(c.ns). | ||
Resource(featureFlagConfigurationName). | ||
VersionedParams(&opts, scheme.ParameterCodec). | ||
Watch(context.Background()) | ||
} | ||
|
||
func NewForConfig(config *rest.Config) (*FeatureFlagConfigurationRestClient, error) { | ||
if config == nil { | ||
return nil, errors.New("rest config is nil") | ||
} | ||
config.ContentConfig.GroupVersion = &schema. | ||
GroupVersion{ | ||
Group: v1alpha1.GroupVersion.Group, | ||
Version: v1alpha1.GroupVersion.Version, | ||
} | ||
config.APIPath = "/apis" | ||
config.UserAgent = rest.DefaultKubernetesUserAgent() | ||
config.NegotiatedSerializer = serializer.NewCodecFactory(scheme.Scheme) | ||
client, err := rest.RESTClientFor(config) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &FeatureFlagConfigurationRestClient{restClient: client}, nil | ||
} | ||
|
||
func (c *FeatureFlagConfigurationRestClient) FeatureFlagConfigurations(namespace string) ClientInterface { | ||
return &FeatureFlagConfigurationImpl{ | ||
restClient: c.restClient, | ||
ns: namespace, | ||
} | ||
} |
Oops, something went wrong.