Skip to content

Commit

Permalink
Merge pull request #402 from yue9944882/chore/example-pod-exec
Browse files Browse the repository at this point in the history
Chore: Example pod exec
  • Loading branch information
k8s-ci-robot committed Aug 27, 2019
2 parents 4cf9042 + a592bee commit 5d8eda2
Show file tree
Hide file tree
Showing 79 changed files with 12,435 additions and 21 deletions.
25 changes: 24 additions & 1 deletion Gopkg.lock

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

12 changes: 12 additions & 0 deletions example/podexec/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
bin/
default.etcd/
kubeconfig
apiserver.local.config/
zz_generated*
pkg/client/*_generated
pkg/openapi/openapi_generated.go
.crt
.key
vendor/**
Gopkg.*
violations.report
15 changes: 15 additions & 0 deletions example/podexec/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

# gazelle:proto disable
# gazelle:exclude vendor
load("@io_bazel_rules_go//go:def.bzl", "gazelle")

gazelle(
name = "gazelle",
command = "fix",
prefix = "sigs.k8s.io/apiserver-builder-alpha/example/podexec",
external = "vendored",
args = [
"-build_file_name",
"BUILD,BUILD.bazel",
],
)
4 changes: 4 additions & 0 deletions example/podexec/PROJECT
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

version: "1"
domain: example.com
repo: sigs.k8s.io/apiserver-builder-alpha/example/podexec
12 changes: 12 additions & 0 deletions example/podexec/WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

http_archive(
name = "io_bazel_rules_go",
url = "https://github.com/bazelbuild/rules_go/releases/download/0.6.0/rules_go-0.6.0.tar.gz",
sha256 = "ba6feabc94a5d205013e70792accb6cce989169476668fbaf98ea9b342e13b59",
)
load("@io_bazel_rules_go//go:def.bzl", "go_rules_dependencies", "go_register_toolchains")
go_rules_dependencies()
go_register_toolchains()

load("@io_bazel_rules_go//proto:def.bzl", "proto_register_toolchains")
proto_register_toolchains()
16 changes: 16 additions & 0 deletions example/podexec/boilerplate.go.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
Copyright 2019 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.
*/

50 changes: 50 additions & 0 deletions example/podexec/cmd/apiserver/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@

/*
Copyright 2019 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 main

import (
// Make sure dep tools picks up these dependencies
_ "k8s.io/apimachinery/pkg/apis/meta/v1"
_ "github.com/go-openapi/loads"

"sigs.k8s.io/apiserver-builder-alpha/pkg/cmd/server"
_ "k8s.io/client-go/plugin/pkg/client/auth" // Enable cloud provider auth

"sigs.k8s.io/apiserver-builder-alpha/example/podexec/pkg/apis"
"sigs.k8s.io/apiserver-builder-alpha/example/podexec/pkg/openapi"
)

func main() {
version := "v0"

err := server.StartApiServerWithOptions(&server.StartOptions{
EtcdPath: "/registry/example.com",
Apis: apis.GetAllApiBuilders(),
Openapidefs: openapi.GetOpenAPIDefinitions,
Title: "Api",
Version: version,

// TweakConfigFuncs []func(apiServer *apiserver.Config) error
// FlagConfigFuncs []func(*cobra.Command) error
})
if err != nil {
panic(err)
}
}
84 changes: 84 additions & 0 deletions example/podexec/cmd/manager/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
Copyright 2019 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 main

import (
"flag"
"os"

_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
"sigs.k8s.io/apiserver-builder-alpha/example/podexec/pkg/apis"
"sigs.k8s.io/apiserver-builder-alpha/example/podexec/pkg/controller"
"sigs.k8s.io/apiserver-builder-alpha/example/podexec/pkg/webhook"
"sigs.k8s.io/controller-runtime/pkg/client/config"
"sigs.k8s.io/controller-runtime/pkg/manager"
logf "sigs.k8s.io/controller-runtime/pkg/runtime/log"
"sigs.k8s.io/controller-runtime/pkg/runtime/signals"
)

func main() {
var metricsAddr string
flag.StringVar(&metricsAddr, "metrics-addr", ":8080", "The address the metric endpoint binds to.")
flag.Parse()
logf.SetLogger(logf.ZapLogger(false))
log := logf.Log.WithName("entrypoint")

// Get a config to talk to the apiserver
log.Info("setting up client for manager")
cfg, err := config.GetConfig()
if err != nil {
log.Error(err, "unable to set up client config")
os.Exit(1)
}

// Create a new Cmd to provide shared dependencies and start components
log.Info("setting up manager")
mgr, err := manager.New(cfg, manager.Options{MetricsBindAddress: metricsAddr})
if err != nil {
log.Error(err, "unable to set up overall controller manager")
os.Exit(1)
}

log.Info("Registering Components.")

// Setup Scheme for all resources
log.Info("setting up scheme")
if err := apis.AddToScheme(mgr.GetScheme()); err != nil {
log.Error(err, "unable add APIs to scheme")
os.Exit(1)
}

// Setup all Controllers
log.Info("Setting up controller")
if err := controller.AddToManager(mgr); err != nil {
log.Error(err, "unable to register controllers to the manager")
os.Exit(1)
}

log.Info("setting up webhooks")
if err := webhook.AddToManager(mgr); err != nil {
log.Error(err, "unable to register webhooks to the manager")
os.Exit(1)
}

// Start the Cmd
log.Info("Starting the Cmd.")
if err := mgr.Start(signals.SetupSignalHandler()); err != nil {
log.Error(err, "unable to run the manager")
os.Exit(1)
}
}
7 changes: 7 additions & 0 deletions example/podexec/docs/examples/pod/pod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
note: Pod Example
sample: |
apiVersion: podexec.example.com/v1
kind: Pod
metadata:
name: pod-example
spec:
25 changes: 25 additions & 0 deletions example/podexec/pkg/apis/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

/*
Copyright 2019 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.
*/




//
// +domain=example.com

package apis

26 changes: 26 additions & 0 deletions example/podexec/pkg/apis/podexec/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

/*
Copyright 2019 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
// +groupName=podexec.example.com

// Package api is the internal version of the API.
package podexec

Loading

0 comments on commit 5d8eda2

Please sign in to comment.