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: fixing informer issues #191

Merged
merged 13 commits into from
Oct 13, 2022
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.

111 changes: 111 additions & 0 deletions pkg/sync/kubernetes/ffclientset.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
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 Interface interface {
AlexsJones marked this conversation as resolved.
Show resolved Hide resolved
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 FeatureFlagConfigurationImpl struct {
restClient rest.Interface
ns string
}

type FeatureFlagConfigurationInterface interface {
FeatureFlagConfigurations(namespace string) Interface
AlexsJones marked this conversation as resolved.
Show resolved Hide resolved
}

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) Interface {
return &FeatureFlagConfigurationImpl{
restClient: c.restClient,
ns: namespace,
}
}
Loading