Skip to content

Commit

Permalink
Move rke away from kdm vendor
Browse files Browse the repository at this point in the history
  • Loading branch information
Daishan committed Feb 24, 2020
1 parent 8d05697 commit d2d7276
Show file tree
Hide file tree
Showing 12 changed files with 4,486 additions and 30 deletions.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,31 @@ Please use [High Availability (HA) Install](https://rancher.com/docs/rancher/v2.

RKE can be built using the `make` command, and will use the scripts in the `scripts` directory as subcommands. The default subcommand is `ci` and will use `scripts/ci`. Cross compiling can be enabled by setting the environment variable `CROSS=1`. The compiled binaries can be found in the `build/bin` directory. Dependencies are managed by Go modules and can be found in [go.mod](https://github.com/rancher/rke/blob/master/go.mod).

RKE now fetches `data.json` from https://github.com/rancher/kontainer-driver-metadata. To fetch data.json and compile it in rke, run

```bash
go generate

# Change RANCHER_METADATA_URL to an external URL instead of using https://releases.rancher.com/kontainer-driver-metadata/dev-v2.4/data.json by default
RANCHER_METADATA_URL=${URL} go generate

# Or load it from local file
RANCHER_METATDATA_URL=./local/data.json go generate

# Compile RKE
make
```

To specify RANCHER_METADATA_URL in runtime, populate the environment variable when running rke CLI. For example:

```bash
RANCHER_METADATA_URL=${URL} rke [commands] [options]

RANCHER_METATDATA_URL=${./local/data.json} rke [commands] [options]
```

`RANCHER_METADATA_URL` defaults to `https://releases.rancher.com/kontainer-driver-metadata/dev-v2.4/data.json`.

## License

Copyright (c) 2019 [Rancher Labs, Inc.](http://rancher.com)
Expand Down
12 changes: 6 additions & 6 deletions cluster/addons.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ import (
"strings"
"time"

rkeData "github.com/rancher/kontainer-driver-metadata/rke/templates"
"github.com/rancher/rke/addons"
"github.com/rancher/rke/authz"
"github.com/rancher/rke/k8s"
"github.com/rancher/rke/log"
"github.com/rancher/rke/services"
"github.com/rancher/rke/templates"
"github.com/rancher/rke/util"
"github.com/rancher/types/apis/management.cattle.io/v3"
v3 "github.com/rancher/types/apis/management.cattle.io/v3"
"github.com/rancher/types/kdm"
"github.com/sirupsen/logrus"
"gopkg.in/yaml.v2"
appsv1 "k8s.io/api/apps/v1"
Expand Down Expand Up @@ -285,7 +285,7 @@ func (c *Cluster) deployKubeDNS(ctx context.Context, data map[string]interface{}
return err
}
KubeDNSConfig.LinearAutoscalerParams = string(linearModeBytes)
tmplt, err := templates.GetVersionedTemplates(rkeData.KubeDNS, data, c.Version)
tmplt, err := templates.GetVersionedTemplates(kdm.KubeDNS, data, c.Version)
if err != nil {
return err
}
Expand Down Expand Up @@ -318,7 +318,7 @@ func (c *Cluster) deployCoreDNS(ctx context.Context, data map[string]interface{}
return err
}
CoreDNSConfig.LinearAutoscalerParams = string(linearModeBytes)
tmplt, err := templates.GetVersionedTemplates(rkeData.CoreDNS, data, c.Version)
tmplt, err := templates.GetVersionedTemplates(kdm.CoreDNS, data, c.Version)
if err != nil {
return err
}
Expand Down Expand Up @@ -364,7 +364,7 @@ func (c *Cluster) deployMetricServer(ctx context.Context, data map[string]interf
UpdateStrategy: c.Monitoring.UpdateStrategy,
Replicas: c.Monitoring.Replicas,
}
tmplt, err := templates.GetVersionedTemplates(rkeData.MetricsServer, data, c.Version)
tmplt, err := templates.GetVersionedTemplates(kdm.MetricsServer, data, c.Version)
if err != nil {
return err
}
Expand Down Expand Up @@ -531,7 +531,7 @@ func (c *Cluster) deployIngress(ctx context.Context, data map[string]interface{}
ingressConfig.AlpineImage = c.SystemImages.Alpine
}
}
tmplt, err := templates.GetVersionedTemplates(rkeData.NginxIngress, data, c.Version)
tmplt, err := templates.GetVersionedTemplates(kdm.NginxIngress, data, c.Version)
if err != nil {
return err
}
Expand Down
4 changes: 3 additions & 1 deletion cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,9 @@ func InitClusterObject(ctx context.Context, rkeConfig *v3.RancherKubernetesEngin
},
}
if metadata.K8sVersionToRKESystemImages == nil {
metadata.InitMetadata(ctx)
if err := metadata.InitMetadata(ctx); err != nil {
return nil, err
}
}
if len(c.ConfigPath) == 0 {
c.ConfigPath = pki.ClusterConfig
Expand Down
3 changes: 0 additions & 3 deletions cluster/encryption.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,9 +381,6 @@ func resolveCustomEncryptionConfig(clusterFile string) (string, *apiserverconfig
if err != nil {
return clusterFile, nil, fmt.Errorf("error unmarshalling: %v", err)
}
if err != nil {
return "", nil, fmt.Errorf("error unmarshalling encryption custom config: %v", err)
}
services, ok := r["services"].(map[string]interface{})
if services == nil || !ok {
return clusterFile, nil, nil
Expand Down
38 changes: 38 additions & 0 deletions codegen/codegen.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package main

import (
"fmt"
"io/ioutil"
"net/http"
"os"

"github.com/rancher/rke/metadata"
)

const (
defaultURL = "https://releases.rancher.com/kontainer-driver-metadata/dev-v2.4/data.json"
dataFile = "data/data.json"
)

// Codegen fetch data.json from https://releases.rancher.com/kontainer-driver-metadata/dev-v2.4/data.json and generates bindata
func main() {
u := os.Getenv(metadata.RancherMetadataURLEnv)
if u == "" {
u = defaultURL
}
data, err := http.Get(u)
if err != nil {
panic(fmt.Errorf("failed to fetch data.json from kontainer-driver-metadata repository"))
}
defer data.Body.Close()

b, err := ioutil.ReadAll(data.Body)
if err != nil {
panic(err)
}

fmt.Println("Writing data")
if err := ioutil.WriteFile(dataFile, b, 0755); err != nil {
return
}
}
246 changes: 246 additions & 0 deletions data/bindata.go

Large diffs are not rendered by default.

Loading

0 comments on commit d2d7276

Please sign in to comment.