-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Skye Gill <[email protected]>
- Loading branch information
Showing
9 changed files
with
343 additions
and
334 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
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
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,30 @@ | ||
package controllers | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/go-logr/logr" | ||
"github.com/open-feature/open-feature-operator/apis/core/v1alpha1" | ||
"github.com/open-feature/open-feature-operator/pkg/utils" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
) | ||
|
||
func CreateConfigMap( | ||
ctx context.Context, log logr.Logger, c client.Client, namespace string, name string, ownerReferences []metav1.OwnerReference, | ||
) error { | ||
log.V(1).Info(fmt.Sprintf("Creating configmap %s", name)) | ||
references := []metav1.OwnerReference{ | ||
ownerReferences[0], | ||
} | ||
references[0].Controller = utils.FalseVal() | ||
ff := FeatureFlag(ctx, c, namespace, name) | ||
if ff.Name == "" { | ||
return fmt.Errorf("feature flag configuration %s/%s not found", namespace, name) | ||
} | ||
references = append(references, v1alpha1.GetFfReference(&ff)) | ||
|
||
cm := v1alpha1.GenerateFfConfigMap(name, namespace, references, ff.Spec) | ||
|
||
return c.Create(ctx, &cm) | ||
} |
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,16 @@ | ||
package controllers | ||
|
||
import ( | ||
"context" | ||
"github.com/open-feature/open-feature-operator/apis/core/v1alpha1" | ||
"k8s.io/apimachinery/pkg/api/errors" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
) | ||
|
||
func FeatureFlag(ctx context.Context, c client.Client, namespace string, name string) v1alpha1.FeatureFlagConfiguration { | ||
ffConfig := v1alpha1.FeatureFlagConfiguration{} | ||
if err := c.Get(ctx, client.ObjectKey{Name: name, Namespace: namespace}, &ffConfig); errors.IsNotFound(err) { | ||
return v1alpha1.FeatureFlagConfiguration{} | ||
} | ||
return ffConfig | ||
} |
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,17 @@ | ||
package controllers | ||
|
||
import ( | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
// SharedOwnership returns true if any of the owner references match in the given slices | ||
func SharedOwnership(ownerReferences1, ownerReferences2 []metav1.OwnerReference) bool { | ||
for _, owner1 := range ownerReferences1 { | ||
for _, owner2 := range ownerReferences2 { | ||
if owner1.UID == owner2.UID { | ||
return true | ||
} | ||
} | ||
} | ||
return false | ||
} |
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,11 @@ | ||
package controllers | ||
|
||
import "strings" | ||
|
||
func ParseAnnotation(s string, defaultNs string) (string, string) { | ||
ss := strings.Split(s, "/") | ||
if len(ss) == 2 { | ||
return ss[0], ss[1] | ||
} | ||
return defaultNs, s | ||
} |
Oops, something went wrong.