Skip to content

Commit f450ab7

Browse files
smiratalos-bot
authored andcommitted
feat: implement namespaces, clean up context use
More of general cleanup/refactoring, no new features. Signed-off-by: Andrey Smirnov <smirnov.andrey@gmail.com>
1 parent 81bf414 commit f450ab7

24 files changed

Lines changed: 444 additions & 172 deletions

.conform.yaml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT.
2+
#
3+
# Generated on 2020-09-25T18:15:38Z by kres ce6bee5-dirty.
4+
5+
policies:
6+
- type: commit
7+
spec:
8+
dco: true
9+
gpg: false
10+
spellcheck:
11+
locale: US
12+
maximumOfOneCommit: true
13+
header:
14+
length: 89
15+
imperative: true
16+
case: lower
17+
invalidLastCharacters: .
18+
body:
19+
required: true
20+
conventional:
21+
types: ["chore","docs","perf","refactor","style","test","release"]
22+
scopes: ["*"]
23+
- type: license
24+
spec:
25+
skipPaths:
26+
- .git/
27+
includeSuffixes:
28+
- .go
29+
excludeSuffixes:
30+
- .pb.go
31+
header: |
32+
// This Source Code Form is subject to the terms of the Mozilla Public
33+
// License, v. 2.0. If a copy of the MPL was not distributed with this
34+
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

.drone.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT.
33
#
4-
# Generated on 2020-08-28T20:50:38Z by kres 292ed36-dirty.
4+
# Generated on 2020-11-17T20:11:41Z by kres eb337ab.
55

66
kind: pipeline
77
type: kubernetes
@@ -166,7 +166,6 @@ services:
166166
- --dns=8.8.4.4
167167
- --mtu=1500
168168
- --log-level=error
169-
- --insecure-registry=http://registry.ci.svc:5000
170169
privileged: true
171170
volumes:
172171
- name: outer-docker-socket

Makefile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT.
22
#
3-
# Generated on 2020-08-28T20:51:32Z by kres 292ed36-dirty.
3+
# Generated on 2020-09-25T18:15:38Z by kres ce6bee5-dirty.
44

55
# common variables
66

77
SHA := $(shell git describe --match=none --always --abbrev=8 --dirty)
88
TAG := $(shell git describe --tag --always --dirty)
99
BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
1010
ARTIFACTS := _out
11-
REGISTRY ?= docker.io
12-
USERNAME ?= autonomy
11+
REGISTRY ?= ghcr.io
12+
USERNAME ?= talos-systems
1313
REGISTRY_AND_USERNAME ?= $(REGISTRY)/$(USERNAME)
1414
GOFUMPT_VERSION ?= abc0db2c416aca0f60ea33c23c76665f6e7ba0b6
1515
GO_VERSION ?= 1.14
1616
TESTPKGS ?= ./...
17-
KRES_IMAGE ?= autonomy/kres:latest
17+
KRES_IMAGE ?= ghcr.io/talos-systems/kres:latest
1818

1919
# docker build settings
2020

@@ -34,7 +34,7 @@ COMMON_ARGS += --build-arg=USERNAME=$(USERNAME)
3434
COMMON_ARGS += --build-arg=TOOLCHAIN=$(TOOLCHAIN)
3535
COMMON_ARGS += --build-arg=GOFUMPT_VERSION=$(GOFUMPT_VERSION)
3636
COMMON_ARGS += --build-arg=TESTPKGS=$(TESTPKGS)
37-
TOOLCHAIN ?= docker.io/golang:1.14-alpine
37+
TOOLCHAIN ?= docker.io/golang:1.15-alpine
3838

3939
# help menu
4040

@@ -130,7 +130,7 @@ lint: lint-golangci-lint lint-gofumpt lint-markdown ## Run all linters for the
130130
.PHONY: rekres
131131
rekres:
132132
@docker pull $(KRES_IMAGE)
133-
@docker run --rm -v $(PWD):/src -w /src $(KRES_IMAGE)
133+
@docker run --rm -v $(PWD):/src -w /src -e GITHUB_TOKEN $(KRES_IMAGE)
134134

135135
.PHONY: help
136136
help: ## This help menu.

cmd/directory-fun/main.go

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// This Source Code Form is subject to the terms of the Mozilla Public
2+
// License, v. 2.0. If a copy of the MPL was not distributed with this
3+
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
4+
15
package main
26

37
import (
@@ -30,7 +34,7 @@ func DirectoryTask(world state.State, path string) {
3034
err error
3135
)
3236

33-
if parent, err = world.WatchFor(ctx, PathResourceType, base, state.WithEventTypes(state.Created, state.Updated)); err != nil {
37+
if parent, err = world.WatchFor(ctx, resource.NewMetadata(defaultNs, PathResourceType, base, resource.VersionUndefined), state.WithEventTypes(state.Created, state.Updated)); err != nil {
3438
log.Fatal(err)
3539
}
3640

@@ -40,43 +44,46 @@ func DirectoryTask(world state.State, path string) {
4044
log.Fatal(err)
4145
}
4246

43-
self := NewPathResource(path)
47+
self := NewPathResource(defaultNs, path)
4448

45-
if err = world.Create(self); err != nil {
49+
if err = world.Create(ctx, self); err != nil {
4650
log.Fatal(err)
4751
}
4852

4953
log.Printf("%q: created %q", path, path)
5054

51-
if parent, err = world.UpdateWithConflicts(parent, func(r resource.Resource) error {
55+
if parent, err = world.UpdateWithConflicts(ctx, parent, func(r resource.Resource) error {
5256
r.(*PathResource).AddDependent(self)
5357

5458
return nil
5559
}); err != nil {
5660
log.Fatal(err)
5761
}
5862

59-
log.Printf("%q: %q.dependents = %q", path, parent.ID(), parent.(*PathResource).dependents)
63+
log.Printf("%q: %q.dependents = %q", path, parent.Metadata().ID(), parent.(*PathResource).spec.dependents)
6064

6165
// doing something useful here <>
6266

6367
log.Printf("%q: watching for teardown %q", path, base)
6468

65-
if parent, err = world.WatchFor(ctx, PathResourceType, base, state.WithEventTypes(state.Destroyed, state.Torndown)); err != nil {
69+
if parent, err = world.WatchFor(ctx, resource.NewMetadata(defaultNs, PathResourceType, base, resource.VersionUndefined), state.WithEventTypes(state.Destroyed, state.Torndown)); err != nil {
6670
log.Fatal(err)
6771
}
6872

6973
log.Printf("%q: teardown self", path)
7074

71-
if err = world.Teardown(self); err != nil {
75+
if err = world.Teardown(ctx, self.Metadata()); err != nil {
7276
log.Fatal(err)
7377
}
7478

7579
log.Printf("%q: watching for dependents to vanish %q", path, path)
7680

77-
if _, err = world.WatchFor(ctx, PathResourceType, path, state.WithEventTypes(state.Created, state.Updated, state.Torndown), state.WithCondition(func(r resource.Resource) (bool, error) {
78-
return len(r.(*PathResource).dependents) == 0, nil
79-
})); err != nil {
81+
if _, err = world.WatchFor(ctx,
82+
resource.NewMetadata(defaultNs, PathResourceType, path, resource.VersionUndefined),
83+
state.WithEventTypes(state.Created, state.Updated, state.Torndown),
84+
state.WithCondition(func(r resource.Resource) (bool, error) {
85+
return len(r.(*PathResource).spec.dependents) == 0, nil
86+
})); err != nil {
8087
log.Fatal(err)
8188
}
8289

@@ -86,24 +93,27 @@ func DirectoryTask(world state.State, path string) {
8693
log.Fatal(err)
8794
}
8895

89-
if _, err = world.UpdateWithConflicts(parent, func(r resource.Resource) error {
96+
if _, err = world.UpdateWithConflicts(ctx, parent, func(r resource.Resource) error {
9097
r.(*PathResource).DropDependent(self)
9198

9299
return nil
93100
}); err != nil {
94101
log.Fatal(err)
95102
}
96103

97-
if err = world.Destroy(self); err != nil {
104+
if err = world.Destroy(ctx, self.Metadata()); err != nil {
98105
log.Fatal(err)
99106
}
100107
}
101108

109+
const defaultNs = "default"
110+
102111
func main() {
103-
world := state.WrapCore(local.NewState())
112+
ctx := context.Background()
113+
world := state.WrapCore(local.NewState(defaultNs))
104114

105-
root := NewPathResource(".")
106-
if err := world.Create(root); err != nil {
115+
root := NewPathResource(defaultNs, ".")
116+
if err := world.Create(ctx, root); err != nil {
107117
log.Fatal(err)
108118
}
109119

@@ -127,7 +137,7 @@ func main() {
127137

128138
time.Sleep(2 * time.Second)
129139

130-
if err := world.Teardown(root); err != nil {
140+
if err := world.Teardown(ctx, root.Metadata()); err != nil {
131141
log.Fatal(err)
132142
}
133143

cmd/directory-fun/path.go

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,74 @@
1+
// This Source Code Form is subject to the terms of the Mozilla Public
2+
// License, v. 2.0. If a copy of the MPL was not distributed with this
3+
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
4+
15
//nolint: golint
26
package main
37

48
import (
59
"fmt"
6-
"strconv"
710

811
"github.com/talos-systems/os-runtime/pkg/resource"
912
)
1013

1114
const PathResourceType = resource.Type("os/path")
1215

16+
type pathResourceSpec struct {
17+
dependents []string
18+
}
19+
1320
// PathResource represents a path in the filesystem.
1421
//
1522
// Resource ID is the path, and dependents are all the immediate
1623
// children on the path.
1724
type PathResource struct {
18-
path string
19-
version int
20-
dependents []string
25+
md resource.Metadata
26+
spec pathResourceSpec
2127
}
2228

23-
func NewPathResource(path string) *PathResource {
24-
return &PathResource{path: path}
25-
}
26-
27-
func (path *PathResource) ID() resource.ID {
28-
return path.path
29-
}
29+
func NewPathResource(ns resource.Namespace, path string) *PathResource {
30+
r := &PathResource{
31+
md: resource.NewMetadata(ns, PathResourceType, path, resource.VersionUndefined),
32+
}
33+
r.md.BumpVersion()
3034

31-
func (path *PathResource) Type() resource.Type {
32-
return PathResourceType
35+
return r
3336
}
3437

35-
func (path *PathResource) Version() resource.Version {
36-
return strconv.Itoa(path.version)
38+
func (path *PathResource) Metadata() resource.Metadata {
39+
return path.md
3740
}
3841

3942
func (path *PathResource) Spec() interface{} {
40-
return nil
43+
return path.spec
4144
}
4245

4346
func (path *PathResource) String() string {
44-
return fmt.Sprintf("PathResource(%q)", path.path)
47+
return fmt.Sprintf("PathResource(%q)", path.md.ID())
4548
}
4649

4750
func (path *PathResource) Copy() resource.Resource {
4851
return &PathResource{
49-
path: path.path,
50-
version: path.version,
51-
dependents: append([]string(nil), path.dependents...),
52+
md: path.md,
53+
spec: pathResourceSpec{
54+
dependents: append([]string(nil), path.spec.dependents...),
55+
},
5256
}
5357
}
5458

5559
func (path *PathResource) AddDependent(dependent *PathResource) {
56-
path.dependents = append(path.dependents, dependent.path)
57-
path.version++
60+
path.spec.dependents = append(path.spec.dependents, dependent.md.ID())
61+
path.md.BumpVersion()
5862
}
5963

6064
func (path *PathResource) DropDependent(dependent *PathResource) {
61-
for i, p := range path.dependents {
62-
if p == dependent.path {
63-
path.dependents = append(path.dependents[:i], path.dependents[i+1:]...)
65+
for i, p := range path.spec.dependents {
66+
if p == dependent.md.ID() {
67+
path.spec.dependents = append(path.spec.dependents[:i], path.spec.dependents[i+1:]...)
6468

6569
break
6670
}
6771
}
6872

69-
path.version++
73+
path.md.BumpVersion()
7074
}

hack/git-chglog/config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT.
22
#
3-
# Generated on 2020-08-28T20:43:11Z by kres 292ed36-dirty.
3+
# Generated on 2020-09-25T18:15:38Z by kres ce6bee5-dirty.
44

55
style: github
66
template: CHANGELOG.tpl.md
77
info:
88
title: CHANGELOG
9-
repository_url: https://github.com/talos-systems/talos
9+
repository_url: https://github.com/talos-systems/os-runtime
1010
options:
1111
commits:
1212
# filters:

hack/release.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT.
44
#
5-
# Generated on 2020-08-28T20:43:11Z by kres 292ed36-dirty.
5+
# Generated on 2020-09-25T18:15:38Z by kres ce6bee5-dirty.
66

77

88
set -e
99

1010
function changelog {
1111
if [ "$#" -eq 1 ]; then
12-
git-chglog --output CHANGELOG.md -c ./hack/git-chglog/config.yaml --tag-filter-pattern "^${1}" "${1}.0-alpha.1.."
12+
git-chglog --output CHANGELOG.md -c ./hack/git-chglog/config.yaml --tag-filter-pattern "^${1}" "${1}.0-alpha.0.."
1313
elif [ "$#" -eq 0 ]; then
1414
git-chglog --output CHANGELOG.md -c ./hack/git-chglog/config.yaml
1515
else

0 commit comments

Comments
 (0)