diff --git a/api-operator/deploy/sample-definitions/wso2_v1alpha2_api_cr.yaml b/api-operator/deploy/sample-definitions/wso2_v1alpha2_api_cr.yaml index 8006b896..33f316da 100644 --- a/api-operator/deploy/sample-definitions/wso2_v1alpha2_api_cr.yaml +++ b/api-operator/deploy/sample-definitions/wso2_v1alpha2_api_cr.yaml @@ -21,4 +21,4 @@ metadata: spec: swaggerConfigMapName: petstore-cm paramsValues: params-cm - certsValues: certs-cm \ No newline at end of file + certsValues: certs-cm diff --git a/api-operator/deploy/sample-definitions/wso2_v1alpha2_targetendpoint_cr.yaml b/api-operator/deploy/sample-definitions/wso2_v1alpha2_targetendpoint_cr.yaml index e775d548..2c1f9ec6 100644 --- a/api-operator/deploy/sample-definitions/wso2_v1alpha2_targetendpoint_cr.yaml +++ b/api-operator/deploy/sample-definitions/wso2_v1alpha2_targetendpoint_cr.yaml @@ -17,21 +17,22 @@ apiVersion: wso2.com/v1alpha2 kind: TargetEndpoint metadata: - name: products-privatejet + name: products labels: - app: wso2 + app: products-backend spec: applicationProtocol: http ports: - name: prod-ep port: 80 - targetPort: 9090 + targetPort: 8080 deploy: - name: products-pj-service - dockerImage: pubudu/products:1.0.0 + name: products + dockerImage: cakebakery/products:v1 minReplicas: 2 maxReplicas: 3 - requestCPU: "60m" - reqMemory: "32Mi" - cpuLimit: "120m" - mode: privateJet \ No newline at end of file + requestCPU: "2m" + reqMemory: "10Mi" + cpuLimit: "5m" + memoryLimit: "20Mi" + mode: privateJet diff --git a/api-operator/pkg/envoy/constants.go b/api-operator/pkg/envoy/constants.go index af862739..60c4f259 100644 --- a/api-operator/pkg/envoy/constants.go +++ b/api-operator/pkg/envoy/constants.go @@ -39,3 +39,19 @@ const ( apiOperatorConfigHome = "API_OPERATOR_CONFIG_HOME" apiOperatorDefaultConfigHome = "/usr/local/bin" ) + +// constants related to API-CTL project +// TODO: use API-CTL code to init project +const ( + apiYamlFile = "api.yaml" + swaggerDefinitionFile = "Definitions/swagger.yaml" + deploymentEnvFile = "deployment_environments.yaml" + // TODO: use API-CTL code to init project + deploymentEnvFileData = `type: deployment_environments +version: v4.0.0 +data: + - + displayOnDevportal: true + deploymentEnvironment: Default +` +) diff --git a/api-operator/pkg/envoy/utils.go b/api-operator/pkg/envoy/utils.go index abaf3f75..5139c37f 100644 --- a/api-operator/pkg/envoy/utils.go +++ b/api-operator/pkg/envoy/utils.go @@ -231,8 +231,9 @@ func getSwaggerData(config *corev1.ConfigMap) (string, func(), error) { } swaggerDirectory, _ := ioutil.TempDir("", "api-swagger-dir*") - apiYamlPath := filepath.Join(swaggerDirectory, filepath.FromSlash("api.yaml")) - swaggerSavePath := filepath.Join(swaggerDirectory, filepath.FromSlash("Definitions/swagger.yaml")) + apiYamlPath := filepath.Join(swaggerDirectory, filepath.FromSlash(apiYamlFile)) + swaggerSavePath := filepath.Join(swaggerDirectory, filepath.FromSlash(swaggerDefinitionFile)) + deploymentEnvPath := filepath.Join(swaggerDirectory, filepath.FromSlash(deploymentEnvFile)) errCreateDirectory := createDirectories(swaggerDirectory) if errCreateDirectory != nil { return "", nil, errCreateDirectory @@ -245,6 +246,10 @@ func getSwaggerData(config *corev1.ConfigMap) (string, func(), error) { if err != nil { return "", nil, err } + err = ioutil.WriteFile(deploymentEnvPath, []byte(deploymentEnvFileData), os.ModePerm) + if err != nil { + return "", nil, err + } swaggerZipFile, err, cleanupFunc := utils.CreateZipFileFromProject(swaggerDirectory, false) if err != nil { return "", nil, err diff --git a/operatorhub-resources/api-operator/2.0.0/api-operator.v2.0.0.clusterserviceversion.yaml b/operatorhub-resources/api-operator/2.0.0/api-operator.v2.0.0.clusterserviceversion.yaml index ef2ec5ca..cd6ad2ce 100644 --- a/operatorhub-resources/api-operator/2.0.0/api-operator.v2.0.0.clusterserviceversion.yaml +++ b/operatorhub-resources/api-operator/2.0.0/api-operator.v2.0.0.clusterserviceversion.yaml @@ -192,19 +192,7 @@ spec: requests: cpu: 250m memory: 250Mi - volumeMounts: - - mountPath: /home/wso2/security/ - name: operator-vol serviceAccountName: api-operator - volumes: - - name: operator-vol - secret: - items: - - key: tls.key - path: tls.key - - key: tls.crt - path: tls.crt - secretName: operator-secret permissions: - rules: - apiGroups: @@ -340,7 +328,7 @@ spec: maintainers: - email: announce@wso2.org name: WSO2 product releases - maturity: 2.x-stable + maturity: stable provider: name: WSO2 version: 2.0.0 diff --git a/operatorhub-resources/api-operator/api-operator.package.yaml b/operatorhub-resources/api-operator/api-operator.package.yaml index cd0e3a88..161aacc3 100755 --- a/operatorhub-resources/api-operator/api-operator.package.yaml +++ b/operatorhub-resources/api-operator/api-operator.package.yaml @@ -16,7 +16,7 @@ packageName: api-operator channels: - - name: stable + - name: 1.x-stable currentCSV: api-operator.v1.2.2 - name: 2.x-stable currentCSV: api-operator.v2.0.0 diff --git a/scenarios/scenario-1-target-endpoint/api_cr.yaml b/scenarios/scenario-1-target-endpoint/api_cr.yaml new file mode 100644 index 00000000..07484be7 --- /dev/null +++ b/scenarios/scenario-1-target-endpoint/api_cr.yaml @@ -0,0 +1,22 @@ +# Copyright (c) 2021 WSO2 Inc. (http:www.wso2.org) All Rights Reserved. +# +# WSO2 Inc. licenses this file to you 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. + +apiVersion: wso2.com/v1alpha2 +kind: API +metadata: + name: products-api +spec: + swaggerConfigMapName: products-cm diff --git a/scenarios/scenario-1-target-endpoint/swagger.yaml b/scenarios/scenario-1-target-endpoint/swagger.yaml new file mode 100644 index 00000000..5ffaee0a --- /dev/null +++ b/scenarios/scenario-1-target-endpoint/swagger.yaml @@ -0,0 +1,184 @@ +# Copyright (c) 2021 WSO2 Inc. (http:www.wso2.org) All Rights Reserved. +# +# WSO2 Inc. licenses this file to you 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. + +openapi: 3.0.0 +servers: + - description: Localhost + url: http://localhost:8080 +info: + description: This is a sample backend - products + version: v1 + title: Products + contact: + email: renukapiyumal@gmail.com +tags: + - name: product + description: Products of store +x-wso2-production-endpoints: + urls: + - http://products + type: http +x-wso2-sandbox-endpoints: + urls: + - http://products + type: http +x-wso2-basePath: /products-api/v1 +paths: + /products: + get: + tags: + - product + summary: All Products + description: All products of the store + responses: + 200: + description: Successful operation + content: + application/json: + schema: + type: array + items: + $ref: "#/components/schemas/Product" + post: + tags: + - product + summary: Add Product + description: Add new products to the store + requestBody: + content: + applicatoin/json: + schema: + $ref: "#/components/schemas/Product" + + responses: + 200: + description: Successful operation + content: + application/json: + schema: + $ref: "#/components/schemas/Product" + 400: + description: Invalid Product + /products/{id}: + get: + tags: + - product + summary: Find product by ID + description: Returns a single product + parameters: + - name: id + in: path + description: ID of product to return + required: true + schema: + type: integer + format: int64 + example: 3 + responses: + 200: + description: successful operation + content: + application/json: + schema: + $ref: "#/components/schemas/Product" + 400: + description: Invalid ID supplied + 404: + description: Product not found + put: + tags: + - product + summary: Update product by ID + description: Update a product + parameters: + - name: id + in: path + description: ID of product to update + required: true + schema: + type: integer + format: int64 + example: 3 + requestBody: + content: + applicatoin/json: + schema: + $ref: "#/components/schemas/Product" + responses: + 200: + description: successful operation + content: + application/json: + schema: + $ref: "#/components/schemas/Product" + 400: + description: Invalid ID supplied + 404: + description: Product not found + delete: + tags: + - product + summary: Delete product by ID + description: Delete a product + parameters: + - name: id + in: path + description: ID of product to delete + required: true + schema: + type: integer + format: int64 + example: 3 + responses: + 200: + description: successful operation + content: + application/json: + schema: + $ref: "#/components/schemas/Result" + 400: + description: Invalid ID supplied + 404: + description: Product not found +components: + schemas: + Product: + type: object + required: + - name + - category + - price + properties: + id: + type: integer + format: int64 + example: 3 + name: + type: string + example: ABC Smart TV + category: + type: string + example: Electronics + price: + type: integer + format: int64 + example: 39999 + Result: + type: object + properties: + result: + type: string + example: success diff --git a/scenarios/scenario-1-target-endpoint/targetendpoint_cr.yaml b/scenarios/scenario-1-target-endpoint/targetendpoint_cr.yaml new file mode 100644 index 00000000..2c1f9ec6 --- /dev/null +++ b/scenarios/scenario-1-target-endpoint/targetendpoint_cr.yaml @@ -0,0 +1,38 @@ +# Copyright (c) 2021 WSO2 Inc. (http:www.wso2.org) All Rights Reserved. +# +# WSO2 Inc. licenses this file to you 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. + +apiVersion: wso2.com/v1alpha2 +kind: TargetEndpoint +metadata: + name: products + labels: + app: products-backend +spec: + applicationProtocol: http + ports: + - name: prod-ep + port: 80 + targetPort: 8080 + deploy: + name: products + dockerImage: cakebakery/products:v1 + minReplicas: 2 + maxReplicas: 3 + requestCPU: "2m" + reqMemory: "10Mi" + cpuLimit: "5m" + memoryLimit: "20Mi" + mode: privateJet diff --git a/scenarios/scenario-2-endpoint-cert-override/api_cr.yaml b/scenarios/scenario-2-endpoint-cert-override/api_cr.yaml new file mode 100644 index 00000000..c7d9c783 --- /dev/null +++ b/scenarios/scenario-2-endpoint-cert-override/api_cr.yaml @@ -0,0 +1,24 @@ +# Copyright (c) 2021 WSO2 Inc. (http:www.wso2.org) All Rights Reserved. +# +# WSO2 Inc. licenses this file to you 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. + +apiVersion: wso2.com/v1alpha2 +kind: API +metadata: + name: cert-products +spec: + certsValues: cert-products-certs + paramsValues: cert-products-params + swaggerConfigMapName: cert-products-cm diff --git a/scenarios/scenario-2-endpoint-cert-override/params_cm.yaml b/scenarios/scenario-2-endpoint-cert-override/params_cm.yaml new file mode 100644 index 00000000..1b29a6ce --- /dev/null +++ b/scenarios/scenario-2-endpoint-cert-override/params_cm.yaml @@ -0,0 +1,34 @@ +# Copyright (c) 2021 WSO2 Inc. (http:www.wso2.org) All Rights Reserved. +# +# WSO2 Inc. licenses this file to you 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. + +apiVersion: v1 +kind: ConfigMap +metadata: + name: cert-products-params +data: + params.yaml: | + environments: + - name: production + configs: + endpoints: + production: + url: https://products-certs + sandbox: + url: https://products-certs + certs: + - hostName: products-certs + alias: products-certs + path: products-certs.crt diff --git a/scenarios/scenario-2-endpoint-cert-override/swagger.yaml b/scenarios/scenario-2-endpoint-cert-override/swagger.yaml new file mode 100644 index 00000000..ea4a4925 --- /dev/null +++ b/scenarios/scenario-2-endpoint-cert-override/swagger.yaml @@ -0,0 +1,184 @@ +# Copyright (c) 2021 WSO2 Inc. (http:www.wso2.org) All Rights Reserved. +# +# WSO2 Inc. licenses this file to you 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. + +openapi: 3.0.0 +servers: + - description: Localhost + url: http://localhost:8443 +info: + description: This is a sample backend - products + version: v1 + title: Cert-Products + contact: + email: renukapiyumal@gmail.com +tags: + - name: product + description: Products of store +x-wso2-production-endpoints: + urls: + - https://products + type: http +x-wso2-sandbox-endpoints: + urls: + - https://products + type: http +x-wso2-basePath: /cert-products-api/v1 +paths: + /products: + get: + tags: + - product + summary: All Products + description: All products of the store + responses: + 200: + description: Successful operation + content: + application/json: + schema: + type: array + items: + $ref: "#/components/schemas/Product" + post: + tags: + - product + summary: Add Product + description: Add new products to the store + requestBody: + content: + applicatoin/json: + schema: + $ref: "#/components/schemas/Product" + + responses: + 200: + description: Successful operation + content: + application/json: + schema: + $ref: "#/components/schemas/Product" + 400: + description: Invalid Product + /products/{id}: + get: + tags: + - product + summary: Find product by ID + description: Returns a single product + parameters: + - name: id + in: path + description: ID of product to return + required: true + schema: + type: integer + format: int64 + example: 3 + responses: + 200: + description: successful operation + content: + application/json: + schema: + $ref: "#/components/schemas/Product" + 400: + description: Invalid ID supplied + 404: + description: Product not found + put: + tags: + - product + summary: Update product by ID + description: Update a product + parameters: + - name: id + in: path + description: ID of product to update + required: true + schema: + type: integer + format: int64 + example: 3 + requestBody: + content: + applicatoin/json: + schema: + $ref: "#/components/schemas/Product" + responses: + 200: + description: successful operation + content: + application/json: + schema: + $ref: "#/components/schemas/Product" + 400: + description: Invalid ID supplied + 404: + description: Product not found + delete: + tags: + - product + summary: Delete product by ID + description: Delete a product + parameters: + - name: id + in: path + description: ID of product to delete + required: true + schema: + type: integer + format: int64 + example: 3 + responses: + 200: + description: successful operation + content: + application/json: + schema: + $ref: "#/components/schemas/Result" + 400: + description: Invalid ID supplied + 404: + description: Product not found +components: + schemas: + Product: + type: object + required: + - name + - category + - price + properties: + id: + type: integer + format: int64 + example: 3 + name: + type: string + example: ABC Smart TV + category: + type: string + example: Electronics + price: + type: integer + format: int64 + example: 39999 + Result: + type: object + properties: + result: + type: string + example: success