-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Knative Serving Deployment (#454)
* This adds the experimental flag `--knative`. The purpose of this flag is to make deploying a Knative Serving Service easy. Since this is experimental, it can change without a major version bump * For a deploy, the first part(build) is unchanged, the "apply-resource" part, which is the second phase of a nodeshift deploy, has been updated to only create a knative serving service that points to the image that was just built in the first step. * If an application has a .nodeshift directory with resource files that are not related to knative, they are ignored
- Loading branch information
1 parent
fca4ad8
commit 88eed5d
Showing
20 changed files
with
1,960 additions
and
1,733 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* | ||
* Copyright 2016-2017 Red Hat, Inc, and individual contributors. | ||
* | ||
* 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. | ||
* | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const log = require('./common-log')(); | ||
const { awaitRequest } = require('./helpers'); | ||
|
||
module.exports = async function getKnativeServingServices (config, resource) { | ||
const knativeService = await awaitRequest(config.openshiftRestClient.apis['serving.knative.dev'].v1.ns(config.namespace.name).service(resource.metadata.name).get()); | ||
|
||
if (knativeService.code === 404) { | ||
// There isn't a service yet, so we need to create one | ||
log.info(`creating new service ${resource.metadata.name}`); | ||
return config.openshiftRestClient.apis['serving.knative.dev'].v1.ns(config.namespace.name).service.post({ body: resource }); | ||
} | ||
|
||
log.info(`using existing service ${knativeService.body.metadata.name}`); | ||
return knativeService; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[ | ||
"knative-serving-service" | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* | ||
* Copyright 2016-2017 Red Hat, Inc, and individual contributors. | ||
* | ||
* 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. | ||
* | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const _ = require('lodash'); | ||
const objectMetadata = require('../definitions/object-metadata'); | ||
|
||
const baseServiceConfig = { | ||
apiVersion: 'serving.knative.dev/v1', | ||
kind: 'Service', | ||
spec: {} // Should be populated in the resource coming in | ||
}; | ||
|
||
// Returns a default knative serving service. | ||
function defaultService (config) { | ||
const serviceConfig = _.merge({}, baseServiceConfig); | ||
|
||
// Apply MetaData | ||
serviceConfig.metadata = objectMetadata({ | ||
name: config.projectName, | ||
namespace: config.namespace.name | ||
}); | ||
|
||
// TODO(lholmquist): Should this also take into account docker images that are not in the openshift registry | ||
serviceConfig.spec.template = { | ||
spec: { | ||
containers: [ | ||
{ | ||
image: `image-registry.openshift-image-registry.svc:5000/${config.namespace.name}/${config.projectName}` | ||
} | ||
] | ||
} | ||
}; | ||
|
||
return serviceConfig; | ||
} | ||
|
||
async function createKnativeServingService (config, resourceList) { | ||
// First check to see if we have a Service | ||
// TODO(lholmquist): Probably should check that this is a knative service not a normal service | ||
// This might be a little tricky since we would have to check the apiVersion and at this point, | ||
// we might not have it yet, there might be some updates needed in the resource loader. | ||
// This should also be done in the service-enricher | ||
if (_.filter(resourceList, { kind: 'Service' }).length < 1) { | ||
// create the default service and add in to the resource list | ||
resourceList.push(defaultService(config)); | ||
return resourceList; | ||
} | ||
|
||
// If there is one, then just do this | ||
return resourceList.map((resource) => { | ||
if (resource.kind !== 'Service') { | ||
return resource; | ||
} | ||
// Merge the default Service Config with the current resource | ||
return _.merge({}, defaultService(config), resource); | ||
}); | ||
} | ||
|
||
module.exports = { | ||
enrich: createKnativeServingService, | ||
name: 'knative-serving-service' | ||
}; | ||
|
||
// apiVersion: serving.knative.dev/v1alpha1 | ||
// kind: Service | ||
// metadata: | ||
// name: helloworld-nodejs | ||
// namespace: fun-times | ||
// spec: | ||
// template: | ||
// spec: | ||
// containers: | ||
// - image: image-registry.openshift-image-registry.svc:5000/fun-times/nodejs-rest-http |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.