Problem with k8s reading keys "ValueError: Could not deserialize key data." - kubernetes

I have deployed app on GKE private cluster, and i have backend service, but the problem is that the backend service cant read the GOOGLE_ACCOUNT_PRIVATE_KEY, I am getting the following error:
line 1526, in _handle_key_loading_error
raise ValueError("Could not deserialize key data.")
ValueError: Could not deserialize key data.
This is part of the backend deployment where this env is found:
env:
- name: GOOGLE_ACCOUNT_PRIVATE_KEY
valueFrom:
configMapKeyRef:
name: gapk
key: GOOGLE_ACCOUNT_PRIVATE_KEY
I have also other env that are successfully and i don't have any error for them
This is how i keep the GOOGLE_ACCOUNT_PRIVATE_KEY env:
apiVersion: v1
kind: ConfigMap
metadata:
name: gapk
data:
GOOGLE_ACCOUNT_PRIVATE_KEY: '-----BEGIN PRIVATE KEY-----\private key\n-----END PRIVATE KEY-----\n'
with " " instead of ' ' is interpreted \n like new row but when i put the key in ' ' I have the serialize error, in both ways i got it wrong :(
Am I doing some mistake while decoding, also i put the original value of the key, not encoded in base64, and still getting the error ValueError: Could not deserialize key data.

Have you tried replacing \n with \\n?
The other thing to try is just to remove the \ns and insert real newlines over mulitple lines. So long as the string is quoted it should be fine. The other thing to try is to remove the trailing newline since private key regex's not always consistent on this one.

Related

Invalid label selector for kubernetes.core.k8s_info ansible inside operator

I am trying to filter out the the deployments which are not of my current version using ansible.
- name: Filter and get old deployment
kubernetes.core.k8s_info:
api_version: v1
kind: Deployment
namespace: "my_namespace"
label_selectors:
- curr_version notin (1.1.0)
register: old_deployments
Expected the output to give the list of deployments not having curr_version equal to 1.1.0
But I am getting this error
{"level":"error","ts":1665557104.5018141,"logger":"proxy","msg":"Unable to convert label selectors for the client","error":"invalid selector: [curr_version notin (1.1.0)]","stacktrace":"net/http.serverHandler.ServeHTTP\n\t/usr/lib/golang/src/net/http/server.go:2879\nnet/http.(*conn).serve\n\t/usr/lib/golang/src/net/http/server.go:1930"}
I referenced the pattern matching from here - https://github.com/abikouo/kubernetes.core/blob/08596fd05ba7190a04e7112270a38a0ce32095dd/plugins/module_utils/selector.py#L39
According to the pattern the above selector looks fine.
Even I tried to change the selector line as this (for testing purpose) -
- curr_version notin ("1.1.0")
But getting error as below.
{"level":"error","ts":1665555657.2939646,"logger":"requestfactory","msg":"Could not parse request","error":"unable to parse requirement: values[0][curr_version]: Invalid value: \"\\\"1.1.0\\\"\": a valid label must be an empty string or consist of alphanumeric characters, '-', '_' or '.', and must start and end with an alphanumeric character (e.g. 'MyValue', or 'my_value', or '12345', regex used for validation is '(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?')","stacktrace":"net/http.serverHandler.ServeHTTP\n\t/usr/lib/golang/src/net/http/server.go:2879\nnet/http.(*conn).serve\n\t/usr/lib/golang/src/net/http/server.go:1930"}
{"level":"error","ts":1665555657.2940943,"logger":"proxy","msg":"Unable to convert label selectors for the client","error":"invalid selector: [curr_version notin (\"1.1.0\")]","stacktrace":"net/http.serverHandler.ServeHTTP\n\t/usr/lib/golang/src/net/http/server.go:2879\nnet/http.(*conn).serve\n\t/usr/lib/golang/src/net/http/server.go:1930"}
I am not sure where am I wrong. I tried to find out the possible workaround but was not able to find it anywhere.
Although I am guessing second issue is just because the label selector is a string and the pattern doesn't allows to have quotes in the string. Which is understood.
Other information which might be useful
kubernetes.core.k8s version - 2.2.3
operator-sdk version - 1.23.0
ansible version - 2.9.27
python - 3.6.8
EDIT
I am using ose-ansible-operator image v4.10 to build an operator. I am unable to see the same error in local. But I am able to when going to operator.

Passing list object into configMap data section

I want to pass a list object in the data section of configMap in application YAML file.
I have the following list in the properties file:
abc.management.provider[0].url=https://example.com
abc.management.provider[0].username=John
abc.management.provider[1].url=https://example2.com
abc.management.provider[1].username=Targerian
YAML file:
data:
abc_management:
provider:
- url: "https://example.com"
username: "John"
- url: "https://example2.com"
username: "Targerian"
I'm getting this error: ConfigMap in version "v1" cannot be handled as a ConfigMap: v1.ConfigMap: Data: ReadString: expects " or n,.
what should I do?
what should I do?
This mostly depends on how your application reads the configuration.
If it works for you, you an create the ConfigMap directly with your properties-file:
kubectl create configmap app-config --from-file=app.properties
I think this question points to what the nature of a ConfigMap object is. Under the hood, it seems ConfigMaps do not explicitly handle lists, so in the end it just depends on how you read that content.
The data field is designed to contain UTF-8 byte sequences ...
Each key under the data or the binaryData field must consist of
alphanumeric characters, -, _ or .. The keys stored in data must not
overlap with the keys in the binaryData field.
https://kubernetes.io/docs/concepts/configuration/configmap/#configmap-object

Invalid characters were found in group names but not replaced ansible k8s

My k8s.yaml inventory file is:
plugin: k8s
connections:
- kubeconfig: '/Users/user1/Documents/Learning/ansible/kubeconfig.test.yaml'
context: 'user1#testeks.us-east-1.eksctl.io'
ansible playbook:
test_new.yml
- hosts: localhost
tasks:
- name: Create a k8s namespace
k8s:
name: testing3
api_version: v1
kind: Namespace
state: present
Looks like the ansibleplaybook command is not picking up the inventory k8s.yaml.Also I am not sure why I am getting Warning invalid characters {'-' in group name warnings.
Please let me know if the above inventory file and ansible playbook files look good or are there anything I am missing?
ansible-playbook -vvvv -i k8s.yaml -vvv ./test_new.yml
No config file found; using defaults
setting up inventory plugins
host_list declined parsing /Users/user1/Documents/Learning/ansible/k8s.yaml as it did not pass its verify_file() method
script declined parsing /Users/user1/Documents/Learning/ansible/k8s.yaml as it did not pass its verify_file() method
Not replacing invalid character(s) "{'-', '9'}" in group name (909676E2B4F81625BF5994625D3353C9-yl4-us-east-1-eks-amazonaws-com)
[WARNING]: Invalid characters were found in group names but not replaced, use -vvvv to see details
Not replacing invalid character(s) "{'-'}" in group name (namespace_add-ons)
Not replacing invalid character(s) "{'-'}" in group name (namespace_add-ons_pods)
Not replacing invalid character(s) "{'.', '/', '-'}" in group name (label_app.kubernetes.io/instance_aws-cluster-autoscaler)
I'm not sure where you got that you need the Kubernetes parameters specified in your inventory file. If you look at the k8s module documentation it says that kubeconfig and context are specified in the playbook or as environment variables.
Your inventory should look something like this:
all:
hosts:
host.where.can.access.the.kubeapiserver.com:
Then your playbook:
- name: Create a k8s namespace
k8s:
name: testing3
api_version: v1
kind: Namespace
state: present
kubeconfig: '/Users/user1/Documents/Learning/ansible/kubeconfig.test.yaml' 👈 this can replaced by the K8S_AUTH_KUBECONFIG env variable
context: 'user1#testeks.us-east-1.eksctl.io' 👈 this can replaced by the K8S_AUTH_CONTEXT env variable
Based on the formatting of your post, it looks like your inventory file contains improper syntax. It should look like this:
plugin: k8s
connections:
- kubeconfig: '/Users/user1/Documents/Learning/ansible/kubeconfig.test.yaml'
context: 'user1#testeks.us-east-1.eksctl.io'
Remember that spaces are important.
For deprecation warnings, be sure to read up on these issues:
https://github.com/ansible/ansible/issues/56930
https://github.com/kubernetes-sigs/kubespray/issues/4830
Usage of hyphens in inventory group names was deprecated in Ansible 2.8 due to Python parser errors when using dot syntax. Auto-transformation can be disabled by adding force_valid_group_names = never to your Ansible config file. Similarly, deprecation warnings can be suppressed by adding deprecation_warnings = False though this is not recommended.

Is there any placeholder notation in mta.yaml that removes spaces from the CF org name parameter?

We are using mta to structure our application and deploying it using the SAP Cloud SDK Pipeline and Transport Management landscape.
In the mta.yaml, we are referencing the org (organization) parameter value using the placeholder notation ${org}.
The issue is that the org name contains spaces between the characters (viz. Sample Org Name) and that is causing error during the application deployment to Cloud Foundry.
We do not want to rename the org name.
Is there any other placeholder notation that removes the spaces between the characters?
We have observed that ${default-host} removes the spaces from the organization name but its scope is limited to only modules and not resources.
We need the substitution variable in the resources scope.
Appreciate if someone can help us here to resolve the issue.
Please find snippet of the mta.yaml and the error message.
resources:
- name: uaa_test_app
parameters:
path: ./xs-security.json
service-plan: application
service: xsuaa
config:
xsappname: 'test-app-${org}-${space}'
type: org.cloudfoundry.managed-service
Error Message:
Service operation failed: Controller operation failed: 502 Updating service "uaa_test_app" failed: Bad Gateway: Service broker error: Service broker xsuaa failed with: org.springframework.cloud.servicebroker.exception.ServiceBrokerException: Error updating application null (Error parsing xs-security.json data: Inconsistent xs-security.json: Invalid xsappname "Test-App-Sample Org Name-test": May only include characters 'a'-'z', 'A'-'Z', '0'-'9', '_', '-', '', and '/'.)

Bluemix cf push error with manifest: expected services to be a list of strings

I'm trying to push an app to Bluemix on a Linux OS. However, the command line returns an error involving the manifest file:
Error reading manifest file:
Expected services to be a list of strings.
Here is the code for the manifest file:
applications:
- name: IdeaSocial
memory: 1024M
instances: 1
host: IdeaSocial
domain: mybluemix.net
path: .
services:
-SQL Database-v5
How do I fix this? Is there a form that the file needs to be in for the current version of Bluemix?
Add quotes around SQL Database-v5 to have it treated as a single string even though there is a space in it. Spaces matter in YAML.
...
services:
- "SQL Database-v5"
The documentation has more information and examples.