-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added list available feature-gates/admission-controllers functions (#59)
* Added list available feature-gates/admission-controllers functions * Update kubeoptions godoc * Naming improvements; update cluster doc
- Loading branch information
1 parent
949956b
commit 048e2e9
Showing
8 changed files
with
745 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"` | ||
} |
Oops, something went wrong.