Skip to content
This repository has been archived by the owner on Aug 14, 2020. It is now read-only.

Update appc data structures for CRI #656

Merged
merged 3 commits into from
Sep 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions schema/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ import (
const PodManifestKind = types.ACKind("PodManifest")

type PodManifest struct {
ACVersion types.SemVer `json:"acVersion"`
ACKind types.ACKind `json:"acKind"`
Apps AppList `json:"apps"`
Volumes []types.Volume `json:"volumes"`
Isolators []types.Isolator `json:"isolators"`
Annotations types.Annotations `json:"annotations"`
Ports []types.ExposedPort `json:"ports"`
ACVersion types.SemVer `json:"acVersion"`
ACKind types.ACKind `json:"acKind"`
Apps AppList `json:"apps"`
Volumes []types.Volume `json:"volumes"`
Isolators []types.Isolator `json:"isolators"`
Annotations types.Annotations `json:"annotations"`
Ports []types.ExposedPort `json:"ports"`
CRIAnnotations types.CRIAnnotations `json:"criAnnotations,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@squeed CRIAnnotation and CRILabels sounds too specific for CRI? Why not just using the old Annotations and changing the type of the Key from ACIdentifier to string?
Both Label or Annotation can be muxed into annotations with prefixes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yifan-gu I thought about that, but the appc spec already defines some app annotations with special parsing rules, e.g. 'created'.
If we're going to add a type that allow arbitrary user-specified Kubernetes labels, we can't go adding more meaning to them.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be inline with previous discussion about this at rkt/rkt#3010 (comment)

CRILabels types.CRILabels `json:"criLabels,omitempty"`
}

// podManifest is a model to facilitate extra validation during the
Expand Down
5 changes: 5 additions & 0 deletions schema/types/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ type App struct {
MountPoints []MountPoint `json:"mountPoints,omitempty"`
Ports []Port `json:"ports,omitempty"`
Isolators Isolators `json:"isolators,omitempty"`
CRIAnnotations CRIAnnotations `json:"criAnnotations,omitempty"`
CRILabels CRILabels `json:"criLabels,omitempty"`
}

// app is a model to facilitate extra validation during the
Expand Down Expand Up @@ -89,5 +91,8 @@ func (a *App) assertValid() error {
if err := a.Isolators.assertValid(); err != nil {
return err
}
if err := a.CRILabels.assertValid(); err != nil {
return err
}
return nil
}
23 changes: 23 additions & 0 deletions schema/types/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,29 @@ func TestAppUnmarshal(t *testing.T) {
},
false,
},
{
`{"Exec":["/a"],"User":"0","Group":"0","CRIAnnotations":{"weird!":"normal?"},"CRILabels":{"one":"two"}}`,
&App{
Exec: Exec{
"/a",
},
User: "0",
Group: "0",
Environment: make(Environment, 0),
CRIAnnotations: CRIAnnotations{
"weird!": "normal?",
},
CRILabels: CRILabels{
"one": "two",
},
},
false,
},
{
`{"Exec":["/a"],"User":"0","Group":"0","CRIAnnotations":{"weird!":"normal?"},"CRILabels":{"!one":"two"}}`,
&App{},
true,
},
}
for i, tt := range tests {
a := &App{}
Expand Down
18 changes: 18 additions & 0 deletions schema/types/cri_annotations.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2016 The appc 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 types

// CRIAnnotations are arbitrary key-value pairs
type CRIAnnotations map[string]string
31 changes: 31 additions & 0 deletions schema/types/cri_labels.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2015 The appc 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 types

import "fmt"

type CRILabels map[ACIdentifier]string
Copy link
Contributor

@yifan-gu yifan-gu Sep 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@squeed Why labels keys are not arbitrary strings as well? Today, the labels injected by kubelet is not ACIdentifier compliant.
Although there is a TODO to change that, and they do smell like annotations then labels.


func (l CRILabels) assertValid() error {
for k, _ := range l {
if err := k.assertValid(); err != nil {
return err
}
if len(k) > 63 {
return fmt.Errorf(`label %q too long`, k)
}
}
return nil
}
52 changes: 52 additions & 0 deletions schema/types/cri_labels_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright 2015 The appc 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 types

import "testing"

func TestCRILabelsAssertValid(t *testing.T) {
tests := []struct {
in CRILabels
werr bool
}{
// empty is OK
{
CRILabels{},
false,
},
{
CRILabels{"a": "b"},
false,
},
{
CRILabels{"a!": "b"},
true,
},
{
CRILabels{"/a": "b"},
true,
},
{
CRILabels{"a/a": "b"},
false,
},
}
for i, tt := range tests {
err := tt.in.assertValid()
if gerr := (err != nil); gerr != tt.werr {
t.Errorf("#%d: gerr=%t, want %t (err=%v)", i, gerr, tt.werr, err)
}
}
}
10 changes: 7 additions & 3 deletions schema/types/mountpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,14 @@ import (
"github.com/appc/spec/schema/common"
)

// MountPoint is the application-side manifestation of a Volume.
// The Volume is optional. If missing, the pod-level Volume of the
// same name shall be used
type MountPoint struct {
Name ACName `json:"name"`
Path string `json:"path"`
ReadOnly bool `json:"readOnly,omitempty"`
Name ACName `json:"name"`
Path string `json:"path"`
ReadOnly bool `json:"readOnly,omitempty"`
Volume *Volume `json:"volume,omitempty"`
}

func (mount MountPoint) assertValid() error {
Expand Down
8 changes: 8 additions & 0 deletions schema/types/port.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@ import (
"encoding/json"
"errors"
"fmt"
"net"
"net/url"
"strconv"

"github.com/appc/spec/schema/common"
)

// Port represents a port as offered by an application *inside*
// the pod.
type Port struct {
Name ACName `json:"name"`
Protocol string `json:"protocol"`
Expand All @@ -32,9 +35,14 @@ type Port struct {
SocketActivated bool `json:"socketActivated"`
}

// ExposedPort represents a port listening on the host side.
// The PodPort is optional -- if missing, then try and find the pod-side
// information by matching names
type ExposedPort struct {
Name ACName `json:"name"`
HostPort uint `json:"hostPort"`
HostIP net.IP `json:"hostIP,omitempty"` // optional
PodPort *Port `json:"podPort,omitempty"` // optional. If missing, try and find a corresponding App's port
}

type port Port
Expand Down