Skip to content

Commit

Permalink
feat: fixing informer issues (#191)
Browse files Browse the repository at this point in the history
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
AlexsJones authored Oct 13, 2022
1 parent 84e32b7 commit 837b0c6
Show file tree
Hide file tree
Showing 5 changed files with 251 additions and 261 deletions.
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ github.com/bufbuild/connect-go v0.5.0 h1:JFbWPWpasBqzM5h/awoRhAXmLERZQlQ5xTn42uf
github.com/bufbuild/connect-go v0.5.0/go.mod h1:ZEtBnQ7J/m7bvWOW+H8T/+hKQCzPVfhhhICuvtcnjlI=
github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE=
Expand Down
149 changes: 0 additions & 149 deletions pkg/sync/kubernetes/featureflagconfiguration/clientset.go

This file was deleted.

This file was deleted.

113 changes: 113 additions & 0 deletions pkg/sync/kubernetes/ffclientset.go
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,
}
}
Loading

0 comments on commit 837b0c6

Please sign in to comment.