Skip to content

Commit

Permalink
Added list available feature-gates/admission-controllers functions (#59)
Browse files Browse the repository at this point in the history
* Added list available feature-gates/admission-controllers functions

* Update kubeoptions godoc

* Naming improvements; update cluster doc
  • Loading branch information
pavelpereyma authored Aug 25, 2021
1 parent 949956b commit 048e2e9
Show file tree
Hide file tree
Showing 8 changed files with 745 additions and 15 deletions.
22 changes: 12 additions & 10 deletions pkg/v1/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,18 @@ import (
)

const (
ResourceURLCluster = "clusters"
ResourceURLKubeversion = "kubeversions"
ResourceURLKubeconfig = "kubeconfig"
ResourceURLRotateCerts = "rotate-certs"
ResourceURLUpgradePatchVersion = "upgrade-patch-version"
ResourceURLUpgradeMinorVersion = "upgrade-minor-version"
ResourceURLTask = "tasks"
ResourceURLNodegroup = "nodegroups"
ResourceURLResize = "resize"
ResourceURLReinstall = "reinstall"
ResourceURLCluster = "clusters"
ResourceURLKubeversion = "kubeversions"
ResourceURLKubeconfig = "kubeconfig"
ResourceURLRotateCerts = "rotate-certs"
ResourceURLUpgradePatchVersion = "upgrade-patch-version"
ResourceURLUpgradeMinorVersion = "upgrade-minor-version"
ResourceURLTask = "tasks"
ResourceURLNodegroup = "nodegroups"
ResourceURLResize = "resize"
ResourceURLReinstall = "reinstall"
ResourceURLFeatureGates = "feature-gates"
ResourceURLAdmissionControllers = "admission-controllers"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion pkg/v1/cluster/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Example of updating an existing cluster
KubernetesOptions: &cluster.KubernetesOptions{
EnablePodSecurityPolicy: false,
FeatureGates: []string{
"BoundServiceAccountTokenVolume",
"TTLAfterFinished",
},
AdmissionControllers: []string{
"NamespaceLifecycle",
Expand Down
8 changes: 4 additions & 4 deletions pkg/v1/cluster/testing/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const testGetClusterResponseRaw = `
"kubernetes_options": {
"enable_pod_security_policy": true,
"feature_gates": [
"BoundServiceAccountTokenVolume",
"TTLAfterFinished",
"CSIMigrationOpenStack"
],
"admission_controllers": [
Expand Down Expand Up @@ -71,7 +71,7 @@ var expectedGetClusterResponse = &cluster.View{
KubernetesOptions: &cluster.KubernetesOptions{
EnablePodSecurityPolicy: true,
FeatureGates: []string{
"BoundServiceAccountTokenVolume",
"TTLAfterFinished",
"CSIMigrationOpenStack",
},
AdmissionControllers: []string{
Expand Down Expand Up @@ -107,7 +107,7 @@ const testGetZonalClusterResponseRaw = `
"kubernetes_options": {
"enable_pod_security_policy": true,
"feature_gates": [
"BoundServiceAccountTokenVolume",
"TTLAfterFinished",
"CSIMigrationOpenStack"
],
"admission_controllers": [
Expand Down Expand Up @@ -142,7 +142,7 @@ var expectedGetZonalClusterResponse = &cluster.View{
KubernetesOptions: &cluster.KubernetesOptions{
EnablePodSecurityPolicy: true,
FeatureGates: []string{
"BoundServiceAccountTokenVolume",
"TTLAfterFinished",
"CSIMigrationOpenStack",
},
AdmissionControllers: []string{
Expand Down
25 changes: 25 additions & 0 deletions pkg/v1/kubeoptions/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
Package kubeoptions provides the ability to retrieve all available Kubernetes
feature gates and admission controllers through the MKS V1 API.
Example of getting available feature gates by Kubernetes version:
availableFG, _, err := kubeoptions.ListFeatureGates(ctx, mksClient)
if err != nil {
log.Fatal(err)
}
for _, fgList := range availableFG {
fmt.Printf("%s: %v\n", fgList.KubeVersion, fgList.Names)
}
Example of getting available admission controllers by Kubernetes version:
availableAC, _, err := kubeoptions.ListAdmissionControllers(ctx, mksClient)
if err != nil {
log.Fatal(err)
}
for _, acList := range availableAC {
fmt.Printf("%s: %v\n", acList.KubeVersion, acList.Names)
}
*/
package kubeoptions
55 changes: 55 additions & 0 deletions pkg/v1/kubeoptions/requests.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package kubeoptions

import (
"context"
"net/http"
"strings"

v1 "github.com/selectel/mks-go/pkg/v1"
)

// ListFeatureGates gets a list of available feature gates by Kubernetes versions.
func ListFeatureGates(ctx context.Context, client *v1.ServiceClient) ([]*View, *v1.ResponseResult, error) {
url := strings.Join([]string{client.Endpoint, v1.ResourceURLFeatureGates}, "/")
responseResult, err := client.DoRequest(ctx, http.MethodGet, url, nil)
if err != nil {
return nil, nil, err
}
if responseResult.Err != nil {
return nil, responseResult, responseResult.Err
}

// Extract available admission-controllers from the response body.
var result struct {
FGList []*View `json:"feature_gates"`
}
err = responseResult.ExtractResult(&result)
if err != nil {
return nil, responseResult, err
}

return result.FGList, responseResult, nil
}

// ListAdmissionControllers gets a list of available admission controllers by Kubernetes versions.
func ListAdmissionControllers(ctx context.Context, client *v1.ServiceClient) ([]*View, *v1.ResponseResult, error) {
url := strings.Join([]string{client.Endpoint, v1.ResourceURLAdmissionControllers}, "/")
responseResult, err := client.DoRequest(ctx, http.MethodGet, url, nil)
if err != nil {
return nil, nil, err
}
if responseResult.Err != nil {
return nil, responseResult, responseResult.Err
}

// Extract available admission-controllers from the response body.
var result struct {
ACList []*View `json:"admission_controllers"`
}
err = responseResult.ExtractResult(&result)
if err != nil {
return nil, responseResult, err
}

return result.ACList, responseResult, nil
}
10 changes: 10 additions & 0 deletions pkg/v1/kubeoptions/schemas.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package kubeoptions

// View represents list of feature-gates/admission-controllers by kubernetes version.
type View struct {
// KubeVersion represents the Kubernetes minor version in format: "X.Y".
KubeVersion string `json:"KubeVersionMinor"`

// Names represents list of feature-gate names.
Names []string `json:"Names"`
}
Loading

0 comments on commit 048e2e9

Please sign in to comment.