Skip to content

Commit

Permalink
Merge pull request #5 from appuio/zone-spec
Browse files Browse the repository at this point in the history
Define Zone CRD spec
  • Loading branch information
ccremer authored Dec 9, 2021
2 parents b28546e + 77c3fa6 commit ad31988
Show file tree
Hide file tree
Showing 4 changed files with 222 additions and 3 deletions.
48 changes: 47 additions & 1 deletion api/v1/zone_types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package v1

import (
"fmt"
"net/url"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand All @@ -12,12 +15,44 @@ type Zone struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

// Data holds the cluster specific metadata.
Data ZoneData `json:"data,omitempty"`
}

// ZoneData holds all the Zone specific properties
type ZoneData struct {
// TODO: Fill out spec
// DisplayName is a human-friendly name for the Zone.
DisplayName string `json:"displayName,omitempty"`
// Features holds a key-value dict with keys being a feature name and values being a property of that feature.
// Some features may hold a version string as property.
Features Features `json:"features,omitempty"`
// URLs holds a key-value dict with keys being a name of the URL and the values publicly accessible links.
URLs URLMap `json:"urls,omitempty"`
// CNAME is the DNS record where custom application DNS hostnames shall be pointing to when exposing an application.
CNAME string `json:"cname,omitempty"`
// DefaultAppDomain is the base DNS record where OpenShift Routes without specific hostnames are exposed.
DefaultAppDomain string `json:"defaultAppDomain,omitempty"`
// GatewayIPs holds the outgoing IP addresses of the cluster.
GatewayIPs []string `json:"gatewayIPs,omitempty"`
// CloudProvider identifies the infrastructure provider which the Zone is running on.
CloudProvider CloudProvider `json:"cloudProvider,omitempty"`
}

// Features is a key-value dict with keys being a feature name and values being a property of that feature.
type Features map[string]string

// URLMap is a key-value dict with keys being a name of the URL and the values publicly accessible links.
type URLMap map[string]string

// CloudProvider identifies an infrastructure provider.
type CloudProvider struct {
// Name identifies the cloud provider.
Name string `json:"name,omitempty"`
// Zones is cloud-provider-specific zone aliases within a Region.
// If multiple entries are present, the cluster may be spanning multiple zones.
Zones []string `json:"zones,omitempty"`
// Region is the geographic location of the Zone.
Region string `json:"region,omitempty"`
}

// +kubebuilder:object:root=true
Expand All @@ -30,6 +65,17 @@ type ZoneList struct {
Items []Zone `json:"items"`
}

// GetURL invokes url.Parse for the raw string from given key, if found.
func (in URLMap) GetURL(key string) (*url.URL, error) {
if in == nil {
return nil, fmt.Errorf("map is nil")
}
if raw, found := in[key]; found {
return url.Parse(raw)
}
return nil, fmt.Errorf("key not found: %s", key)
}

func init() {
SchemeBuilder.Register(&Zone{}, &ZoneList{})
}
43 changes: 43 additions & 0 deletions api/v1/zone_types_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package v1

import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestUrlMap_GetURL(t *testing.T) {
tests := map[string]struct {
givenMap URLMap
givenKey string
expectedErr string
expectedValue string
}{
"GivenNil_ThenExpectError": {
expectedErr: "map is nil",
},
"GivenEmptyMap_WhenKeyNotPresent_ThenExpectError": {
givenMap: URLMap{},
givenKey: "key",
expectedErr: "key not found: key",
},
"GivenMap_WhenKeyPresent_ThenParseUrl": {
givenMap: URLMap{
"key": "https://hostname:80/path",
},
givenKey: "key",
expectedValue: "https://hostname:80/path",
},
}
for name, tt := range tests {
t.Run(name, func(t *testing.T) {
result, err := tt.givenMap.GetURL(tt.givenKey)
if tt.expectedErr != "" {
require.EqualError(t, err, tt.expectedErr)
return
}
assert.Equal(t, tt.expectedValue, result.String())
})
}
}
84 changes: 83 additions & 1 deletion api/v1/zz_generated.deepcopy.go

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

50 changes: 49 additions & 1 deletion config/crd/apiextensions.k8s.io/v1/base/appuio.io_zones.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,55 @@ spec:
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
data:
description: ZoneData holds all the Zone specific properties
description: Data holds the cluster specific metadata.
properties:
cloudProvider:
description: CloudProvider identifies the infrastructure provider
which the Zone is running on.
properties:
name:
description: Name identifies the cloud provider.
type: string
region:
description: Region is the geographic location of the Zone.
type: string
zones:
description: Zones is cloud-provider-specific zone aliases within
a Region. If multiple entries are present, the cluster may be
spanning multiple zones.
items:
type: string
type: array
type: object
cname:
description: CNAME is the DNS record where custom application DNS
hostnames shall be pointing to when exposing an application.
type: string
defaultAppDomain:
description: DefaultAppDomain is the base DNS record where OpenShift
Routes without specific hostnames are exposed.
type: string
displayName:
description: DisplayName is a human-friendly name for the Zone.
type: string
features:
additionalProperties:
type: string
description: Features holds a key-value dict with keys being a feature
name and values being a property of that feature. Some features
may hold a version string as property.
type: object
gatewayIPs:
description: GatewayIPs holds the outgoing IP addresses of the cluster.
items:
type: string
type: array
urls:
additionalProperties:
type: string
description: URLs holds a key-value dict with keys being a name of
the URL and the values publicly accessible links.
type: object
type: object
kind:
description: 'Kind is a string value representing the REST resource this
Expand Down

0 comments on commit ad31988

Please sign in to comment.