Skip to content

Commit

Permalink
feat: update naming conventions for resources and types
Browse files Browse the repository at this point in the history
Rename 'core' resources to 'meta' (including namespace), introduce new
naming concept:

* internal type name should be `CamelCases.some.cosi.dev`
* resource definition id is `camelecases.some.cosi.dev`
* displayed type name is `CamelCase`
* type aliases are `camelcase`, `camelcases`, `cc`, `ccs`

Signed-off-by: Andrey Smirnov <smirnov.andrey@gmail.com>
  • Loading branch information
smira authored and talos-bot committed Mar 2, 2021
1 parent 28dd9aa commit 8b3f192
Show file tree
Hide file tree
Showing 16 changed files with 325 additions and 134 deletions.
3 changes: 2 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT.
#
# Generated on 2020-12-30T20:27:21Z by kres latest.
# Generated on 2021-03-01T18:00:23Z by kres latest.


# options for analysis running
Expand Down Expand Up @@ -128,6 +128,7 @@ linters:
- wrapcheck
- paralleltest
- exhaustivestruct
- forbidigo
disable-all: false
fast: false

Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT.
#
# Generated on 2020-12-30T20:27:21Z by kres latest.
# Generated on 2021-03-01T18:00:23Z by kres latest.

ARG TOOLCHAIN

Expand All @@ -24,7 +24,7 @@ FROM toolchain AS tools
ENV GO111MODULE on
ENV CGO_ENABLED 0
ENV GOPATH /go
RUN curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b /bin v1.33.0
RUN curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b /bin v1.36.0
ARG GOFUMPT_VERSION
RUN cd $(mktemp -d) \
&& go mod init tmp \
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.14
require (
github.com/AlekSi/pointer v1.1.0
github.com/cenkalti/backoff/v4 v4.1.0
github.com/gertd/go-pluralize v0.1.7
github.com/hashicorp/go-memdb v1.3.0
github.com/stretchr/testify v1.6.1
github.com/talos-systems/go-retry v0.2.0
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ github.com/cenkalti/backoff/v4 v4.1.0 h1:c8LkOFQTzuO0WBM/ae5HdGQuZPfPxp7lqBRwQRm
github.com/cenkalti/backoff/v4 v4.1.0/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gertd/go-pluralize v0.1.7 h1:RgvJTJ5W7olOoAks97BOwOlekBFsLEyh00W48Z6ZEZY=
github.com/gertd/go-pluralize v0.1.7/go.mod h1:O4eNeeIf91MHh1GJ2I47DNtaesm66NYvjYgAahcqSDQ=
github.com/hashicorp/go-immutable-radix v1.3.0 h1:8exGP7ego3OmkfksihtSouGMZ+hQrhxx+FVELeXpVPE=
github.com/hashicorp/go-immutable-radix v1.3.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
github.com/hashicorp/go-memdb v1.3.0 h1:xdXq34gBOMEloa9rlGStLxmfX/dyIK8htOv36dQUwHU=
Expand All @@ -18,6 +20,8 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand Down
18 changes: 9 additions & 9 deletions pkg/controller/runtime/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ func (adapter *adapter) UpdateDependencies(deps []controller.Dependency) error {
break
}

add := false
delete := false
shouldAdd := false
shouldDelete := false

switch {
case i >= len(deps):
delete = true
shouldDelete = true
case j >= len(dbDeps):
add = true
shouldAdd = true
default:
dI := deps[i]
dJ := dbDeps[j]
Expand All @@ -84,15 +84,15 @@ func (adapter *adapter) UpdateDependencies(deps []controller.Dependency) error {
i++
j++
case dependency.EqualKeys(&dI, &dJ):
add, delete = true, true
shouldAdd, shouldDelete = true, true
case dependency.Less(&dI, &dJ):
add = true
shouldAdd = true
default:
delete = true
shouldDelete = true
}
}

if add {
if shouldAdd {
if err := adapter.runtime.depDB.AddControllerDependency(adapter.name, deps[i]); err != nil {
return fmt.Errorf("error adding controller dependency: %w", err)
}
Expand All @@ -104,7 +104,7 @@ func (adapter *adapter) UpdateDependencies(deps []controller.Dependency) error {
i++
}

if delete {
if shouldDelete {
if err := adapter.runtime.depDB.DeleteControllerDependency(adapter.name, dbDeps[j]); err != nil {
return fmt.Errorf("error deleting controller dependency: %w", err)
}
Expand Down
76 changes: 0 additions & 76 deletions pkg/resource/core/resource_definition.go

This file was deleted.

8 changes: 4 additions & 4 deletions pkg/resource/core/core.go → pkg/resource/meta/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

// Package core provides definition of core system resources.
package core
// Package meta provides definition of core metadata resources.
package meta

import "github.com/talos-systems/os-runtime/pkg/resource"

// NamespaceName is the name of 'core' namespace.
const NamespaceName resource.Namespace = "core"
// NamespaceName is the name of 'meta' namespace.
const NamespaceName resource.Namespace = "meta"
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

package core
package meta

import (
"fmt"
Expand All @@ -11,7 +11,7 @@ import (
)

// NamespaceType is the type of Namespace.
const NamespaceType = resource.Type("core/namespace")
const NamespaceType = resource.Type("Namespaces.meta.cosi.dev")

// Namespace provides metadata about namespaces.
type Namespace struct {
Expand All @@ -21,9 +21,7 @@ type Namespace struct {

// NamespaceSpec provides Namespace definition.
type NamespaceSpec struct {
Description string `yaml:"description"`
System bool `yaml:"system"`
UserWritable bool `yaml:"userWritable"`
Description string `yaml:"description"`
}

// NewNamespace initializes a Namespace resource.
Expand Down Expand Up @@ -64,7 +62,7 @@ func (r *Namespace) DeepCopy() resource.Resource {
func (r *Namespace) ResourceDefinition() ResourceDefinitionSpec {
return ResourceDefinitionSpec{
Type: NamespaceType,
Aliases: []resource.Type{"namespace", "namespaces", "ns"},
DefaultNamespace: NamespaceName,
Aliases: []resource.Type{"ns"},
}
}

0 comments on commit 8b3f192

Please sign in to comment.