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.

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