Skip to content
This repository has been archived by the owner on Mar 13, 2021. It is now read-only.

Commit

Permalink
Support manifest on riff system install
Browse files Browse the repository at this point in the history
Fixes #648
  • Loading branch information
glyn committed Aug 29, 2018
1 parent 491d109 commit 2fd166b
Show file tree
Hide file tree
Showing 12 changed files with 290 additions and 56 deletions.
16 changes: 14 additions & 2 deletions cmd/commands/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,20 @@ func SystemInstall(kc *core.KubectlClient) *cobra.Command {
Short: "Install riff and Knative system components",
Long: `Install riff and Knative system components
If an 'istio-system' namespace isn't found then the it will be created and Istio components will be installed.
If an 'istio-system' namespace isn't found, it will be created and Istio components will be installed.
Use the '--node-port' flag when installing on Minikube and other clusters that don't support an external load balancer.'
Use the '--node-port' flag when installing on Minikube and other clusters that don't support an external load balancer.
Use the '--manifest' flag to specify the path of a manifest file which provides the URLs of the YAML definitions of the
components to be installed. The manifest file contents should be of the following form:
version: 0.1
istio:
- https://path/to/istio-release.yaml
knative:
- https://path/to/serving-release.yaml
- https://path/to/eventing-release.yaml
- https://path/to/stub-bus-release.yaml
`,
Example: ` riff system install`,
PreRunE: func(cmd *cobra.Command, args []string) error {
Expand Down Expand Up @@ -68,6 +79,7 @@ Use the '--node-port' flag when installing on Minikube and other clusters that d
},
}

command.Flags().StringVarP(&options.Manifest, "manifest", "m", "", "file path of a manifest file referring to the YAML files to be applied")
command.Flags().BoolVarP(&options.NodePort, "node-port", "", false, "whether to use NodePort instead of LoadBalancer for ingress gateways")
command.Flags().BoolVarP(&options.Force, "force", "", false, "force the install of components without getting any prompts")

Expand Down
22 changes: 17 additions & 5 deletions docs/riff_system_install.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,20 @@ Install riff and Knative system components

Install riff and Knative system components

If an 'istio-system' namespace isn't found then the it will be created and Istio components will be installed.
If an 'istio-system' namespace isn't found, it will be created and Istio components will be installed.

Use the '--node-port' flag when installing on Minikube and other clusters that don't support an external load balancer.'
Use the '--node-port' flag when installing on Minikube and other clusters that don't support an external load balancer.

Use the '--manifest' flag to specify the path of a manifest file which provides the URLs of the YAML definitions of the
components to be installed. The manifest file contents should be of the following form:

version: 0.1
istio:
- https://path/to/istio-release.yaml
knative:
- https://path/to/serving-release.yaml
- https://path/to/eventing-release.yaml
- https://path/to/stub-bus-release.yaml


```
Expand All @@ -24,9 +35,10 @@ riff system install [flags]
### Options

```
--force force the install of components without getting any prompts
-h, --help help for install
--node-port whether to use NodePort instead of LoadBalancer for ingress gateways
--force force the install of components without getting any prompts
-h, --help help for install
-m, --manifest string file path of a manifest file referring to the YAML files to be applied
--node-port whether to use NodePort instead of LoadBalancer for ingress gateways
```

### Options inherited from parent commands
Expand Down
8 changes: 8 additions & 0 deletions manifest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: 0.1
istio:
- https://storage.googleapis.com/riff-releases/istio/istio-1.0.0-riff-crds.yaml
- https://storage.googleapis.com/riff-releases/istio/istio-1.0.0-riff-main.yaml
knative:
- https://storage.googleapis.com/knative-releases/serving/previous/v20180809-6b01d8e/release-no-mon.yaml
- https://storage.googleapis.com/knative-releases/eventing/previous/v20180809-34ab480/release.yaml
- https://storage.googleapis.com/knative-releases/eventing/previous/v20180809-34ab480/release-clusterbus-stub.yaml
1 change: 1 addition & 0 deletions pkg/core/fixtures/invalid.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.
3 changes: 3 additions & 0 deletions pkg/core/fixtures/noistio.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
version: 0.1
knative:
- serving-release
4 changes: 4 additions & 0 deletions pkg/core/fixtures/noknative.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
version: 0.1
istio:
- istio-crds
- istio-release
8 changes: 8 additions & 0 deletions pkg/core/fixtures/valid.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: 0.1
istio:
- istio-crds
- istio-release
knative:
- serving-release
- eventing-release
- stub-bus-release
1 change: 1 addition & 0 deletions pkg/core/fixtures/wrongversion.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version: 0.0
57 changes: 57 additions & 0 deletions pkg/core/manifest.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright 2018 The original author or 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 core

import (
"fmt"
"gopkg.in/yaml.v2"
"io/ioutil"
)

const MANIFEST_VERSION = "0.1"

// Manifest defines the location of YAML files for system components.
type Manifest struct {
Version string
Istio []string
Knative []string
}

func NewManifest(path string) (*Manifest, error) {
var m Manifest
yamlFile, err := ioutil.ReadFile(path)
if err != nil {
return nil, fmt.Errorf("Error reading manifest file: %v", err)
}

err = yaml.Unmarshal(yamlFile, &m)
if err != nil {
return nil, fmt.Errorf("Error parsing manifest file: %v", err)
}

if m.Version != MANIFEST_VERSION {
return nil, fmt.Errorf("Manifest has unsupported version: %s", m.Version)
}

if m.Istio == nil ||
m.Knative == nil {
return nil, fmt.Errorf("Manifest is incomplete: %#v", m)
}

return &m, nil
}
112 changes: 112 additions & 0 deletions pkg/core/manifest_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*
* Copyright 2018 The original author or 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 core_test

import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/projectriff/riff/pkg/core"
)

var _ = Describe("Manifest", func() {
Describe("NewManifest", func() {

var (
manifestPath string
manifest *core.Manifest
err error
)

JustBeforeEach(func() {
manifest, err = core.NewManifest(manifestPath)
})

Context("when an invalid path is provided", func() {
BeforeEach(func() {
manifestPath = ""
})

It("should return a suitable error", func() {
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(HavePrefix("Error reading manifest file:"))
})
})

Context("when the file contains invalid YAML", func() {
BeforeEach(func() {
manifestPath = "./fixtures/invalid.yaml"
})

It("should return a suitable error", func() {
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(HavePrefix("Error parsing manifest file:"))
})
})

Context("when the manifest has the wrong version", func() {
BeforeEach(func() {
manifestPath = "./fixtures/wrongversion.yaml"
})

It("should return a suitable error", func() {
Expect(err).To(MatchError("Manifest has unsupported version: 0.0"))
})
})

Context("when the manifest does not specify the istio array", func() {
BeforeEach(func() {
manifestPath = "./fixtures/noistio.yaml"
})

It("should return a suitable error", func() {
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(HavePrefix("Manifest is incomplete:"))
})
})

Context("when the manifest does not specify the knative array", func() {
BeforeEach(func() {
manifestPath = "./fixtures/noknative.yaml"
})

It("should return a suitable error", func() {
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(HavePrefix("Manifest is incomplete:"))
})
})

Context("when the manifest is valid", func() {
BeforeEach(func() {
manifestPath = "./fixtures/valid.yaml"
})

It("should return with no error", func() {
Expect(err).NotTo(HaveOccurred())
})

It("should parse the istio array", func() {
Expect(manifest.Istio).To(ConsistOf("istio-crds", "istio-release"))
})

It("should parse the Knative array", func() {
Expect(manifest.Knative).To(ConsistOf("serving-release", "eventing-release", "stub-bus-release"))
})
})
})

})
1 change: 0 additions & 1 deletion pkg/core/mocks/Client.go

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

Loading

0 comments on commit 2fd166b

Please sign in to comment.