Skip to content

Commit

Permalink
Add internal API representation of nodepools
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Shen <[email protected]>
  • Loading branch information
mjlshen committed Jun 10, 2024
1 parent ace4e8b commit 0554119
Show file tree
Hide file tree
Showing 9 changed files with 315 additions and 38 deletions.
2 changes: 1 addition & 1 deletion frontend/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ require (
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.19.0 // indirect
github.com/go-playground/validator/v10 v10.21.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt/v4 v4.4.1 // indirect
github.com/golang-jwt/jwt/v5 v5.2.1 // indirect
Expand Down
4 changes: 2 additions & 2 deletions frontend/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/o
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
github.com/go-playground/validator/v10 v10.19.0 h1:ol+5Fu+cSq9JD7SoSqe04GMI92cbn0+wvQ3bZ8b/AU4=
github.com/go-playground/validator/v10 v10.19.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
github.com/go-playground/validator/v10 v10.21.0 h1:4fZA11ovvtkdgaeev9RGWPgc1uj3H8W+rNYyH/ySBb0=
github.com/go-playground/validator/v10 v10.21.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI=
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
Expand Down
1 change: 1 addition & 0 deletions frontend/pkg/frontend/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ const (
PathSegmentResourceName = "resourcename"
PathSegmentDeploymentName = "deploymentname"
PathSegmentActionName = "actionname"
PathSegmentNodepoolName = "nodepoolname"
)
34 changes: 24 additions & 10 deletions frontend/pkg/frontend/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ import (
"strings"
"sync/atomic"

v1 "github.com/openshift-online/ocm-sdk-go/clustersmgmt/v1"

"github.com/google/uuid"
sdk "github.com/openshift-online/ocm-sdk-go"
cmv1 "github.com/openshift-online/ocm-sdk-go/clustersmgmt/v1"
"github.com/prometheus/client_golang/prometheus/promhttp"

"github.com/Azure/ARO-HCP/frontend/pkg/database"
Expand All @@ -28,13 +27,14 @@ import (
)

const (
PatternSubscriptions = "subscriptions/{" + PathSegmentSubscriptionID + "}"
PatternLocations = "locations/{" + PageSegmentLocation + "}"
PatternProviders = "providers/" + api.ResourceType
PatternDeployments = "deployments/{" + PathSegmentDeploymentName + "}"
PatternResourceGroups = "resourcegroups/{" + PathSegmentResourceGroupName + "}"
PatternResourceName = "{" + PathSegmentResourceName + "}"
PatternActionName = "{" + PathSegmentActionName + "}"
PatternSubscriptions = "subscriptions/{" + PathSegmentSubscriptionID + "}"
PatternLocations = "locations/{" + PageSegmentLocation + "}"
PatternProviders = "providers/" + api.ResourceType
PatternNodepoolResource = "nodepools/{" + PathSegmentNodepoolName + "}"
PatternDeployments = "deployments/{" + PathSegmentDeploymentName + "}"
PatternResourceGroups = "resourcegroups/{" + PathSegmentResourceGroupName + "}"
PatternResourceName = "{" + PathSegmentResourceName + "}"
PatternActionName = "{" + PathSegmentActionName + "}"
)

type Frontend struct {
Expand Down Expand Up @@ -128,6 +128,20 @@ func NewFrontend(logger *slog.Logger, listener net.Listener, emitter Emitter, db
MuxPattern(http.MethodPost, PatternSubscriptions, PatternResourceGroups, PatternProviders, PatternResourceName, PatternActionName),
postMuxMiddleware.HandlerFunc(f.ArmResourceAction))

// Nodepool Routes
mux.Handle(
MuxPattern(http.MethodGet, PatternSubscriptions, PatternResourceGroups, PatternProviders, PatternResourceName, PatternNodepoolResource),
postMuxMiddleware.HandlerFunc(f.ArmResourceRead))
mux.Handle(
MuxPattern(http.MethodPut, PatternSubscriptions, PatternResourceGroups, PatternProviders, PatternResourceName, PatternNodepoolResource),
postMuxMiddleware.HandlerFunc(f.ArmResourceCreateOrUpdate))
mux.Handle(
MuxPattern(http.MethodPatch, PatternSubscriptions, PatternResourceGroups, PatternProviders, PatternResourceName, PatternNodepoolResource),
postMuxMiddleware.HandlerFunc(f.ArmResourceCreateOrUpdate))
mux.Handle(
MuxPattern(http.MethodDelete, PatternSubscriptions, PatternResourceGroups, PatternProviders, PatternResourceName, PatternNodepoolResource),
postMuxMiddleware.HandlerFunc(f.ArmResourceDelete))

// Exclude ARO-HCP API version validation for endpoints defined by ARM.
postMuxMiddleware = NewMiddleware(
MiddlewareLoggingPostMux,
Expand Down Expand Up @@ -350,7 +364,7 @@ func (f *Frontend) ArmResourceCreateOrUpdate(writer http.ResponseWriter, request
}

var hcpCluster *api.HCPOpenShiftCluster
var csResp *v1.ClusterGetResponse
var csResp *cmv1.ClusterGetResponse
if doc.ClusterID != "" {
csResp, err = f.conn.ClustersMgmt().V1().Clusters().Cluster(doc.ClusterID).Get().Send()
if err != nil {
Expand Down
12 changes: 12 additions & 0 deletions go.work.sum
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,29 @@ github.com/xhit/go-str2duration/v2 v2.1.0 h1:lxklc02Drh6ynqX+DdPyp5pCKLUQpRT8bp8
github.com/xhit/go-str2duration/v2 v2.1.0/go.mod h1:ohY8p+0f07DiV6Em5LKB0s2YpLtXVyJfNt1+BlmyAsU=
github.com/yuin/goldmark v1.2.1 h1:ruQGxdhGHe7FWOJPT0mKs5+pD2Xs1Bm/kdGlHO04FmM=
github.com/yuin/goldmark v1.4.13 h1:fVcFKWvrslecOb/tg+Cc05dkeYx540o0FuFt3nUVDoE=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
github.com/zalando/go-keyring v0.2.3 h1:v9CUu9phlABObO4LPWycf+zwMG7nlbb3t/B5wa97yms=
github.com/zalando/go-keyring v0.2.3/go.mod h1:HL4k+OXQfJUWaMnqyuSOc0drfGPX2b51Du6K+MRgZMk=
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA=
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2 h1:IRJeR9r1pYWsHKTRe/IInb7lYvbBVIqOgsX/u0mbOWY=
golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2/go.mod h1:TeRTkGYfJXctD9OcfyVLyj2J3IxLnKwHJR8f4D8a3YE=
golang.org/x/term v0.19.0 h1:+ThwsDv+tYfnJFhF4L8jITxu1tdTWRTZpdsWgEgjL6Q=
golang.org/x/term v0.19.0/go.mod h1:2CuTdWZ7KHSQwUzKva0cbMg6q2DMI3Mmxp+gKJbskEk=
golang.org/x/term v0.21.0 h1:WVXCp+/EBEHOj53Rvu+7KiT/iElMrO8ACK16SMZ3jaA=
golang.org/x/term v0.21.0/go.mod h1:ooXLefLobQVslOqselCNF4SxFAaoS6KujMbsGzSDmX0=
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4=
golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg=
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 h1:BZqlfIlq5YbRMFko6/PM7FjZpUb45WallggurYhKGag=
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340/go.mod h1:yD4MZYeKMBwQKVht279WycxKyM84kkAx2DPrTXaeb98=
11 changes: 11 additions & 0 deletions internal/api/enums.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,14 @@ const (
VisibilityPublic Visibility = "public"
VisibilityPrivate Visibility = "private"
)

type Effect string

const (
// EffectNoExecute - NoExecute taint effect
EffectNoExecute Effect = "NoExecute"
// EffectNoSchedule - NoSchedule taint effect
EffectNoSchedule Effect = "NoSchedule"
// EffectPreferNoSchedule - PreferNoSchedule taint effect
EffectPreferNoSchedule Effect = "PreferNoSchedule"
)
59 changes: 36 additions & 23 deletions internal/api/hcpopenshiftclusternodepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,53 @@ import (
// OpenShift clusters.
type HCPOpenShiftClusterNodePool struct {
arm.TrackedResource
Properties HCPOpenShiftClusterNodePoolProperties `json:":properties,omitempty"`
Properties HCPOpenShiftClusterNodePoolProperties `json:":properties,omitempty" validate:"required_for_put"`
}

// HCPOpenShiftClusterNodePoolProperties represents the property bag of a
// HCPOpenShiftClusterNodePool resource.
type HCPOpenShiftClusterNodePoolProperties struct {
ProvisioningState arm.ProvisioningState `json:"provisioningState,omitempty" visibility:"read"`
Profile NodePoolProfile `json:"profile,omitempty" visibility:"read,create,update"`
ProvisioningState arm.ProvisioningState `json:"provisioningState,omitempty" visibility:"read" validate:"omitempty,enum_provisioningstate"`
Spec NodePoolSpec `json:"spec,omitempty" visibility:"read,create,update" validate:"required_for_put"`
}

// NodePoolProfile represents a worker node pool configuration.
type NodePoolSpec struct {
Version VersionProfile `json:"version,omitempty" visibility:"read create update" validate:"required_for_put"`
Platform NodePoolPlatformProfile `json:"platform,omitempty" visibility:"read create" validate:"required_for_put"`
Replicas int32 `json:"replicas,omitempty" visibility:"read create update"`
AutoRepair bool `json:"autoRepair,omitempty" visibility:"read create"`
Autoscaling NodePoolAutoscaling `json:"autoscaling,omitempty" visibility:"read create update"`
Labels map[string]string `json:"labels,omitempty" visibility:"read create update"`
Taints []*Taint `json:"taints,omitempty" visibility:"read create update"`
TuningConfigs []string `json:"tuningConfigs,omitempty" visibility:"read create update"`
}

// NodePoolPlatformProfile 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"`
DiskEncryptionSetID string `json:"diskEncryptionSetId,omitempty"`
TuningConfigs []string `json:"tuningConfigs,omitempty"`
AvailabilityZone string `json:"availabilityZone,omitempty"`
DiskStorageAccountType string `json:"diskStorageAccountType,omitempty"`
VMSize string `json:"vmSize,omitempty"`
Autoscaling NodePoolAutoscaling `json:"autoscaling,omitempty"`
type NodePoolPlatformProfile struct {
SubnetID string `json:"subnetId,omitempty"`
VMSize string `json:"vmSize,omitempty" validate:"required_for_put"`
DiskSizeGB int32 `json:"diskSizeGB,omitempty"`
DiskStorageAccountType string `json:"diskStorageAccountType,omitempty"`
AvailabilityZone string `json:"availabilityZone,omitempty"`
EncryptionAtHost bool `json:"encryptionAtHost,omitempty"`
DiskEncryptionSetID string `json:"diskEncryptionSetId,omitempty"`
EphemeralOSDisk bool `json:"ephemeralOsDisk,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"`
Min int32 `json:"min,omitempty" validate:"required_for_put"`
Max int32 `json:"max,omitempty" validate:"required_for_put"`
}

type Taint struct {
Effect Effect `json:"effect,omitempty" validate:"required_for_put,enum_effect"`
Key string `json:"key,omitempty" validate:"required_for_put"`
Value string `json:"value,omitempty"`
}

func NewDefaultHCPOpenShiftClusterNodepool() *HCPOpenShiftClusterNodePool {
return &HCPOpenShiftClusterNodePool{}
}
3 changes: 1 addition & 2 deletions internal/api/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ type Version interface {
// Resource Types
// Passing a nil pointer creates a resource with default values.
NewHCPOpenShiftCluster(*HCPOpenShiftCluster) VersionedHCPOpenShiftCluster
// FIXME Disable until we have generated structs for node pools.
//NewHCPOpenShiftClusterNodePool(*HCPOpenShiftClusterNodePool) VersionedHCPOpenShiftClusterNodePool
NewHCPOpenShiftClusterNodePool(*HCPOpenShiftClusterNodePool) VersionedHCPOpenShiftClusterNodePool
}

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

0 comments on commit 0554119

Please sign in to comment.