Skip to content

Commit

Permalink
Enable Deployment.ClusterName
Browse files Browse the repository at this point in the history
  • Loading branch information
hjkatz committed Dec 19, 2024
1 parent 62264f9 commit 913d6cb
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 56 deletions.
4 changes: 2 additions & 2 deletions api/ngrok/v1alpha1/kubernetesoperator_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ type ngrokAPICommon struct {
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

type KubernetesOperatorDeployment struct {
// Cluster is the name of the k8s cluster in which the operator is deployed
Cluster string `json:"cluster,omitempty"`
// ClusterName is the name of the k8s cluster in which the operator is deployed
ClusterName string `json:"clusterName,omitempty"`
// Name is the name of the k8s deployment for the operator
Name string `json:"name,omitempty"`
// The namespace in which the operator is deployed
Expand Down
17 changes: 7 additions & 10 deletions cmd/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,9 @@ func runNormalMode(ctx context.Context, opts managerOpts, k8sClient client.Clien
return fmt.Errorf("Unable to load ngrokClientSet: %w", err)
}

// TODO(hkatz) for now we are hiding the k8sop API regstration behind the bindings feature flag
if opts.enableFeatureBindings {
// register the k8sop in the ngrok API
if err := createKubernetesOperator(ctx, k8sClient, opts); err != nil {
return fmt.Errorf("unable to create KubernetesOperator: %w", err)
}
// register the k8sop in the ngrok API
if err := createKubernetesOperator(ctx, k8sClient, opts); err != nil {
return fmt.Errorf("unable to create KubernetesOperator: %w", err)
}

// k8sResourceDriver is the driver that will be used to interact with the k8s resources for all controllers
Expand Down Expand Up @@ -659,10 +656,10 @@ func createKubernetesOperator(ctx context.Context, client client.Client, opts ma
_, err := controllerutil.CreateOrUpdate(ctx, client, k8sOperator, func() error {
k8sOperator.Spec = ngrokv1alpha1.KubernetesOperatorSpec{
Deployment: &ngrokv1alpha1.KubernetesOperatorDeployment{
Cluster: opts.clusterName,
Name: opts.releaseName,
Namespace: opts.namespace,
Version: version.GetVersion(),
ClusterName: opts.clusterName,
Name: opts.releaseName,
Namespace: opts.namespace,
Version: version.GetVersion(),
},
Region: opts.region,
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 7 additions & 9 deletions internal/controller/ngrok/kubernetesoperator_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,10 @@ func (r *KubernetesOperatorReconciler) create(ctx context.Context, ko *ngrokv1al
EnabledFeatures: calculateFeaturesEnabled(ko),
Region: ko.Spec.Region,
Deployment: ngrok.KubernetesOperatorDeployment{
// TODO(hkatz) clusterName
// Cluster: ko.Spec.Deployment.Cluster,
Name: ko.Spec.Deployment.Name,
Namespace: ko.Spec.Deployment.Namespace,
Version: ko.Spec.Deployment.Version,
ClusterName: ko.Spec.Deployment.ClusterName,
Name: ko.Spec.Deployment.Name,
Namespace: ko.Spec.Deployment.Namespace,
Version: ko.Spec.Deployment.Version,
},
}

Expand Down Expand Up @@ -326,10 +325,9 @@ func ngrokK8sopMatchesKubernetesOperator(k8sop *ngrok.KubernetesOperator, ko *ng
return false
}

// TODO(hkatz) clusterName
// if item.Deployment.Cluster != ko.Spec.Deployment.Cluster {
// continue
// }
if k8sop.Deployment.ClusterName != ko.Spec.Deployment.ClusterName {
return false
}

if k8sop.Deployment.Name != ko.Spec.Deployment.Name {
return false
Expand Down
124 changes: 92 additions & 32 deletions internal/controller/ngrok/kubernetesoperator_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,39 @@ func Test_ngrokK8sopMatchesKubernetesOperator(t *testing.T) {
ngrokK8sop: &ngrok.KubernetesOperator{
EnabledFeatures: []string{"Ingress"}, // API returns title cased features
Deployment: ngrok.KubernetesOperatorDeployment{
Name: "example",
Namespace: "ngrok-operator",
ClusterName: "my-cluster",
Name: "example",
Namespace: "ngrok-operator",
},
},
koK8sop: &ngrokv1alpha1.KubernetesOperator{
Spec: ngrokv1alpha1.KubernetesOperatorSpec{
Deployment: &ngrokv1alpha1.KubernetesOperatorDeployment{
Name: "example",
Namespace: "ngrok-operator",
ClusterName: "my-cluster",
Name: "example",
Namespace: "ngrok-operator",
},
EnabledFeatures: []string{ngrokv1alpha1.KubernetesOperatorFeatureIngress},
},
},
},
{
name: "different clustername",
want: false,
ngrokK8sop: &ngrok.KubernetesOperator{
EnabledFeatures: []string{"Ingress"}, // API returns title cased features
Deployment: ngrok.KubernetesOperatorDeployment{
ClusterName: "my-cluster",
Name: "example",
Namespace: "ngrok-operator",
},
},
koK8sop: &ngrokv1alpha1.KubernetesOperator{
Spec: ngrokv1alpha1.KubernetesOperatorSpec{
Deployment: &ngrokv1alpha1.KubernetesOperatorDeployment{
ClusterName: "different-cluster",
Name: "example",
Namespace: "ngrok-operator",
},
EnabledFeatures: []string{ngrokv1alpha1.KubernetesOperatorFeatureIngress},
},
Expand All @@ -49,15 +73,17 @@ func Test_ngrokK8sopMatchesKubernetesOperator(t *testing.T) {
ngrokK8sop: &ngrok.KubernetesOperator{
EnabledFeatures: []string{"Ingress"}, // API returns title cased features
Deployment: ngrok.KubernetesOperatorDeployment{
Name: "example",
Namespace: "ngrok-operator",
ClusterName: "my-cluster",
Name: "example",
Namespace: "ngrok-operator",
},
},
koK8sop: &ngrokv1alpha1.KubernetesOperator{
Spec: ngrokv1alpha1.KubernetesOperatorSpec{
Deployment: &ngrokv1alpha1.KubernetesOperatorDeployment{
Name: "example",
Namespace: "different-namespace",
ClusterName: "my-cluster",
Name: "example",
Namespace: "different-namespace",
},
EnabledFeatures: []string{ngrokv1alpha1.KubernetesOperatorFeatureIngress},
},
Expand All @@ -69,15 +95,39 @@ func Test_ngrokK8sopMatchesKubernetesOperator(t *testing.T) {
ngrokK8sop: &ngrok.KubernetesOperator{
EnabledFeatures: []string{"Ingress"}, // API returns title cased features
Deployment: ngrok.KubernetesOperatorDeployment{
Name: "example",
Namespace: "ngrok-operator",
ClusterName: "my-cluster",
Name: "example",
Namespace: "ngrok-operator",
},
},
koK8sop: &ngrokv1alpha1.KubernetesOperator{
Spec: ngrokv1alpha1.KubernetesOperatorSpec{
Deployment: &ngrokv1alpha1.KubernetesOperatorDeployment{
ClusterName: "my-cluster",
Name: "different-name",
Namespace: "ngrok-operator",
},
EnabledFeatures: []string{ngrokv1alpha1.KubernetesOperatorFeatureIngress},
},
},
},
{
name: "same name, different clustername",
want: false,
ngrokK8sop: &ngrok.KubernetesOperator{
EnabledFeatures: []string{"Ingress"}, // API returns title cased features
Deployment: ngrok.KubernetesOperatorDeployment{
ClusterName: "my-cluster",
Name: "example",
Namespace: "ngrok-operator",
},
},
koK8sop: &ngrokv1alpha1.KubernetesOperator{
Spec: ngrokv1alpha1.KubernetesOperatorSpec{
Deployment: &ngrokv1alpha1.KubernetesOperatorDeployment{
Name: "different-name",
Namespace: "ngrok-operator",
ClusterName: "different-cluster",
Name: "example",
Namespace: "ngrok-operator",
},
EnabledFeatures: []string{ngrokv1alpha1.KubernetesOperatorFeatureIngress},
},
Expand All @@ -89,8 +139,9 @@ func Test_ngrokK8sopMatchesKubernetesOperator(t *testing.T) {
ngrokK8sop: &ngrok.KubernetesOperator{
EnabledFeatures: []string{"Ingress", "Bindings"}, // API returns title cased features
Deployment: ngrok.KubernetesOperatorDeployment{
Name: "example",
Namespace: "ngrok-operator",
ClusterName: "my-cluster",
Name: "example",
Namespace: "ngrok-operator",
},
Binding: &ngrok.KubernetesOperatorBinding{
Name: "example",
Expand All @@ -99,8 +150,9 @@ func Test_ngrokK8sopMatchesKubernetesOperator(t *testing.T) {
koK8sop: &ngrokv1alpha1.KubernetesOperator{
Spec: ngrokv1alpha1.KubernetesOperatorSpec{
Deployment: &ngrokv1alpha1.KubernetesOperatorDeployment{
Name: "example",
Namespace: "ngrok-operator",
ClusterName: "my-cluster",
Name: "example",
Namespace: "ngrok-operator",
},
EnabledFeatures: []string{ngrokv1alpha1.KubernetesOperatorFeatureIngress, ngrokv1alpha1.KubernetesOperatorFeatureBindings},
Binding: &ngrokv1alpha1.KubernetesOperatorBinding{
Expand All @@ -115,8 +167,9 @@ func Test_ngrokK8sopMatchesKubernetesOperator(t *testing.T) {
ngrokK8sop: &ngrok.KubernetesOperator{
EnabledFeatures: []string{"Ingress", "Bindings"}, // API returns title cased features
Deployment: ngrok.KubernetesOperatorDeployment{
Name: "example",
Namespace: "ngrok-operator",
ClusterName: "my-cluster",
Name: "example",
Namespace: "ngrok-operator",
},
Binding: &ngrok.KubernetesOperatorBinding{
Name: "example",
Expand All @@ -125,8 +178,9 @@ func Test_ngrokK8sopMatchesKubernetesOperator(t *testing.T) {
koK8sop: &ngrokv1alpha1.KubernetesOperator{
Spec: ngrokv1alpha1.KubernetesOperatorSpec{
Deployment: &ngrokv1alpha1.KubernetesOperatorDeployment{
Name: "example",
Namespace: "ngrok-operator",
ClusterName: "my-cluster",
Name: "example",
Namespace: "ngrok-operator",
},
EnabledFeatures: []string{ngrokv1alpha1.KubernetesOperatorFeatureIngress, ngrokv1alpha1.KubernetesOperatorFeatureBindings},
Binding: &ngrokv1alpha1.KubernetesOperatorBinding{
Expand All @@ -141,8 +195,9 @@ func Test_ngrokK8sopMatchesKubernetesOperator(t *testing.T) {
ngrokK8sop: &ngrok.KubernetesOperator{
EnabledFeatures: []string{"Ingress", "Bindings"}, // API returns title cased features
Deployment: ngrok.KubernetesOperatorDeployment{
Name: "example",
Namespace: "ngrok-operator",
ClusterName: "my-cluster",
Name: "example",
Namespace: "ngrok-operator",
},
Binding: &ngrok.KubernetesOperatorBinding{
Name: "example",
Expand All @@ -151,8 +206,9 @@ func Test_ngrokK8sopMatchesKubernetesOperator(t *testing.T) {
koK8sop: &ngrokv1alpha1.KubernetesOperator{
Spec: ngrokv1alpha1.KubernetesOperatorSpec{
Deployment: &ngrokv1alpha1.KubernetesOperatorDeployment{
Name: "example",
Namespace: "ngrok-operator",
ClusterName: "my-cluster",
Name: "example",
Namespace: "ngrok-operator",
},
EnabledFeatures: []string{ngrokv1alpha1.KubernetesOperatorFeatureIngress},
},
Expand All @@ -164,8 +220,9 @@ func Test_ngrokK8sopMatchesKubernetesOperator(t *testing.T) {
ngrokK8sop: &ngrok.KubernetesOperator{
EnabledFeatures: []string{"Ingress"}, // API returns title cased features
Deployment: ngrok.KubernetesOperatorDeployment{
Name: "example",
Namespace: "ngrok-operator",
ClusterName: "my-cluster",
Name: "example",
Namespace: "ngrok-operator",
},
Binding: &ngrok.KubernetesOperatorBinding{
Name: "example",
Expand All @@ -174,8 +231,9 @@ func Test_ngrokK8sopMatchesKubernetesOperator(t *testing.T) {
koK8sop: &ngrokv1alpha1.KubernetesOperator{
Spec: ngrokv1alpha1.KubernetesOperatorSpec{
Deployment: &ngrokv1alpha1.KubernetesOperatorDeployment{
Name: "example",
Namespace: "ngrok-operator",
ClusterName: "my-cluster",
Name: "example",
Namespace: "ngrok-operator",
},
EnabledFeatures: []string{ngrokv1alpha1.KubernetesOperatorFeatureIngress, ngrokv1alpha1.KubernetesOperatorFeatureBindings},
Binding: &ngrokv1alpha1.KubernetesOperatorBinding{
Expand All @@ -194,8 +252,9 @@ func Test_ngrokK8sopMatchesKubernetesOperator(t *testing.T) {
ngrokK8sop: &ngrok.KubernetesOperator{
EnabledFeatures: []string{"Ingress"}, // API returns title cased features
Deployment: ngrok.KubernetesOperatorDeployment{
Name: "example",
Namespace: "ngrok-operator",
ClusterName: "my-cluster",
Name: "example",
Namespace: "ngrok-operator",
},
Binding: &ngrok.KubernetesOperatorBinding{
Name: "example",
Expand All @@ -204,8 +263,9 @@ func Test_ngrokK8sopMatchesKubernetesOperator(t *testing.T) {
koK8sop: &ngrokv1alpha1.KubernetesOperator{
Spec: ngrokv1alpha1.KubernetesOperatorSpec{
Deployment: &ngrokv1alpha1.KubernetesOperatorDeployment{
Name: "example",
Namespace: "ngrok-operator",
ClusterName: "my-cluster",
Name: "example",
Namespace: "ngrok-operator",
},
EnabledFeatures: []string{ngrokv1alpha1.KubernetesOperatorFeatureIngress, ngrokv1alpha1.KubernetesOperatorFeatureBindings},
Binding: &ngrokv1alpha1.KubernetesOperatorBinding{
Expand Down

0 comments on commit 913d6cb

Please sign in to comment.