Skip to content

Commit

Permalink
api: Synchronize with API specification
Browse files Browse the repository at this point in the history
This uses OpenShift API types for the internal representation of
a cluster's ExternalAuths. The types are not a 100% match to our
representation (data is stored in what are supposed to be config
map or secret name references) but it's close enough.

Adds a dependency on github.com/openshift/api.
  • Loading branch information
Matthew Barnes committed Mar 19, 2024
1 parent 70e7761 commit bc36a02
Show file tree
Hide file tree
Showing 16 changed files with 912 additions and 292 deletions.
21 changes: 21 additions & 0 deletions go.work.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
github.com/emicklei/go-restful/v3 v3.8.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc=
github.com/evanphx/json-patch v4.12.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14=
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/moby/spdystream v0.2.0/go.mod h1:f7i0iNDQJ059oMTcWxx8MA/zKFIuD/lY+0GqbN2Wy8c=
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U=
golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8=
40 changes: 40 additions & 0 deletions internal/api/enums.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,46 @@ package api

import "fmt"

// NetworkType represents an OpenShift cluster network plugin.
type NetworkType int

const (
NetworkTypeOpenShiftSDN NetworkType = iota
NetworkTypeOVNKubernetes

NetworkTypeOther // catch-all, must be last
)

func (v NetworkType) String() string {
switch v {
case NetworkTypeOpenShiftSDN:
return "OpenShiftSDN"
case NetworkTypeOVNKubernetes:
return "OVNKubernetes"
default:
return "Other"
}
}

func (v NetworkType) MarshalText() (text []byte, err error) {
// NetworkTypeOther is a catch-all value.
text = []byte(v.String())
return
}

func (v *NetworkType) UnmarshalText(text []byte) error {
for i := range NetworkTypeOther {
if i.String() == string(text) {
*v = i
return nil
}
}

// NetworkTypeOther is a catch-all value.
*v = NetworkTypeOther
return nil
}

// OutboundType represents a routing strategy to provide egress to the Internet.
type OutboundType int

Expand Down
65 changes: 65 additions & 0 deletions internal/api/enums_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,71 @@ import (
"testing"
)

func TestNetworkType(t *testing.T) {
// Ensure NetworkType implementes these interfaces
var i NetworkType
_ = fmt.Stringer(i)
_ = encoding.TextMarshaler(i)
_ = encoding.TextUnmarshaler(&i)

for _, tt := range []struct {
name string
val int
str string
skipMarshal bool
skipUnmarshal bool
}{
{
name: "NetworkTypeOpenShiftSDN",
val: int(NetworkTypeOpenShiftSDN),
str: fmt.Sprintf("%q", NetworkTypeOpenShiftSDN),
},
{
name: "NetworkTypeOVNKubernetes",
val: int(NetworkTypeOVNKubernetes),
str: fmt.Sprintf("%q", NetworkTypeOVNKubernetes),
},
{
name: "NetworkTypeOther",
val: int(NetworkTypeOther),
str: fmt.Sprintf("%q", NetworkTypeOther),
},
{
name: "Unknown NetworkType string",
val: int(NetworkTypeOther),
str: "\"unknown\"",
skipMarshal: true,
},
{
name: "Unknown NetworkType value",
val: -1,
str: fmt.Sprintf("%q", NetworkTypeOther),
skipUnmarshal: true,
},
} {
if !tt.skipMarshal {
t.Logf("Marshaling %d", tt.val)
data, err := json.Marshal(NetworkType(tt.val))
if err != nil {
t.Fatalf("Marshal: Unexpected error: %s", err)
} else if string(data) != tt.str {
t.Fatalf("Marshal: Expected %s, got %s", tt.str, string(data))
}
}

if !tt.skipUnmarshal {
var val NetworkType
t.Logf("Unmarshaling %s", tt.str)
err := json.Unmarshal([]byte(tt.str), &val)
if err != nil {
t.Fatalf("Unmarshal: Unexpected error: %s", err)
} else if int(val) != tt.val {
t.Fatalf("Unmarshal: Expected %d, got %d", tt.val, val)
}
}
}
}

func TestOutboundType(t *testing.T) {
// Ensure OutboundType implements these interfaces
var i OutboundType
Expand Down
140 changes: 69 additions & 71 deletions internal/api/hcpopenshiftcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ package api
import (
"net"

configv1 "github.com/openshift/api/config/v1"

"github.com/Azure/ARO-HCP/internal/api/arm"
"github.com/Azure/ARO-HCP/internal/api/json"
)
Expand All @@ -19,106 +21,102 @@ type HCPOpenShiftCluster struct {
// HCPOpenShiftClusterProperties represents the property bag of a HCPOpenShiftCluster resource.
type HCPOpenShiftClusterProperties struct {
ProvisioningState arm.ProvisioningState `json:"provisioningState,omitempty" visibility:"read"`
ClusterProfile ClusterProfile `json:"clusterProfile,omitempty" visibility:"read,create,update"`
ProxyProfile ProxyProfile `json:"proxyProfile,omitempty" visibility:"read,create,update"`
APIProfile APIProfile `json:"apiProfile,omitempty" visibility:"read,create"`
ConsoleProfile ConsoleProfile `json:"consoleProfile,omitempty" visibility:"read,create,update"`
IngressProfile IngressProfile `json:"ingressProfile,omitempty" visibility:"read,create"`
NetworkProfile NetworkProfile `json:"networkProfile,omitempty" visibility:"read,create"`
NodePoolProfiles []*NodePoolProfile `json:"nodePoolProfiles,omitempty" visibility:"read"`
EtcdEncryption EtcdEncryptionProfile `json:"etcdEncryption,omitempty" visibility:"read,create"`
Spec ClusterSpec `json:"spec,omitempty" visibility:"read,create,update"`
}

// ClusterProfile represents a high level cluster configuration.
type ClusterProfile struct {
ControlPlaneVersion string `json:"controlPlaneVersion,omitempty" visibility:"read,create,update"`
SubnetID string `json:"subnetId,omitempty" visibility:"read,create"`
ManagedResourceGroup string `json:"managedResourceGroup,omitempty" visibility:"read,create"`
OIDCIssuerURL json.URL `json:"oidcIssuerUrl,omitempty" visibility:"read"`
// ClusterSpec represents a high level cluster configuration.
type ClusterSpec struct {
Version VersionProfile `json:"version,omitempty" visibility:"read,create,update"`
DNS DNSProfile `json:"dns,omitempty" visibility:"read,create,update"`
Network NetworkProfile `json:"network,omitempty" visibility:"read,create"`
Console ConsoleProfile `json:"console,omitempty" visibility:"read"`
API APIProfile `json:"api,omitempty" visibility:"read,create"`
FIPS bool `json:"fips,omitempty" visibility:"read,create"`
EtcdEncryption bool `json:"etcdEncryption,omitempty" visibility:"read,create"`
DisableUserWorkloadMonitoring bool `json:"disableUserWorkloadMonitoring,omitempty" visibility:"read,create,update"`
Proxy ProxyProfile `json:"proxy,omitempty" visibility:"read,create,update"`
Platform PlatformProfile `json:"platform,omitempty" visibility:"read,create"`
IssuerURL json.URL `json:"issuerUrl,omitempty" visibility:"read"`
ExternalAuth ExternalAuthConfigProfile `json:"externalAuth,omitempty visibility:"read,create"`

Check failure on line 40 in internal/api/hcpopenshiftcluster.go

View workflow job for this annotation

GitHub Actions / lint

structtag: struct field tag `json:"externalAuth,omitempty visibility:"read,create"` not compatible with reflect.StructTag.Get: suspicious space in struct tag value (govet)
Ingress []*IngressProfile `json:"ingressProfile,omitempty" visibility:"read,create"`
}

// ProxyProfile represents the cluster proxy configuration.
// Visibility for the entire struct is "read,create,update".
type ProxyProfile struct {
HTTPProxy string `json:"httpProxy,omitempty"`
HTTPSProxy string `json:"httpsProxy,omitempty"`
NoProxy string `json:"noProxy,omitempty"`
TrustedCA string `json:"trustedCa,omitempty"`
// VersionProfile represents the cluster control plane version.
type VersionProfile struct {
ID string `json:"id,omitempty" visibility:"read,create,update"`
ChannelGroup string `json:channelGroup,omitempty visibility:"read,create"`

Check failure on line 47 in internal/api/hcpopenshiftcluster.go

View workflow job for this annotation

GitHub Actions / lint

structtag: struct field tag `json:channelGroup,omitempty visibility:"read,create"` not compatible with reflect.StructTag.Get: bad syntax for struct tag value (govet)
AvailableUpgrades []string `json:availableUpgrades,omitempty visibility:"read"`

Check failure on line 48 in internal/api/hcpopenshiftcluster.go

View workflow job for this annotation

GitHub Actions / lint

structtag: struct field tag `json:availableUpgrades,omitempty visibility:"read"` not compatible with reflect.StructTag.Get: bad syntax for struct tag value (govet)
}

// APIProfile represents a cluster API server configuration.
// DNSProfile represents the DNS configuration of the cluster.
type DNSProfile struct {
BaseDomain string `json:"baseDomain,omitempty" visibility:"read"`
BaseDomainPrefix string `json:"baseDomainPrefix,omitempty" visibility:"read,create"`
}

// NetworkProfile represents a cluster network configuration.
// Visibility for the entire struct is "read,create".
type APIProfile struct {
URL json.URL `json:"url,omitempty"`
IP net.IP `json:"ip,omitempty"`
Visibility Visibility `json:"visibility,omitempty"`
type NetworkProfile struct {
NetworkType NetworkType `json:"networkType,omitempty"`
PodCIDR json.IPNet `json:"podCidr,omitempty"`
ServiceCIDR json.IPNet `json:"serviceCidr,omitempty"`
MachineCIDR json.IPNet `json:"machineCidr,omitempty"`
HostPrefix int32 `json:"hostPrefix,omitempty"`
}

// ConsoleProfile represents a cluster web console configuration.
// Visibility for the entire struct is "read".
type ConsoleProfile struct {
URL json.URL `json:"url,omitempty" visibility:"read"`
FIPS bool `json:"fips,omitempty" visibility:"read,create,update"`
URL json.URL `json:"url,omitempty"`
}

// IngressProfile represents a cluster ingress configuration.
type IngressProfile struct {
IP net.IP `json:"ip,omitempty" visibility:"read"`
// APIProfile represents a cluster API server configuration.
type APIProfile struct {
URL json.URL `json:"url,omitempty" visibility:"read"`
IP net.IP `json:"ip,omitempty" visibility:"read"`
Visibility Visibility `json:"visibility,omitempty" visibility:"read,create"`
}

// NetworkProfile represents a cluster network configuration.
// Visibility for the entire struct is "read,create".
type NetworkProfile struct {
PodCIDR json.IPNet `json:"podCidr,omitempty"`
ServiceCIDR json.IPNet `json:"serviceCidr,omitempty"`
MachineCIDR json.IPNet `json:"machineCidr,omitempty"`
HostPrefix int32 `json:"hostPrefix,omitempty"`
OutboundType OutboundType `json:"outboundType,omitempty"`
PreconfiguredNSGs bool `json:"preconfiguredNsgs,omitempty"`
// ProxyProfile represents the cluster proxy configuration.
// Visibility for the entire struct is "read,create,update".
type ProxyProfile struct {
HTTPProxy string `json:"httpProxy,omitempty"`
HTTPSProxy string `json:"httpsProxy,omitempty"`
NoProxy string `json:"noProxy,omitempty"`
TrustedCA string `json:"trustedCa,omitempty"`
}

// NodePoolAutoscaling represents a node pool autoscaling configuration.
// Visibility for the entire struct is "read".
type NodePoolAutoscaling struct {
MinReplicas int32 `json:"minReplicas,omitempty"`
MaxReplicas int32 `json:"maxReplicas,omitempty"`
// PlatformProfile represents the Azure platform configuration.
// Visibility for the entire struct is "read,create".
type PlatformProfile struct {
ManagedResourceGroup string `json:"managedResourceGroup,omitempty"`
SubnetID string `json:"subnetId,omitempty"`
OutboundType OutboundType `json:"outboundType,omitempty"`
PreconfiguredNSGs bool `json:"preconfiguredNsgs,omitempty"`
EtcdEncryptionSetID string `json:"etcdEncryptionSetId,omitempty"`
}

// NodePoolProfile represents a worker node pool configuration.
// Visibility for the entire struct is "read".
type NodePoolProfile struct {
Name string `json:"name,omitempty"`
Version string `json:"version,omitempty"`
Labels []string `json:"labels,omitempty"`
Taints []string `json:"taints,omitempty"`
DiskSize int32 `json:"diskSize,omitempty"`
EphemeralOSDisk bool `json:"ephemeralOsDisk,omitempty"`
Replicas int32 `json:"replicas,omitempty"`
SubnetID string `json:"subnetId,omitempty"`
EncryptionAtHost bool `json:"encryptionAtHost,omitempty"`
AutoRepair bool `json:"autoRepair,omitempty"`
DiscEncryptionSetID string `json:"discEncryptionSetId,omitempty"`
TuningConfigs []string `json:"tuningConfigs,omitempty"`
AvailabilityZone string `json:"availabilityZone,omitempty"`
DiscStorageAccountType string `json:"discStorageAccountType,omitempty"`
VMSize string `json:"vmSize,omitempty"`
Autoscaling NodePoolAutoscaling `json:"autoscaling,omitempty"`
// ExternalAuthConfigProfile represents the external authentication configuration.
type ExternalAuthConfigProfile struct {
Enabled bool `json:"enabled,omitempty" visibility:"read,create"`
ExternalAuths []*configv1.OIDCProvider `json:"externalAuths,omitempty" visibility:"read"`
}

// EtcdEncryptionProfile represents the configuration needed for customer
// provided keys to encrypt etcd storage.
// Visibility for the entire struct is "read,create".
type EtcdEncryptionProfile struct {
DiscEncryptionSetID string `json:"discEncryptionSetId,omitempty"`
// IngressProfile represents a cluster ingress configuration.
type IngressProfile struct {
IP net.IP `json:"ip,omitempty" visibility:"read"`
URL json.URL `json:"url,omitempty" visibility:"read"`
Visibility Visibility `json:"visibility,omitempty" visibility:"read,create"`
}

// Creates an HCPOpenShiftCluster with any non-zero default values.
func NewDefaultHCPOpenShiftCluster() *HCPOpenShiftCluster {
return &HCPOpenShiftCluster{
Properties: HCPOpenShiftClusterProperties{
NetworkProfile: NetworkProfile{
HostPrefix: 23,
Spec: ClusterSpec{
Network: NetworkProfile{
HostPrefix: 23,
},
},
},
}
Expand Down
28 changes: 28 additions & 0 deletions internal/api/hcpopenshiftclusternodepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,31 @@ type HCPOpenShiftClusterNodePoolProperties struct {
ProvisioningState arm.ProvisioningState `json:"provisioningState,omitempty" visibility:"read"`
Profile NodePoolProfile `json:"profile,omitempty" visibility:"read,create,update"`
}

// NodePoolProfile represents a worker node pool configuration.
// Visibility for the entire struct is "read".
type NodePoolProfile struct {
Name string `json:"name,omitempty"`
Version string `json:"version,omitempty"`
Labels []string `json:"labels,omitempty"`
Taints []string `json:"taints,omitempty"`
DiskSize int32 `json:"diskSize,omitempty"`
EphemeralOSDisk bool `json:"ephemeralOsDisk,omitempty"`
Replicas int32 `json:"replicas,omitempty"`
SubnetID string `json:"subnetId,omitempty"`
EncryptionAtHost bool `json:"encryptionAtHost,omitempty"`
AutoRepair bool `json:"autoRepair,omitempty"`
DiscEncryptionSetID string `json:"discEncryptionSetId,omitempty"`
TuningConfigs []string `json:"tuningConfigs,omitempty"`
AvailabilityZone string `json:"availabilityZone,omitempty"`
DiscStorageAccountType string `json:"discStorageAccountType,omitempty"`
VMSize string `json:"vmSize,omitempty"`
Autoscaling NodePoolAutoscaling `json:"autoscaling,omitempty"`
}

// NodePoolAutoscaling represents a node pool autoscaling configuration.
// Visibility for the entire struct is "read".
type NodePoolAutoscaling struct {
MinReplicas int32 `json:"minReplicas,omitempty"`
MaxReplicas int32 `json:"maxReplicas,omitempty"`
}
8 changes: 0 additions & 8 deletions internal/api/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,10 @@ type VersionedHCPOpenShiftClusterNodePool interface {
ValidateStatic() error
}

type VersionedNodePoolProfile interface {
Normalize(*NodePoolProfile)
ValidateStatic() error
}

type Version interface {
// Resource Types
NewHCPOpenShiftCluster(*HCPOpenShiftCluster) VersionedHCPOpenShiftCluster
NewHCPOpenShiftClusterNodePool(*HCPOpenShiftClusterNodePool) VersionedHCPOpenShiftClusterNodePool

// Component Types
NewNodePoolProfile(*NodePoolProfile) VersionedNodePoolProfile
}

// APIs is the map of registered API versions
Expand Down
Loading

0 comments on commit bc36a02

Please sign in to comment.