norman

package module
v0.0.0-...-dfeffc8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 24, 2018 License: Apache-2.0 Imports: 19 Imported by: 0

README

Norman

An API framework for Building Rancher Style APIs backed by K8s CustomResources.

Building

make

Example

Refer to examples/

package main

import (
	"context"
	"fmt"
	"net/http"
	"os"

	"github.com/rancher/norman/generator"
	"github.com/rancher/norman/server"
	"github.com/rancher/norman/types"
)

type Foo struct {
	types.Resource
	Name     string `json:"name"`
	Foo      string `json:"foo"`
	SubThing Baz    `json:"subThing"`
}

type Baz struct {
	Name string `json:"name"`
}

var (
	version = types.APIVersion{
		Version: "v1",
		Group:   "io.cattle.core.example",
		Path:    "/example/v1",
	}

	Schemas = types.NewSchemas()
)

func main() {
	if _, err := Schemas.Import(&version, Foo{}); err != nil {
		panic(err)
	}

	server, err := server.NewAPIServer(context.Background(), os.Getenv("KUBECONFIG"), Schemas)
	if err != nil {
		panic(err)
	}

	fmt.Println("Listening on 0.0.0.0:1234")
	http.ListenAndServe("0.0.0.0:1234", server)
}

License

Copyright (c) 2014-2017 Rancher Labs, Inc.

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.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Name                string
	DisableAPI          bool
	Schemas             []*types.Schemas
	CRDs                map[*types.APIVersion][]string
	Clients             []ClientFactory
	ClientGetter        proxy.ClientGetter
	CRDStorageContext   types.StorageContext
	K8sClient           kubernetes.Interface
	APIExtClient        clientset.Interface
	Config              *rest.Config
	IgnoredKubConfigEnv bool
	Threadiness         int
	K3s                 K3sConfig

	GlobalSetup func(context.Context) (context.Context, error)
	MasterSetup func(context.Context) (context.Context, error)
	PreStart    func(context.Context) error
	APISetup    func(context.Context, *api.Server) error

	PerServerControllers []ControllerRegister
	MasterControllers    []ControllerRegister
}

func (*Config) Build

func (c *Config) Build(ctx context.Context, opts Options) (context.Context, *Server, error)

type ControllerRegister

type ControllerRegister func(ctx context.Context) error

type K3sConfig

type K3sConfig struct {
	DataDir                string
	RemoteDialerAuthorizer remotedialer.Authorizer
}

type Options

type Options struct {
	K8sMode            string
	DisableControllers bool
}

type Runtime

type Runtime struct {
	AllSchemas        *types.Schemas
	LocalConfig       *rest.Config
	UnversionedClient rest.Interface
	APIHandler        http.Handler
	K3sTunnelServer   http.Handler
	K3sServerConfig   *server.ServerConfig
	Embedded          bool
}

type Server

type Server struct {
	*Config
	*Runtime
}

func GetServer

func GetServer(ctx context.Context) *Server

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL