Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add simple validation for BackendConfig using OpenAPI schema generation #272

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 82 additions & 22 deletions Gopkg.lock

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

7 changes: 5 additions & 2 deletions cmd/glbc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (

"k8s.io/ingress-gce/cmd/glbc/app"
"k8s.io/ingress-gce/pkg/backendconfig"
"k8s.io/ingress-gce/pkg/crd"
"k8s.io/ingress-gce/pkg/flags"
"k8s.io/ingress-gce/pkg/version"
)
Expand Down Expand Up @@ -79,8 +80,10 @@ func main() {
if err != nil {
glog.Fatalf("Failed to create kubernetes CRD client: %v", err)
}

if _, err := backendconfig.EnsureCRD(crdClient); err != nil {
// TODO(rramkumar): Reuse this CRD handler for other CRD's coming.
crdHandler := crd.NewCRDHandler(crdClient)
backendConfigCRDMeta := backendconfig.CRDMeta()
if _, err := crdHandler.EnsureCRD(backendConfigCRDMeta); err != nil {
glog.Fatalf("Failed to ensure BackendConfig CRD: %v", err)
}

Expand Down
16 changes: 10 additions & 6 deletions hack/update-codegen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,16 @@ set -o pipefail
SCRIPT_ROOT=$(dirname ${BASH_SOURCE})/..
CODEGEN_PKG=${CODEGEN_PKG:-$(cd ${SCRIPT_ROOT}; ls -d -1 ./vendor/k8s.io/code-generator 2>/dev/null || echo ../code-generator)}

# generate the code with:
# --output-base because this script should also be able to run inside the vendor dir of
# k8s.io/kubernetes. The output-base is needed for the generators to output into the vendor dir
# instead of the $GOPATH directly. For normal projects this can be dropped.
${CODEGEN_PKG}/generate-groups.sh "deepcopy,client,informer,lister" \
${CODEGEN_PKG}/generate-groups.sh \
"deepcopy,client,informer,lister" \
k8s.io/ingress-gce/pkg/backendconfig/client k8s.io/ingress-gce/pkg/apis \
backendconfig:v1beta1 \
--output-base "$(dirname ${BASH_SOURCE})/../../.." \
--go-header-file ${SCRIPT_ROOT}/hack/boilerplate.go.txt

echo "Generating openapi"
go install ${CODEGEN_PKG}/cmd/openapi-gen
${GOPATH}/bin/openapi-gen \
--output-file-base zz_generated.openapi \
--input-dirs k8s.io/ingress-gce/pkg/apis/backendconfig/v1beta1\
--output-package k8s.io/ingress-gce/pkg/apis/backendconfig/v1beta1 \
--go-header-file ${SCRIPT_ROOT}/hack/boilerplate.go.txt
34 changes: 20 additions & 14 deletions pkg/apis/backendconfig/v1beta1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,20 @@ import (
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// BackendConfig is a specification for a BackendConfig resource
// +k8s:openapi-gen=true
type BackendConfig struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec BackendConfigSpec `json:"spec"`
Status BackendConfigStatus `json:"status"`
Spec BackendConfigSpec `json:"spec,omitempty"`
Status BackendConfigStatus `json:"status,omitempty"`
}

// BackendConfigSpec is the spec for a BackendConfig resource
// +k8s:openapi-gen=true
type BackendConfigSpec struct {
Iap *IAPConfig
Cdn *CDNConfig
Iap *IAPConfig `json:"iap,omitempty"`
Cdn *CDNConfig `json:"cdn,omitempty"`
}

// BackendConfigStatus is the status for a BackendConfig resource
Expand All @@ -54,40 +56,44 @@ type BackendConfigList struct {
}

// IAPConfig contains configuration for IAP-enabled backends.
// +k8s:openapi-gen=true
type IAPConfig struct {
Enabled bool
ClientCredentials *OAuthClientCredentials
Enabled bool `json:"enabled"`
ClientCredentials *OAuthClientCredentials `json:"clientCredentials,omitempty"`
}

// OAuthClientCredentials contains credentials for a single IAP-enabled backend.
// +k8s:openapi-gen=true
type OAuthClientCredentials struct {
// The name of a k8s secret which stores the OAuth client id & secret.
Secret string
Secret string `json:"secret"`
}

// CDNConfig contains configuration for CDN-enabled backends.
// +k8s:openapi-gen=true
type CDNConfig struct {
Enabled bool
CDNPolicy *CacheKeyPolicy
Enabled bool `json:"enabled"`
CachePolicy *CacheKeyPolicy `json:"cachePolicy,omitempty"`
}

// CacheKeyPolicy contains configuration for how requests to a CDN-enabled backend are cached.
// +k8s:openapi-gen=true
type CacheKeyPolicy struct {
// If true, requests to different hosts will be cached separately.
IncludeHost bool
IncludeHost bool `json:"includeHost,omitempty"`
// If true, http and https requests will be cached separately.
IncludeProtocol bool
IncludeProtocol bool `json:"includeProtocol,omitempty"`
// If true, query string parameters are included in the cache key
// according to QueryStringBlacklist and QueryStringWhitelist.
// If neither is set, the entire query string is included and if false
// the entire query string is excluded.
IncludeQueryString bool
IncludeQueryString bool `json:"includeQueryString,omitempty"`
// Names of query strint parameters to exclude from cache keys. All other
// parameters are included. Either specify QueryStringBlacklist or
// QueryStringWhitelist, but not both.
QueryStringBlacklist []string
QueryStringBlacklist []string `json:"queryStringBlacklist,omitempty"`
// Names of query string parameters to include in cache keys. All other
// parameters are excluded. Either specify QueryStringBlacklist or
// QueryStringWhitelist, but not both.
QueryStringWhitelist []string
QueryStringWhitelist []string `json:"queryStringWhitelist,omitempty"`
}
4 changes: 2 additions & 2 deletions pkg/apis/backendconfig/v1beta1/zz_generated.deepcopy.go

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

Loading