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

api federation types #37561

Merged
merged 4 commits into from
Dec 6, 2016
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
10 changes: 8 additions & 2 deletions cmd/kubernetes-discovery/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ go_binary(
srcs = ["main.go"],
tags = ["automanaged"],
deps = [
"//cmd/kubernetes-discovery/discoverysummarizer:go_default_library",
"//vendor:github.com/golang/glog",
"//cmd/kubernetes-discovery/pkg/apis/apiregistration/install:go_default_library",
"//cmd/kubernetes-discovery/pkg/apis/apiregistration/validation:go_default_library",
"//cmd/kubernetes-discovery/pkg/client/clientset_generated/internalclientset:go_default_library",
"//cmd/kubernetes-discovery/pkg/client/listers/apiregistration/internalversion:go_default_library",
"//cmd/kubernetes-discovery/pkg/client/listers/apiregistration/v1alpha1:go_default_library",
"//cmd/kubernetes-discovery/pkg/cmd/server:go_default_library",
"//pkg/kubectl/cmd/util:go_default_library",
"//pkg/util/logs:go_default_library",
],
)
69 changes: 69 additions & 0 deletions cmd/kubernetes-discovery/hack/update-codegen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/bin/bash

# Copyright 2016 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -o errexit
set -o nounset
set -o pipefail

KUBE_ROOT=$(dirname "${BASH_SOURCE}")/../../..
APIFEDERATOR_ROOT=$(dirname "${BASH_SOURCE}")/..
source "${KUBE_ROOT}/hack/lib/init.sh"

# Register function to be called on EXIT to remove generated binary.
function cleanup {
rm -f "${CLIENTGEN:-}"
rm -f "${listergen:-}"
}
trap cleanup EXIT

echo "Building client-gen"
CLIENTGEN="${PWD}/client-gen-binary"
go build -o "${CLIENTGEN}" ./cmd/libs/go2idl/client-gen

PREFIX=k8s.io/kubernetes/cmd/kubernetes-discovery/pkg/apis
INPUT_BASE="--input-base ${PREFIX}"
INPUT_APIS=(
apiregistration/
apiregistration/v1alpha1
)
INPUT="--input ${INPUT_APIS[@]}"
CLIENTSET_PATH="--clientset-path k8s.io/kubernetes/cmd/kubernetes-discovery/pkg/client/clientset_generated"

${CLIENTGEN} ${INPUT_BASE} ${INPUT} ${CLIENTSET_PATH}
${CLIENTGEN} --clientset-name="release_1_5" ${INPUT_BASE} --input apiregistration/v1alpha1 ${CLIENTSET_PATH}


echo "Building lister-gen"
listergen="${PWD}/lister-gen"
go build -o "${listergen}" ./cmd/libs/go2idl/lister-gen

LISTER_INPUT="--input-dirs k8s.io/kubernetes/cmd/kubernetes-discovery/pkg/apis/apiregistration --input-dirs k8s.io/kubernetes/cmd/kubernetes-discovery/pkg/apis/apiregistration/v1alpha1"
LISTER_PATH="--output-package k8s.io/kubernetes/cmd/kubernetes-discovery/pkg/client/listers"
${listergen} ${LISTER_INPUT} ${LISTER_PATH}


# TODO generated code has the wrong internal package name
# echo "Building informer-gen"
# informergen="${PWD}/informer-gen"
# go build -o "${informergen}" ./cmd/libs/go2idl/informer-gen

# ${informergen} \
# --input-dirs k8s.io/kubernetes/cmd/kubernetes-discovery/pkg/apis/apiregistration --input-dirs k8s.io/kubernetes/cmd/kubernetes-discovery/pkg/apis/apiregistration/v1alpha1 \
# --versioned-clientset-package k8s.io/kubernetes/cmd/kubernetes-discovery/pkg/client/clientset_generated/release_1_5 \
# --internal-clientset-package k8s.io/kubernetes/cmd/kubernetes-discovery/pkg/client/clientset_generated/internalclientset \
# --listers-package k8s.io/kubernetes/cmd/kubernetes-discovery/pkg/client/listers \
# --output-package k8s.io/kubernetes/cmd/kubernetes-discovery/pkg/client/informers
# "$@"
50 changes: 50 additions & 0 deletions cmd/kubernetes-discovery/hack/verify-codegen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/bash

# Copyright 2016 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -o errexit
set -o nounset
set -o pipefail

KUBE_ROOT=$(dirname "${BASH_SOURCE}")/../../..
APIFEDERATOR_ROOT=$(dirname "${BASH_SOURCE}")/..
source "${KUBE_ROOT}/hack/lib/init.sh"

DIFFROOT="${APIFEDERATOR_ROOT}/pkg"
TMP_DIFFROOT="${APIFEDERATOR_ROOT}/_tmp/pkg"
_tmp="${APIFEDERATOR_ROOT}/_tmp"

cleanup() {
rm -rf "${_tmp}"
}
trap "cleanup" EXIT SIGINT

cleanup

mkdir -p "${_tmp}"
cp -a -T "${DIFFROOT}" "${TMP_DIFFROOT}"

"${APIFEDERATOR_ROOT}/hack/update-codegen.sh"
echo "diffing ${DIFFROOT} against freshly generated codegen"
ret=0
diff -Naupr "${DIFFROOT}" "${TMP_DIFFROOT}" || ret=$?
cp -a -T "${TMP_DIFFROOT}" "${DIFFROOT}"
if [[ $ret -eq 0 ]]
then
echo "${DIFFROOT} up to date."
else
echo "${DIFFROOT} is out of date. Please run hack/update-codegen.sh"
exit 1
fi
32 changes: 21 additions & 11 deletions cmd/kubernetes-discovery/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,31 @@ limitations under the License.
package main

import (
"k8s.io/kubernetes/cmd/kubernetes-discovery/discoverysummarizer"
"os"
"runtime"

"github.com/golang/glog"
"k8s.io/kubernetes/cmd/kubernetes-discovery/pkg/cmd/server"
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
"k8s.io/kubernetes/pkg/util/logs"

// force compilation of packages we'll later rely upon
_ "k8s.io/kubernetes/cmd/kubernetes-discovery/pkg/apis/apiregistration/install"
_ "k8s.io/kubernetes/cmd/kubernetes-discovery/pkg/apis/apiregistration/validation"
_ "k8s.io/kubernetes/cmd/kubernetes-discovery/pkg/client/clientset_generated/internalclientset"
_ "k8s.io/kubernetes/cmd/kubernetes-discovery/pkg/client/listers/apiregistration/internalversion"
_ "k8s.io/kubernetes/cmd/kubernetes-discovery/pkg/client/listers/apiregistration/v1alpha1"
)

func main() {
// TODO: move them to flags.
configFilePath := "config.json"
port := "9090"
s, err := discoverysummarizer.NewDiscoverySummarizer(configFilePath)
if err != nil {
glog.Fatalf("%v\n", err)
logs.InitLogs()
defer logs.FlushLogs()

if len(os.Getenv("GOMAXPROCS")) == 0 {
runtime.GOMAXPROCS(runtime.NumCPU())
}
err = s.Run(port)
if err != nil {
glog.Fatalf("%v\n", err)

cmd := server.NewCommandStartDiscoveryServer(os.Stdout, os.Stderr)
if err := cmd.Execute(); err != nil {
cmdutil.CheckErr(err)
}
}
31 changes: 31 additions & 0 deletions cmd/kubernetes-discovery/pkg/apis/apiregistration/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package(default_visibility = ["//visibility:public"])

licenses(["notice"])

load(
"@io_bazel_rules_go//go:def.bzl",
"go_binary",
"go_library",
"go_test",
"cgo_library",
)

go_library(
name = "go_default_library",
srcs = [
"doc.go",
"helpers.go",
"register.go",
"types.go",
"zz_generated.deepcopy.go",
],
tags = ["automanaged"],
deps = [
"//pkg/api:go_default_library",
"//pkg/apis/meta/v1:go_default_library",
"//pkg/conversion:go_default_library",
"//pkg/runtime:go_default_library",
"//pkg/runtime/schema:go_default_library",
"//pkg/watch/versioned:go_default_library",
],
)
21 changes: 21 additions & 0 deletions cmd/kubernetes-discovery/pkg/apis/apiregistration/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
Copyright 2016 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// +k8s:deepcopy-gen=package,register

// Package api is the internal version of the API.
// +groupName=apiregistration.k8s.io
package apiregistration
59 changes: 59 additions & 0 deletions cmd/kubernetes-discovery/pkg/apis/apiregistration/helpers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
Copyright 2016 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package apiregistration

import (
"sort"
"strings"
)

func SortedByGroup(servers []*APIService) [][]*APIService {
serversByPriority := ByPriority(servers)
sort.Sort(serversByPriority)

ret := [][]*APIService{}
for _, curr := range serversByPriority {
// check to see if we already have an entry for this group
existingIndex := -1
for j, groupInReturn := range ret {
if groupInReturn[0].Spec.Group == curr.Spec.Group {
existingIndex = j
break
}
}

if existingIndex >= 0 {
ret[existingIndex] = append(ret[existingIndex], curr)
continue
}

ret = append(ret, []*APIService{curr})
}

return ret
}

type ByPriority []*APIService

func (s ByPriority) Len() int { return len(s) }
func (s ByPriority) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
func (s ByPriority) Less(i, j int) bool {
if s[i].Spec.Priority == s[j].Spec.Priority {
return strings.Compare(s[i].Name, s[j].Name) < 0
}
return s[i].Spec.Priority < s[j].Spec.Priority
}
23 changes: 23 additions & 0 deletions cmd/kubernetes-discovery/pkg/apis/apiregistration/install/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package(default_visibility = ["//visibility:public"])

licenses(["notice"])

load(
"@io_bazel_rules_go//go:def.bzl",
"go_binary",
"go_library",
"go_test",
"cgo_library",
)

go_library(
name = "go_default_library",
srcs = ["install.go"],
tags = ["automanaged"],
deps = [
"//cmd/kubernetes-discovery/pkg/apis/apiregistration:go_default_library",
"//cmd/kubernetes-discovery/pkg/apis/apiregistration/v1alpha1:go_default_library",
"//pkg/apimachinery/announced:go_default_library",
"//pkg/util/sets:go_default_library",
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
Copyright 2016 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package install

import (
"k8s.io/kubernetes/cmd/kubernetes-discovery/pkg/apis/apiregistration"
"k8s.io/kubernetes/cmd/kubernetes-discovery/pkg/apis/apiregistration/v1alpha1"
"k8s.io/kubernetes/pkg/apimachinery/announced"
"k8s.io/kubernetes/pkg/util/sets"
)

func init() {
if err := announced.NewGroupMetaFactory(
&announced.GroupMetaFactoryArgs{
GroupName: apiregistration.GroupName,
RootScopedKinds: sets.NewString("APIService"),
VersionPreferenceOrder: []string{v1alpha1.SchemeGroupVersion.Version},
ImportPrefix: "k8s.io/kubernetes/cmd/kubernetes-discovery/pkg/apis/apiregistration",
AddInternalObjectsToScheme: apiregistration.AddToScheme,
},
announced.VersionToSchemeFunc{
v1alpha1.SchemeGroupVersion.Version: v1alpha1.AddToScheme,
},
).Announce().RegisterAndEnable(); err != nil {
panic(err)
}
}
Loading