Skip to content

Commit

Permalink
Add apply to example
Browse files Browse the repository at this point in the history
  • Loading branch information
justinsb committed Oct 7, 2016
1 parent 606c573 commit d965f14
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 3 deletions.
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
all: kops

.PHONY: channels
.PHONY: channels examples

DOCKER_REGISTRY?=gcr.io/must-override
S3_BUCKET?=s3://must-override/
Expand Down Expand Up @@ -194,3 +194,8 @@ channels: channels-gocode
channels-gocode:
go install ${EXTRA_BUILDFLAGS} -ldflags "-X main.BuildVersion=${VERSION} ${EXTRA_LDFLAGS}" k8s.io/kops/channels/cmd/channels

# --------------------------------------------------
# API / embedding examples

examples:
go install k8s.io/kops/examples/kops-api-example/...
2 changes: 1 addition & 1 deletion cmd/kops/update_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func init() {

cmd.Flags().BoolVar(&updateCluster.Yes, "yes", false, "Actually create cloud resources")
cmd.Flags().StringVar(&updateCluster.Target, "target", "direct", "Target - direct, terraform")
cmd.Flags().StringVar(&updateCluster.Models, "model", "config,proto,cloudup", "Models to apply (separate multiple models with commas)")
cmd.Flags().StringVar(&updateCluster.Models, "model", strings.Join(cloudup.CloudupModels, ","), "Models to apply (separate multiple models with commas)")
cmd.Flags().StringVar(&updateCluster.SSHPublicKey, "ssh-public-key", "", "SSH public key to use (deprecated: use kops create secret instead)")
cmd.Flags().StringVar(&updateCluster.OutDir, "out", "", "Path to write any local output")
}
Expand Down
11 changes: 11 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## Examples of how to embed kops / use the kops API

The kops API is still a work in progress, but this is where we will put examples of how it can be used.

```
make examples
```

```
kops-api-example -name api1.example.com -zones us-east-1c
```
27 changes: 27 additions & 0 deletions examples/kops-api-example/apply.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package main

import (
"k8s.io/kops/pkg/client/simple/vfsclientset"
"k8s.io/kops/upup/pkg/fi/cloudup"
)

func apply() error {
clientset := vfsclientset.NewVFSClientset(registryBase)

cluster, err := clientset.Clusters().Get(clusterName)
if err != nil {
return err
}

applyCmd := &cloudup.ApplyClusterCmd{
Cluster: cluster,
Clientset: clientset,
TargetName: cloudup.TargetDirect,
}
err = applyCmd.Run()
if err != nil {
return err
}

return nil
}
8 changes: 7 additions & 1 deletion examples/kops-api-example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ func main() {

err = up()
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
fmt.Fprintf(os.Stderr, "error from up: %v\n", err)
os.Exit(1)
}

err = apply()
if err != nil {
fmt.Fprintf(os.Stderr, "error from apply: %v\n", err)
os.Exit(1)
}
}
Expand Down
6 changes: 6 additions & 0 deletions upup/pkg/fi/cloudup/apply_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ const (

const MaxAttemptsWithNoProgress = 3

var CloudupModels = []string{"config","proto","cloudup"}

type ApplyClusterCmd struct {
Cluster *api.Cluster

Expand Down Expand Up @@ -73,6 +75,10 @@ func (c *ApplyClusterCmd) Run() error {
c.InstanceGroups = instanceGroups
}

if c.Models == nil {
c.Models = CloudupModels
}

modelStore, err := findModelStore()
if err != nil {
return err
Expand Down

0 comments on commit d965f14

Please sign in to comment.