Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Populate sigs.k8s.io/json #1

Merged
merged 12 commits into from
Oct 20, 2021
67 changes: 67 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: ci-pipeline
liggitt marked this conversation as resolved.
Show resolved Hide resolved

on:
push:
branches: [ "*" ]
pull_request:
branches: [ "*" ]

jobs:

ci:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
path: src/sigs.k8s.io/json/

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: "1.x"
stable: true

- name: Test
run: |
cd ${GITHUB_WORKSPACE}/src/sigs.k8s.io/json/
make test
- name: Benchmark
run: |
cd ${GITHUB_WORKSPACE}/src/sigs.k8s.io/json/
make benchmark
- name: Vet
run: |
cd ${GITHUB_WORKSPACE}/src/sigs.k8s.io/json/
make vet
- name: fmt
run: |
cd ${GITHUB_WORKSPACE}/src/sigs.k8s.io/json/
make fmt
git diff --exit-code

apidiff:
runs-on: ubuntu-latest
if: github.base_ref
steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: '1.x'
- name: Add GOBIN to PATH
run: echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
- name: Install dependencies
run: go get golang.org/x/exp/cmd/apidiff
- name: Checkout old code
uses: actions/checkout@v2
with:
ref: ${{ github.base_ref }}
path: "old"
- name: Checkout new code
uses: actions/checkout@v2
with:
path: "new"
- name: APIDiff
run: ./hack/verify-apidiff.sh -d ../old
working-directory: "new"


29 changes: 20 additions & 9 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@ Welcome to Kubernetes. We are excited about the prospect of you joining our [com

_As contributors and maintainers of this project, and in the interest of fostering an open and welcoming community, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities._

## Criteria for adding code here

This library adapts the stdlib `encoding/json` decoder to be compatible with
Kubernetes JSON decoding, and is not expected to actively add new features.

It may be updated with changes from the stdlib `encoding/json` decoder.

Any code that is added must:
* Have full unit test and benchmark coverage
* Be backward compatible with the existing exposed go API
* Have zero external dependencies
* Preserve existing benchmark performance
* Preserve compatibility with existing decoding behavior of `Unmarshal()` or `UnmarshalStrict()`
* Avoid use of `unsafe`

## Getting Started

We have full documentation on how to get started contributing here:
Expand All @@ -16,16 +31,12 @@ If your repo has certain guidelines for contribution, put them here ahead of the
- [Kubernetes Contributor Guide](https://git.k8s.io/community/contributors/guide) - Main contributor documentation, or you can just jump directly to the [contributing section](https://git.k8s.io/community/contributors/guide#contributing)
- [Contributor Cheat Sheet](https://git.k8s.io/community/contributors/guide/contributor-cheatsheet) - Common resources for existing developers

## Mentorship
## Community, discussion, contribution, and support

- [Mentoring Initiatives](https://git.k8s.io/community/mentoring) - We have a diverse set of mentorship programs available that are always looking for volunteers!
You can reach the maintainers of this project via the
[sig-api-machinery mailing list / channels](https://github.com/kubernetes/community/tree/master/sig-api-machinery#contact).

<!---
Custom Information - if you're copying this template for the first time you can add custom content here, for example:

## Contact Information
## Mentorship

- [Slack channel](https://kubernetes.slack.com/messages/kubernetes-users) - Replace `kubernetes-users` with your slack channel string, this will send users directly to your channel.
- [Mailing list](URL)
- [Mentoring Initiatives](https://git.k8s.io/community/mentoring) - We have a diverse set of mentorship programs available that are always looking for volunteers!

-->
37 changes: 37 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
Files other than internal/golang/* licensed under:


Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
Expand Down Expand Up @@ -199,3 +202,37 @@
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.


------------------

internal/golang/* files licensed under:


Copyright (c) 2009 The Go Authors. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 changes: 35 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
.PHONY: default build test benchmark fmt vet

default: build

build:
go build ./...

test:
go test sigs.k8s.io/json/...

benchmark:
go test sigs.k8s.io/json -bench . -benchmem

fmt:
go mod tidy
gofmt -s -w *.go

vet:
go vet sigs.k8s.io/json

@echo "checking for external dependencies"
@deps=$$(go mod graph); \
if [ -n "$${deps}" ]; then \
echo "only stdlib dependencies allowed, found:"; \
echo "$${deps}"; \
exit 1; \
fi

@echo "checking for unsafe use"
@unsafe=$$(go list -f '{{.ImportPath}} depends on {{.Imports}}' sigs.k8s.io/json/... | grep unsafe || true); \
if [ -n "$${unsafe}" ]; then \
echo "no dependencies on unsafe allowed, found:"; \
echo "$${unsafe}"; \
exit 1; \
fi
43 changes: 27 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,36 @@
# Kubernetes Template Project
# sigs.k8s.io/json

The Kubernetes Template Project is a template for starting new projects in the GitHub organizations owned by Kubernetes. All Kubernetes projects, at minimum, must have the following files:
[![Go Reference](https://pkg.go.dev/badge/sigs.k8s.io/json.svg)](https://pkg.go.dev/sigs.k8s.io/json)

- a `README.md` outlining the project goals, sponsoring sig, and community contact information
- an `OWNERS` with the project leads listed as approvers ([docs on `OWNERS` files][owners])
- a `CONTRIBUTING.md` outlining how to contribute to the project
- an unmodified copy of `code-of-conduct.md` from this repo, which outlines community behavior and the consequences of breaking the code
- a `LICENSE` which must be Apache 2.0 for code projects, or [Creative Commons 4.0] for documentation repositories, without any custom content
- a `SECURITY_CONTACTS` with the contact points for the Product Security Team
to reach out to for triaging and handling of incoming issues. They must agree to abide by the
[Embargo Policy](https://git.k8s.io/security/private-distributors-list.md#embargo-policy)
and will be removed and replaced if they violate that agreement.
## Introduction

## Community, discussion, contribution, and support
This library is a subproject of [sig-api-machinery](https://github.com/kubernetes/community/tree/master/sig-api-machinery#json).
It provides case-sensitive, integer-preserving JSON unmarshaling functions based on `encoding/json` `Unmarshal()`.

Learn how to engage with the Kubernetes community on the [community page](http://kubernetes.io/community/).
## Compatibility

You can reach the maintainers of this project at:
The `Unmarshal()` function behaves like `encoding/json#Unmarshal()` with the following differences:

- [Slack](http://slack.k8s.io/)
- [Mailing List](https://groups.google.com/forum/#!forum/kubernetes-dev)
- JSON object keys are treated case-sensitively.
Object keys must exactly match json tag names (for tagged struct fields)
or struct field names (for untagged struct fields).
- JSON integers are unmarshaled into `interface{}` fields as an `int64` instead of a
`float64` when possible, falling back to `float64` on any parse or overflow error.
- Syntax errors do not return an `encoding/json` `*SyntaxError` error.
Instead, they return an error which can be passed to `SyntaxErrorOffset()` to obtain an offset.

## Additional capabilities

The `UnmarshalStrict()` function decodes identically to `Unmarshal()`,
and also returns non-fatal strict errors encountered while decoding:

- Duplicate fields encountered
- Unknown fields encountered

### Community, discussion, contribution, and support

You can reach the maintainers of this project via the
[sig-api-machinery mailing list / channels](https://github.com/kubernetes/community/tree/master/sig-api-machinery#contact).

### Code of conduct

Expand Down
9 changes: 0 additions & 9 deletions RELEASE.md

This file was deleted.

17 changes: 17 additions & 0 deletions doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
Copyright 2021 The Kubernetes Authors.

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.
*/

package json // import "sigs.k8s.io/json"
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module sigs.k8s.io/json

go 1.16
Loading