GithubHelp home page GithubHelp logo

vijaykpin / copper Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cloud66-oss/copper

0.0 0.0 0.0 4.39 MB

A configuration file validator for Kubernetes.

Home Page: https://help.cloud66.com/copper/

License: Apache License 2.0

Shell 5.62% Go 43.78% JavaScript 50.60%

copper's Introduction

Copper

Copper is a simple tool for validate your configuration files. This is specifically useful with Kubernetes configuration files to enforce best practices, apply policies and compliance requirements.

NOTE: This is Copper v2.0 which is a rewrite of Copper v1.0 (and not an in-place upgrade). Copper v2.0 uses Javascript as it's scripting language instead of Copper v1.0's custom DSL. At the moment, we don't offer any upgrades for old Copper v1 scripts to Copper v2.

Copper Logo

Installation

Head to the releases section of this repository and download the latest version of Copper. You can update Copper using copper update command at any time. By default, you will be running the stable releases. To change the channel, you can use the --channel argument in copper update.

Usage

copper validate --in samples/sample.yml --validator samples/no_latest.js

This will run no_latest.js script to validate sample.yml (both available in this repository).

Copper supports YAML configuration files. By default, it loads the entire input YAML file into the $$ variable that's available to your scripts. Each section of your YAML file is one item in the $$ array.

Here is an example on how to stop using latest as the image tag.

$$.forEach(function($){
    if ($.kind === 'Deployment') {
        $.spec.template.spec.containers.forEach(function(container) {
            var image = new DockerImage(container.image);
            if (image.tag === 'latest') {
                errors.add_error('no_latest',"latest is used in " + $.metadata.name, 1)
            }
        });
    }
});

As you can see, for each section in the YAML, we check if the item is a Deployment, if it is use one of Copper's internal helper classes DocerkImage to load the image name and parse it. DockerImage understands the intricacies of Docker image names (default tag names, default repos, etc). If the tag is latest we push an error into the errors list.

Once our script has run, Copper will check errors for any errors.

Each validation error should have 3 attributes: check_name: The name of the check we just performed title: Some explanation about this error severity: A numerical representation of the severity of this error.

You can set the maximum allowed severity when running Copper using the --threshold argument.

Helpers

To see what helpers are available for you to use in your scripts, see the files in the libjs folder in the repository. All these files are loaded before your script is run and therefore are available to use within your scripts.

copper's People

Contributors

amitsaha avatar kasia66 avatar khash avatar lvangool avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.