Skip to content

Commit

Permalink
Remove scoped reference
Browse files Browse the repository at this point in the history
All commonv1alpha1.ScopedReferences are removed in favor of simple
corev1.LocalObjectReferences.

Additionally, the manager overlay is
removed as relation computation w/o the refs does not make that much
sense anymore.
Also, dependency and dependant triggering via watches and field indexers
is the proper way how it is built into any controller using the
controller-runtime and makes us behave more in line / not having to
maintain additional overlays.
  • Loading branch information
adracus committed Sep 27, 2021
1 parent 0177fc7 commit a81cf44
Show file tree
Hide file tree
Showing 57 changed files with 452 additions and 1,312 deletions.
20 changes: 0 additions & 20 deletions apis/common/v1alpha1/classes.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,26 +52,6 @@ type ZoneAvailability struct {
Name string `json:"name"`
}

//+kubebuilder:object:generate=true

// ScopedReference refers to a scope and the scopes name
type ScopedReference struct {
// Name is the name of the scope
Name string `json:"name"`
// Scope is the absolute scope path
//+optional
Scope string `json:"scope,omitempty"`
}

// ScopedKindReference defines an object with its kind and API group and its scope reference
type ScopedKindReference struct {
// Kind is the kind of the object
Kind string `json:"kind"`
// APIGroup is the API group of the object
APIGroup string `json:"apiGroup"`
ScopedReference `json:",inline"`
}

// ConfigMapKeySelector is a reference to a specific 'key' within a ConfigMap resource.
// In some instances, `key` is a required field.
type ConfigMapKeySelector struct {
Expand Down
31 changes: 0 additions & 31 deletions apis/common/v1alpha1/zz_generated.deepcopy.go

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

3 changes: 2 additions & 1 deletion apis/compute/v1alpha1/image_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package v1alpha1

import (
common "github.com/onmetal/onmetal-api/apis/common/v1alpha1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand All @@ -40,7 +41,7 @@ type ImageSpec struct {
// Source defines the source artefacts and their corresponding location
Source []SourceAttribute `json:"source"`
// ImageRef is a scoped reference to an existing Image
ImageRef common.ScopedReference `json:"imageRef,omitempty"`
ImageRef corev1.LocalObjectReference `json:"imageRef,omitempty"`
// Flags is a generic key value pair used for defining Image hints
Flags []Flag `json:"flags,omitempty"`
}
Expand Down
15 changes: 8 additions & 7 deletions apis/compute/v1alpha1/machine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package v1alpha1

import (
common "github.com/onmetal/onmetal-api/apis/common/v1alpha1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand All @@ -27,19 +28,19 @@ type MachineSpec struct {
// Hostname is the hostname of the machine
Hostname string `json:"hostname"`
// MachineClass is the machine class/flavor of the machine
MachineClass common.ScopedReference `json:"machineClass"`
MachineClass corev1.LocalObjectReference `json:"machineClass"`
// MachinePool defines the compute pool of the machine
MachinePool common.ScopedReference `json:"machinePool,omitempty"`
MachinePool corev1.LocalObjectReference `json:"machinePool,omitempty"`
// Location is the physical location of the machine
Location common.Location `json:"location"`
// Image is the operating system image of the machine
Image common.ScopedReference `json:"image"`
Image corev1.LocalObjectReference `json:"image"`
// SSHPublicKeys is a list of SSH public keys of a machine
SSHPublicKeys []SSHPublicKeyEntry `json:"sshPublicKeys"`
// Interfaces define a list of network interfaces present on the machine
Interfaces []Interface `json:"interfaces,omitempty"`
// SecurityGroups is a list of security groups of a machine
SecurityGroups []common.ScopedReference `json:"securityGroups"`
SecurityGroups []corev1.LocalObjectReference `json:"securityGroups"`
// VolumeClaims
VolumeClaims []VolumeClaim `json:"volumeClaims"`
// UserData defines the ignition file
Expand All @@ -51,7 +52,7 @@ type Interface struct {
// Name is the name of the interface
Name string `json:"name"`
// Target is the referenced resource of this interface
Target common.ScopedKindReference `json:"target"`
Target corev1.LocalObjectReference `json:"target"`
// Priority is the priority level of this interface
Priority int `json:"priority,omitempty"`
// IP specifies a concrete IP address which should be allocated from a Subnet
Expand All @@ -69,11 +70,11 @@ type VolumeClaim struct {
// Device defines the device for a volume on the machine
Device string `json:"device"`
// StorageClass describes the storage class of the volumes
StorageClass common.ScopedReference `json:"storageClass"`
StorageClass corev1.LocalObjectReference `json:"storageClass"`
// Size defines the size of the volume
Size *resource.Quantity `json:"size,omitempty"`
// Volume is a reference to an existing volume
Volume common.ScopedReference `json:"volume,omitempty"`
Volume corev1.LocalObjectReference `json:"volume,omitempty"`
}

type RetainPolicy string
Expand Down
3 changes: 2 additions & 1 deletion apis/compute/v1alpha1/zz_generated.deepcopy.go

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

17 changes: 14 additions & 3 deletions apis/network/v1alpha1/gateway_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package v1alpha1

import (
common "github.com/onmetal/onmetal-api/apis/common/v1alpha1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand All @@ -34,12 +35,22 @@ type GatewaySpec struct {
// Regions is a list of regions where this Gateway should be available
Regions []string `json:"regions,omitempty"`
FilterRules []FilterRule `json:"filterRules,omitempty"`
// Uplink is either a ReservedIP or a Subnet
Uplink common.ScopedKindReference `json:"uplink"`
// UplinkRef is either a ReservedIP or a Subnet
UplinkRef GatewayUplink `json:"uplink"`
}

// GatewayUplink contains information that points to the resource being used.
type GatewayUplink struct {
// APIGroup is the group for the resource being referenced
APIGroup string `json:"apiGroup" protobuf:"bytes,1,opt,name=apiGroup"`
// Kind is the type of resource being referenced
Kind string `json:"kind" protobuf:"bytes,2,opt,name=kind"`
// Name is the name of resource being referenced
Name string `json:"name" protobuf:"bytes,3,opt,name=name"`
}

type FilterRule struct {
SecurityGroup common.ScopedReference `json:"securityGroup,omitempty"`
SecurityGroup corev1.LocalObjectReference `json:"securityGroup,omitempty"`
}

// GatewayStatus defines the observed state of Gateway
Expand Down
3 changes: 2 additions & 1 deletion apis/network/v1alpha1/ipamrange_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package v1alpha1

import (
common "github.com/onmetal/onmetal-api/apis/common/v1alpha1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
)
Expand All @@ -35,7 +36,7 @@ var IPAMRangeGK = schema.GroupKind{
// Otherwise, the status of the object will be set to "Invalid".
type IPAMRangeSpec struct {
// Parent is the reference of the Parent IPAMRange from which the Cidr or size should be derived
Parent *common.ScopedReference `json:"parent,omitempty"`
Parent *corev1.LocalObjectReference `json:"parent,omitempty"`
// CIDRs is a list of CIDR specs which are defined for this IPAMRange
CIDRs []string `json:"cidrs,omitempty"`
// Mode
Expand Down
4 changes: 2 additions & 2 deletions apis/network/v1alpha1/ipamrange_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ func (r *IPAMRange) ValidateCreate() error {
}

if r.Spec.Parent != nil {
if r.Spec.Parent.Name == "" && r.Spec.Parent.Scope != "" {
allErrs = append(allErrs, field.Invalid(path.Child("parent").Child("name"), r.Spec.Parent.Name, "parent name must be set"))
if r.Spec.Parent.Name == "" {
allErrs = append(allErrs, field.Required(path.Child("parent").Child("name"), r.Spec.Parent.Name))
}
}

Expand Down
19 changes: 15 additions & 4 deletions apis/network/v1alpha1/reservedip_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,29 @@ package v1alpha1

import (
common "github.com/onmetal/onmetal-api/apis/common/v1alpha1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// ReservedIPSpec defines the desired state of ReservedIP
type ReservedIPSpec struct {
// Subnet references the subnet where an IP address should be reserved
Subnet common.ScopedReference `json:"subnet"`
Subnet corev1.LocalObjectReference `json:"subnet"`
// IP specifies an IP address which should be reserved. Must be in the CIDR of the
// associated Subnet
IP common.IPAddr `json:"ip,omitempty"`
// Assignment indicates to which resource this IP address should be assigned
Assignment common.ScopedKindReference `json:"assignment,omitempty"`
Assignment ReservedIPAssignment `json:"assignment,omitempty"`
}

// ReservedIPAssignment contains information that points to the resource being used.
type ReservedIPAssignment struct {
// APIGroup is the group for the resource being referenced
APIGroup string `json:"apiGroup" protobuf:"bytes,1,opt,name=apiGroup"`
// Kind is the type of resource being referenced
Kind string `json:"kind" protobuf:"bytes,2,opt,name=kind"`
// Name is the name of resource being referenced
Name string `json:"name" protobuf:"bytes,3,opt,name=name"`
}

// ReservedIPStatus defines the observed state of ReservedIP
Expand All @@ -42,8 +53,8 @@ type ReservedIPStatus struct {

// ReservedIPBound describes the binding state of a ReservedIP
type ReservedIPBound struct {
Mode string `json:"mode"`
Assignment common.ScopedKindReference `json:"assignment,omitempty"`
Mode string `json:"mode"`
Assignment ReservedIPAssignment `json:"assignment,omitempty"`
}

const (
Expand Down
5 changes: 3 additions & 2 deletions apis/network/v1alpha1/routingdomain_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package v1alpha1

import (
common "github.com/onmetal/onmetal-api/apis/common/v1alpha1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand All @@ -32,11 +33,11 @@ type RoutingDomainSpec struct {
// Route describes a single route definition
type Route struct {
// SubnetRef is a reference to Subnet
SubnetRef common.ScopedReference `json:"subnetRef,omitempty"`
SubnetRef corev1.LocalObjectReference `json:"subnetRef,omitempty"`
// CIDR is the matching CIDR of a Route
CIDR string `json:"cidr,omitempty"`
// Target is the target object of a Route
Target common.ScopedKindReference `json:"target,omitempty"`
Target corev1.LocalObjectReference `json:"target,omitempty"`
}

// RoutingDomainStatus defines the observed state of RoutingDomain
Expand Down
5 changes: 3 additions & 2 deletions apis/network/v1alpha1/securitygroup_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package v1alpha1

import (
common "github.com/onmetal/onmetal-api/apis/common/v1alpha1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down Expand Up @@ -48,7 +49,7 @@ type SecurityGroupRule struct {
// Name is the name of the SecurityGroupRule
Name string `json:"name"`
// SecurityGroupRef is a scoped reference to an existing SecurityGroup
SecurityGroupRef common.ScopedReference `json:"securityGroupRef,omitempty"`
SecurityGroupRef corev1.LocalObjectReference `json:"securityGroupRef,omitempty"`
// Action defines the action type of a SecurityGroupRule
Action ActionType `json:"action,omitempty"`
// Protocol defines the protocol of a SecurityGroupRule
Expand All @@ -62,7 +63,7 @@ type IPSetSpec struct {
// CIDR block for source/destination
CIDR common.Cidr `json:"cidr,omitempty"`
// SecurityGroupRef references a security group
SecurityGroupRef common.ScopedReference `json:"securityGroupref,omitempty"`
SecurityGroupRef corev1.LocalObjectReference `json:"securityGroupref,omitempty"`
}

// PortRange defines the start and end of a port range
Expand Down
7 changes: 4 additions & 3 deletions apis/network/v1alpha1/subnet_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package v1alpha1

import (
common "github.com/onmetal/onmetal-api/apis/common/v1alpha1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
)
Expand All @@ -31,11 +32,11 @@ var SubnetGK = schema.GroupKind{
type SubnetSpec struct {
// Parent is a reference to a public parent Subnet without regional manifestation. The direct children
// then represent the regional incarnations of this public subnet.
Parent common.ScopedReference `json:"parent,omitempty"`
Parent corev1.LocalObjectReference `json:"parent,omitempty"`
// Locations defines in which regions and availability zone this subnet should be available
Locations []common.RegionAvailability `json:"locations,omitempty"`
// RoutingDomain is the reference to the routing domain this SubNet should be associated with
RoutingDomain common.ScopedReference `json:"routingDomain"`
RoutingDomain corev1.LocalObjectReference `json:"routingDomain"`
// Ranges defines the size of the subnet
// +kubebuilder:validation:MinItems:=1
Ranges []RangeType `json:"ranges,omitempty"`
Expand All @@ -44,7 +45,7 @@ type SubnetSpec struct {
// RangeType defines the range/size of a subnet
type RangeType struct {
// IPAM is a reference to the an range block of a subnet
IPAM common.ScopedReference `json:"ipam,omitempty"`
IPAM corev1.LocalObjectReference `json:"ipam,omitempty"`
// Size defines the size of a subnet e.g. "/12"
Size string `json:"size,omitempty"`
// CIDR is the CIDR block
Expand Down
Loading

0 comments on commit a81cf44

Please sign in to comment.