python icon indicating copy to clipboard operation
python copied to clipboard

Not working create_from_yaml

Open renatosazup-zz opened this issue 2 years ago • 1 comments

What happened (please include outputs or screenshots):

kubetest3.py


import yaml
from kubernetes import client,config,utils

config.load_kube_config()
k8s_client = client.ApiClient()

yaml_file = 'src/assets/zap-api-scan.yaml'
utils.create_from_yaml(k8s_client,yaml_file,verbose=True)

zap-api-scan.yaml


# SPDX-FileCopyrightText: the secureCodeBox authors
#
# SPDX-License-Identifier: Apache-2.0

---
apiVersion: v1
kind: ConfigMap
metadata:
  name: zap-advanced-scan-config
data:
  2-zap-advanced-scan.yaml: |-
    # ZAP Contexts Configuration 
        contexts:
          - name: test-context
            url: https://petstore.swagger.io/
            includePaths:
              - "https://petstore.swagger.io*"
            excludePaths:
              - ".*\\.js"
              - ".*\\.css"
              - ".*\\.png"
              - ".*\\.svg"
              - ".*\\.jpeg"
              - ".*\\swagger.json"
            apis:
              - name: scb-petstore-api
                context: test-context
                format: openapi # 'openapi', 'grapql', 'soap'
                url: https://petstore.swagger.io/v2/swagger.json
                hostOverride: https://petstore.swagger.io
            session:
              type: "cookieBasedSessionManagement"
            authentication:
              json-based:
                  loginUrl: "https://petstore.swagger.io/access"
                  loginRequestData: '{"username":"[email protected]","password":"test@"}'
            users:
              - name: test-user-1
                username: "[email protected]"
                password: "test"
                forced: true
            verification:     
              isLoggedInIndicator: "bearer"
              isLoggedOutIndicator: ""

---
apiVersion: "execution.securecodebox.io/v1"
kind: Scan
metadata:
  name: "job-owasp-zap"
  labels:
    organization: "OWASP"
spec:
  scanType: "zap-advanced-scan"
  parameters:
    # target URL including the protocol
    - "-t"
    - "https://petstore.swagger.io"
  volumeMounts:
    - name: zap-advanced-scantype-config-2
      mountPath: /home/securecodebox/configs/2-zap-advanced-scan.yaml
      subPath: 2-zap-advanced-scan.yaml
      readOnly: true
  volumes:
    - name: zap-advanced-scantype-config-2
      configMap:
        name: zap-advanced-scan-config

Output


Traceback (most recent call last):
  File "kubetest3.py", line 10, in <module>
    utils.create_from_yaml(k8s_client,yaml_file,verbose=True)
  File "/home/srburton/.local/lib/python3.6/site-packages/kubernetes/utils/create_from_yaml.py", line 162, in create_from_yaml
    return create_with(yml_document_all)
  File "/home/srburton/.local/lib/python3.6/site-packages/kubernetes/utils/create_from_yaml.py", line 148, in create_with
    **kwargs)
  File "/home/srburton/.local/lib/python3.6/site-packages/kubernetes/utils/create_from_yaml.py", line 217, in create_from_dict
    k8s_client, data, verbose, namespace=namespace, **kwargs)
  File "/home/srburton/.local/lib/python3.6/site-packages/kubernetes/utils/create_from_yaml.py", line 242, in create_from_yaml_single_item
    k8s_api = getattr(client, fcn_to_call)(k8s_client)
AttributeError: module 'kubernetes.client' has no attribute 'ExecutionSecurecodeboxIoV1Api'

What you expected to happen: The job is expected to be created in my cluster.

Environment:

  • Kubernetes version (kubectl version):
{Major:"1", Minor:"22", GitVersion:"v1.22.5", GitCommit:"5c99e2ac2ff9a3c549d9ca665e7bc05a3e18f07e", GitTreeState:"clean", BuildDate:"2021-12-16T08:38:33Z", GoVersion:"go1.16.12", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"21+", GitVersion:"v1.21.13-eks-84b4fe6", GitCommit:"e1318dce57b3e319a2e3fecf343677d1c4d4aa75", GitTreeState:"clean", BuildDate:"2022-06-09T18:22:07Z", GoVersion:"go1.16.15", Compiler:"gc", Platform:"linux/amd64"}
  • Python version (python --version): Python 3.6.9
  • Python client version (pip list | grep kubernetes): Kubernetes (24.2.0)

renatosazup-zz avatar Aug 17 '22 13:08 renatosazup-zz

Hello @renatosazup , given this is a CRD, there are other similar issues open around this, but to be helpful, here is a work around I found in one of the issues, #1792 - work around

venkatalolla avatar Aug 31 '22 22:08 venkatalolla

The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle stale
  • Mark this issue or PR as rotten with /lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

k8s-triage-robot avatar Nov 29 '22 23:11 k8s-triage-robot

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

k8s-triage-robot avatar Dec 29 '22 23:12 k8s-triage-robot

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Reopen this issue with /reopen
  • Mark this issue as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close not-planned

k8s-triage-robot avatar Jan 29 '23 00:01 k8s-triage-robot

@k8s-triage-robot: Closing this issue, marking it as "Not Planned".

In response to this:

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Reopen this issue with /reopen
  • Mark this issue as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close not-planned

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

k8s-ci-robot avatar Jan 29 '23 00:01 k8s-ci-robot