Skip to content

Commit

Permalink
Update Ingress and Hostname (devfile#80)
Browse files Browse the repository at this point in the history
* update ingress hostname

Signed-off-by: Jordan Dubrick <jdubrick@redhat.com>

* update known issues

Signed-off-by: Jordan Dubrick <dubrickjordan@gmail.com>

---------

Signed-off-by: Jordan Dubrick <jdubrick@redhat.com>
Signed-off-by: Jordan Dubrick <dubrickjordan@gmail.com>
  • Loading branch information
Jdubrick committed Mar 6, 2024
1 parent 29aef03 commit 24724a1
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 1 deletion.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,8 @@ make run ENABLE_WEBHOOKS=false
## Contributing

Please see our [contributing.md](./CONTRIBUTING.md).

## Known Issues
- [`make test-integration` times out when running in Minikube](https://github.com/devfile/api/issues/1313)
- [Headless mode field does not update devfile registry state during reconcile](https://github.com/devfile/api/issues/1258)
- [`make bundle` removes `alm-examples` for `DevfileRegistriesList` and `ClusterDevfileRegistriesList` CRDs due to bug with Kustomize](https://github.com/kubernetes-sigs/kustomize/issues/5042)
8 changes: 7 additions & 1 deletion pkg/registry/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package registry

import (
"fmt"

registryv1alpha1 "github.com/devfile/registry-operator/api/v1alpha1"
networkingv1 "k8s.io/api/networking/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -70,5 +72,9 @@ func GenerateIngress(cr *registryv1alpha1.DevfileRegistry, host string, scheme *
}

func GetDevfileRegistryIngress(cr *registryv1alpha1.DevfileRegistry) string {
return cr.Name + "." + cr.Spec.K8s.IngressDomain
return GetHostname(cr) + "." + cr.Spec.K8s.IngressDomain
}

func GetHostname(cr *registryv1alpha1.DevfileRegistry) string {
return fmt.Sprintf("%s-%s", cr.Name, cr.Namespace)
}
85 changes: 85 additions & 0 deletions pkg/registry/ingress_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
//
//
// Copyright Red Hat
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package registry

import (
"testing"

registryv1alpha1 "github.com/devfile/registry-operator/api/v1alpha1"
)

func TestGetDevfileRegistryIngress(t *testing.T) {

tests := []struct {
name string
cr registryv1alpha1.DevfileRegistry
want string
}{
{
name: "Case 1: Correct Conjunction",
cr: registryv1alpha1.DevfileRegistry{
Spec: registryv1alpha1.DevfileRegistrySpec{
K8s: registryv1alpha1.DevfileRegistrySpecK8sOnly{
IngressDomain: "my-domain",
},
}},
want: "test-name-test-namespace.my-domain",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tt.cr.Name = "test-name"
tt.cr.Namespace = "test-namespace"
ingress := GetDevfileRegistryIngress(&tt.cr)
if ingress != tt.want {
t.Errorf("expected: %v got: %v", tt.want, ingress)
}
})
}

}

func TestGetHostname(t *testing.T) {

tests := []struct {
name string
cr registryv1alpha1.DevfileRegistry
want string
}{
{
name: "Case 1: Correct Hostname",
cr: registryv1alpha1.DevfileRegistry{
Spec: registryv1alpha1.DevfileRegistrySpec{
K8s: registryv1alpha1.DevfileRegistrySpecK8sOnly{
IngressDomain: "my-domain",
},
}},
want: "test-name-test-namespace",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tt.cr.Name = "test-name"
tt.cr.Namespace = "test-namespace"
hostname := GetHostname(&tt.cr)
if hostname != tt.want {
t.Errorf("expected: %v got: %v", tt.want, hostname)
}
})
}

}

0 comments on commit 24724a1

Please sign in to comment.