Skip to content

Commit

Permalink
Make Machines Shared (#79)
Browse files Browse the repository at this point in the history
As this is needed by kubernetes and baremetal, make it shared to prevent
divergence.
  • Loading branch information
spjmurray authored Sep 23, 2024
1 parent 6b1105a commit c784ba3
Show file tree
Hide file tree
Showing 5 changed files with 202 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ GOBIN := $(if $(shell go env GOBIN),$(shell go env GOBIN),$(GOPATH)/bin)
LINT_VERSION=v1.57.1

# Defines the version of the CRD generation tools to use.
CONTROLLER_TOOLS_VERSION=v0.14.0
CONTROLLER_TOOLS_VERSION=v0.16.3

# Defines the version of code generator tools to use.
# This should be kept in sync with the Kubenetes library versions defined in go.mod.
Expand Down
4 changes: 2 additions & 2 deletions charts/core/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ description: A Helm chart for deploying Unikorn Core

type: application

version: v0.1.69
appVersion: v0.1.69
version: v0.1.70
appVersion: v0.1.70

icon: https://assets.unikorn-cloud.org/images/logos/dark-on-light/icon.svg

Expand Down
28 changes: 28 additions & 0 deletions pkg/apis/unikorn/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"net"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"sigs.k8s.io/structured-merge-diff/v4/value"
Expand Down Expand Up @@ -150,6 +151,33 @@ func (IPv4Prefix) OpenAPISchemaFormat() string {
return ""
}

// MachineGeneric contains common things across all machine pool types.
type MachineGeneric struct {
// Image is the region service image to deploy with.
ImageID *string `json:"imageId"`
// Flavor is the regions service flavor to deploy with.
FlavorID *string `json:"flavorId"`
// DiskSize is the persistent root disk size to deploy with. This
// overrides the default ephemeral disk size defined in the flavor.
// This is irrelevant for baremetal machine flavors.
DiskSize *resource.Quantity `json:"diskSize,omitempty"`
// Replicas is the initial pool size to deploy.
// +kubebuilder:validation:Minimum=0
// +kubebuilder:default=3
Replicas *int `json:"replicas,omitempty"`
}

// Network generic constains common networking options.
type NetworkGeneric struct {
// NodeNetwork is the IPv4 prefix for the node network.
// This is tyically used to populate a physical network address range.
NodeNetwork *IPv4Prefix `json:"nodeNetwork"`
// DNSNameservers sets the DNS nameservers for hosts on the network.
// +listType=set
// +kubebuilder:validation:MinItems=1
DNSNameservers []IPv4Address `json:"dnsNameservers"`
}

// +kubebuilder:validation:Enum=Available
type ConditionType string

Expand Down
108 changes: 108 additions & 0 deletions pkg/apis/unikorn/v1alpha1/types_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*
Copyright 2022-2023 EscherCloud.
Copyright 2024 the Unikorn Authors.
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 v1alpha1_test

import (
"net"
"testing"

"github.com/unikorn-cloud/core/pkg/apis/unikorn/v1alpha1"
)

const (
// Expect IP addresses to be marshalled as strings in dotted quad format.
testAddressMarshaled = `"192.168.0.1"`

// Expect IP prefixes to be marshalled as strings in dotted quad CIDR format.
testPrefixMarshaled = `"192.168.0.0/16"`
)

var (
// Expect IP addresses to be unmarshalled as an IPv4 address.
//nolint:gochecknoglobals
testAddressUnmarshaled = net.IPv4(192, 168, 0, 1)

// Expect IP prefixes to be unmarshalled as an IPv4 network.
//nolint:gochecknoglobals
testPrefixUnmarshaled = net.IPNet{
IP: net.IPv4(192, 168, 0, 0),
Mask: net.IPv4Mask(255, 255, 0, 0),
}
)

func TestIPv4AddressUnmarshal(t *testing.T) {
t.Parallel()

input := []byte(testAddressMarshaled)

output := &v1alpha1.IPv4Address{}

if err := output.UnmarshalJSON(input); err != nil {
t.Fatal(err)
}

if !output.IP.Equal(testAddressUnmarshaled) {
t.Fatal("address mismatch")
}
}

func TestIPv4AddressMarshal(t *testing.T) {
t.Parallel()

input := &v1alpha1.IPv4Address{IP: testAddressUnmarshaled}

output, err := input.MarshalJSON()
if err != nil {
t.Fatal()
}

if string(output) != testAddressMarshaled {
t.Fatal("address mismatch")
}
}

func TestIPv4PrefixUnmarshal(t *testing.T) {
t.Parallel()

input := []byte(testPrefixMarshaled)

output := &v1alpha1.IPv4Prefix{}

if err := output.UnmarshalJSON(input); err != nil {
t.Fatal(nil)
}

if output.String() != testPrefixUnmarshaled.String() {
t.Fatal("prefix mismatch")
}
}

func TestIPv4PrefixMarshal(t *testing.T) {
t.Parallel()

input := &v1alpha1.IPv4Prefix{IPNet: testPrefixUnmarshaled}

output, err := input.MarshalJSON()
if err != nil {
t.Fatal(err)
}

if string(output) != testPrefixMarshaled {
t.Fatal("prefix mismatch")
}
}
63 changes: 63 additions & 0 deletions pkg/apis/unikorn/v1alpha1/zz_generated.deepcopy.go

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

0 comments on commit c784ba3

Please sign in to comment.