id
int32 0
167k
| repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
listlengths 21
1.41k
| docstring
stringlengths 6
2.61k
| docstring_tokens
listlengths 3
215
| sha
stringlengths 40
40
| url
stringlengths 85
252
|
---|---|---|---|---|---|---|---|---|---|---|---|
18,200 |
sassoftware/go-rpmutils
|
writeheader.go
|
WriteTo
|
func (hdr *rpmHeader) WriteTo(outfile io.Writer, regionTag int) error {
if regionTag != 0 && regionTag >= RPMTAG_HEADERREGIONS {
return errors.New("invalid region tag")
}
// sort tags
var keys []int
for k := range hdr.entries {
if k < RPMTAG_HEADERREGIONS {
// discard existing regions
continue
}
keys = append(keys, k)
}
sort.Ints(keys)
entries := bytes.NewBuffer(make([]byte, 0, 16*len(keys)))
blobs := bytes.NewBuffer(make([]byte, 0, hdr.origSize))
for _, k := range keys {
if k == regionTag {
continue
}
if err := writeTag(entries, blobs, k, hdr.entries[k]); err != nil {
return err
}
}
intro := headerIntro{
Magic: introMagic,
Reserved: 0,
Entries: uint32(len(keys) + 1),
Size: uint32(blobs.Len() + 16),
}
if err := binary.Write(outfile, binary.BigEndian, &intro); err != nil {
return err
}
if err := writeRegion(outfile, blobs, regionTag, len(keys)); err != nil {
return err
}
totalSize := 96 + blobs.Len() + entries.Len()
if _, err := io.Copy(outfile, entries); err != nil {
return err
}
if _, err := io.Copy(outfile, blobs); err != nil {
return err
}
if regionTag == RPMTAG_HEADERSIGNATURES {
alignment := totalSize % 8
if alignment != 0 {
outfile.Write(make([]byte, 8-alignment))
}
}
return nil
}
|
go
|
func (hdr *rpmHeader) WriteTo(outfile io.Writer, regionTag int) error {
if regionTag != 0 && regionTag >= RPMTAG_HEADERREGIONS {
return errors.New("invalid region tag")
}
// sort tags
var keys []int
for k := range hdr.entries {
if k < RPMTAG_HEADERREGIONS {
// discard existing regions
continue
}
keys = append(keys, k)
}
sort.Ints(keys)
entries := bytes.NewBuffer(make([]byte, 0, 16*len(keys)))
blobs := bytes.NewBuffer(make([]byte, 0, hdr.origSize))
for _, k := range keys {
if k == regionTag {
continue
}
if err := writeTag(entries, blobs, k, hdr.entries[k]); err != nil {
return err
}
}
intro := headerIntro{
Magic: introMagic,
Reserved: 0,
Entries: uint32(len(keys) + 1),
Size: uint32(blobs.Len() + 16),
}
if err := binary.Write(outfile, binary.BigEndian, &intro); err != nil {
return err
}
if err := writeRegion(outfile, blobs, regionTag, len(keys)); err != nil {
return err
}
totalSize := 96 + blobs.Len() + entries.Len()
if _, err := io.Copy(outfile, entries); err != nil {
return err
}
if _, err := io.Copy(outfile, blobs); err != nil {
return err
}
if regionTag == RPMTAG_HEADERSIGNATURES {
alignment := totalSize % 8
if alignment != 0 {
outfile.Write(make([]byte, 8-alignment))
}
}
return nil
}
|
[
"func",
"(",
"hdr",
"*",
"rpmHeader",
")",
"WriteTo",
"(",
"outfile",
"io",
".",
"Writer",
",",
"regionTag",
"int",
")",
"error",
"{",
"if",
"regionTag",
"!=",
"0",
"&&",
"regionTag",
">=",
"RPMTAG_HEADERREGIONS",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"// sort tags",
"var",
"keys",
"[",
"]",
"int",
"\n",
"for",
"k",
":=",
"range",
"hdr",
".",
"entries",
"{",
"if",
"k",
"<",
"RPMTAG_HEADERREGIONS",
"{",
"// discard existing regions",
"continue",
"\n",
"}",
"\n",
"keys",
"=",
"append",
"(",
"keys",
",",
"k",
")",
"\n",
"}",
"\n",
"sort",
".",
"Ints",
"(",
"keys",
")",
"\n",
"entries",
":=",
"bytes",
".",
"NewBuffer",
"(",
"make",
"(",
"[",
"]",
"byte",
",",
"0",
",",
"16",
"*",
"len",
"(",
"keys",
")",
")",
")",
"\n",
"blobs",
":=",
"bytes",
".",
"NewBuffer",
"(",
"make",
"(",
"[",
"]",
"byte",
",",
"0",
",",
"hdr",
".",
"origSize",
")",
")",
"\n",
"for",
"_",
",",
"k",
":=",
"range",
"keys",
"{",
"if",
"k",
"==",
"regionTag",
"{",
"continue",
"\n",
"}",
"\n",
"if",
"err",
":=",
"writeTag",
"(",
"entries",
",",
"blobs",
",",
"k",
",",
"hdr",
".",
"entries",
"[",
"k",
"]",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"intro",
":=",
"headerIntro",
"{",
"Magic",
":",
"introMagic",
",",
"Reserved",
":",
"0",
",",
"Entries",
":",
"uint32",
"(",
"len",
"(",
"keys",
")",
"+",
"1",
")",
",",
"Size",
":",
"uint32",
"(",
"blobs",
".",
"Len",
"(",
")",
"+",
"16",
")",
",",
"}",
"\n",
"if",
"err",
":=",
"binary",
".",
"Write",
"(",
"outfile",
",",
"binary",
".",
"BigEndian",
",",
"&",
"intro",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"err",
":=",
"writeRegion",
"(",
"outfile",
",",
"blobs",
",",
"regionTag",
",",
"len",
"(",
"keys",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"totalSize",
":=",
"96",
"+",
"blobs",
".",
"Len",
"(",
")",
"+",
"entries",
".",
"Len",
"(",
")",
"\n",
"if",
"_",
",",
"err",
":=",
"io",
".",
"Copy",
"(",
"outfile",
",",
"entries",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"_",
",",
"err",
":=",
"io",
".",
"Copy",
"(",
"outfile",
",",
"blobs",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"regionTag",
"==",
"RPMTAG_HEADERSIGNATURES",
"{",
"alignment",
":=",
"totalSize",
"%",
"8",
"\n",
"if",
"alignment",
"!=",
"0",
"{",
"outfile",
".",
"Write",
"(",
"make",
"(",
"[",
"]",
"byte",
",",
"8",
"-",
"alignment",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Write the header out, adding a region tag encompassing all the existing tags.
|
[
"Write",
"the",
"header",
"out",
"adding",
"a",
"region",
"tag",
"encompassing",
"all",
"the",
"existing",
"tags",
"."
] |
c37ab0fd127a1e43f40d0ba2250302e20eaee937
|
https://github.com/sassoftware/go-rpmutils/blob/c37ab0fd127a1e43f40d0ba2250302e20eaee937/writeheader.go#L71-L121
|
18,201 |
sassoftware/go-rpmutils
|
writeheader.go
|
DumpSignatureHeader
|
func (hdr *RpmHeader) DumpSignatureHeader(sameSize bool) ([]byte, error) {
if len(hdr.lead) != 96 {
return nil, errors.New("invalid or missing RPM lead")
}
sigh := hdr.sigHeader
regionTag := RPMTAG_HEADERSIGNATURES
delete(sigh.entries, SIG_RESERVEDSPACE-_SIGHEADER_TAG_BASE)
if sameSize {
needed, err := sigh.size(regionTag)
if err != nil {
return nil, err
}
available := uint64(sigh.origSize)
if needed+16 <= available {
// Fill unused space with a RESERVEDSPACE tag
padding := make([]byte, available-needed-16)
sigh.entries[SIG_RESERVEDSPACE-_SIGHEADER_TAG_BASE] = entry{
dataType: RPM_BIN_TYPE,
count: int32(len(padding)),
contents: padding,
}
}
}
buf := new(bytes.Buffer)
buf.Write(hdr.lead)
if err := sigh.WriteTo(buf, regionTag); err != nil {
return nil, err
}
return buf.Bytes(), nil
}
|
go
|
func (hdr *RpmHeader) DumpSignatureHeader(sameSize bool) ([]byte, error) {
if len(hdr.lead) != 96 {
return nil, errors.New("invalid or missing RPM lead")
}
sigh := hdr.sigHeader
regionTag := RPMTAG_HEADERSIGNATURES
delete(sigh.entries, SIG_RESERVEDSPACE-_SIGHEADER_TAG_BASE)
if sameSize {
needed, err := sigh.size(regionTag)
if err != nil {
return nil, err
}
available := uint64(sigh.origSize)
if needed+16 <= available {
// Fill unused space with a RESERVEDSPACE tag
padding := make([]byte, available-needed-16)
sigh.entries[SIG_RESERVEDSPACE-_SIGHEADER_TAG_BASE] = entry{
dataType: RPM_BIN_TYPE,
count: int32(len(padding)),
contents: padding,
}
}
}
buf := new(bytes.Buffer)
buf.Write(hdr.lead)
if err := sigh.WriteTo(buf, regionTag); err != nil {
return nil, err
}
return buf.Bytes(), nil
}
|
[
"func",
"(",
"hdr",
"*",
"RpmHeader",
")",
"DumpSignatureHeader",
"(",
"sameSize",
"bool",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"len",
"(",
"hdr",
".",
"lead",
")",
"!=",
"96",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"sigh",
":=",
"hdr",
".",
"sigHeader",
"\n",
"regionTag",
":=",
"RPMTAG_HEADERSIGNATURES",
"\n",
"delete",
"(",
"sigh",
".",
"entries",
",",
"SIG_RESERVEDSPACE",
"-",
"_SIGHEADER_TAG_BASE",
")",
"\n",
"if",
"sameSize",
"{",
"needed",
",",
"err",
":=",
"sigh",
".",
"size",
"(",
"regionTag",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"available",
":=",
"uint64",
"(",
"sigh",
".",
"origSize",
")",
"\n",
"if",
"needed",
"+",
"16",
"<=",
"available",
"{",
"// Fill unused space with a RESERVEDSPACE tag",
"padding",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"available",
"-",
"needed",
"-",
"16",
")",
"\n",
"sigh",
".",
"entries",
"[",
"SIG_RESERVEDSPACE",
"-",
"_SIGHEADER_TAG_BASE",
"]",
"=",
"entry",
"{",
"dataType",
":",
"RPM_BIN_TYPE",
",",
"count",
":",
"int32",
"(",
"len",
"(",
"padding",
")",
")",
",",
"contents",
":",
"padding",
",",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"buf",
":=",
"new",
"(",
"bytes",
".",
"Buffer",
")",
"\n",
"buf",
".",
"Write",
"(",
"hdr",
".",
"lead",
")",
"\n",
"if",
"err",
":=",
"sigh",
".",
"WriteTo",
"(",
"buf",
",",
"regionTag",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"buf",
".",
"Bytes",
"(",
")",
",",
"nil",
"\n",
"}"
] |
// Dump the lead and signature header, optionally adding or changing padding to
// make it the same size as when it was originally read. Otherwise padding is
// removed to make it as small as possible.
|
[
"Dump",
"the",
"lead",
"and",
"signature",
"header",
"optionally",
"adding",
"or",
"changing",
"padding",
"to",
"make",
"it",
"the",
"same",
"size",
"as",
"when",
"it",
"was",
"originally",
"read",
".",
"Otherwise",
"padding",
"is",
"removed",
"to",
"make",
"it",
"as",
"small",
"as",
"possible",
"."
] |
c37ab0fd127a1e43f40d0ba2250302e20eaee937
|
https://github.com/sassoftware/go-rpmutils/blob/c37ab0fd127a1e43f40d0ba2250302e20eaee937/writeheader.go#L145-L174
|
18,202 |
marksalpeter/token
|
Token.go
|
Encode
|
func (t Token) Encode() string {
bs, _ := t.MarshalText()
return string(bs)
}
|
go
|
func (t Token) Encode() string {
bs, _ := t.MarshalText()
return string(bs)
}
|
[
"func",
"(",
"t",
"Token",
")",
"Encode",
"(",
")",
"string",
"{",
"bs",
",",
"_",
":=",
"t",
".",
"MarshalText",
"(",
")",
"\n",
"return",
"string",
"(",
"bs",
")",
"\n",
"}"
] |
// Encode encodes the token into a base62 string
|
[
"Encode",
"encodes",
"the",
"token",
"into",
"a",
"base62",
"string"
] |
27d8e59762a88663f89b6cf73cd01a485fae47e6
|
https://github.com/marksalpeter/token/blob/27d8e59762a88663f89b6cf73cd01a485fae47e6/Token.go#L52-L55
|
18,203 |
marksalpeter/token
|
Token.go
|
MarshalText
|
func (t Token) MarshalText() ([]byte, error) {
number := uint64(t)
var chars []byte
if number == 0 {
return chars, nil
}
for number > 0 {
result := number / base62Len
remainder := number % base62Len
chars = append(chars, Base62[remainder])
number = result
}
for i, j := 0, len(chars)-1; i < j; i, j = i+1, j-1 {
chars[i], chars[j] = chars[j], chars[i]
}
return chars, nil
}
|
go
|
func (t Token) MarshalText() ([]byte, error) {
number := uint64(t)
var chars []byte
if number == 0 {
return chars, nil
}
for number > 0 {
result := number / base62Len
remainder := number % base62Len
chars = append(chars, Base62[remainder])
number = result
}
for i, j := 0, len(chars)-1; i < j; i, j = i+1, j-1 {
chars[i], chars[j] = chars[j], chars[i]
}
return chars, nil
}
|
[
"func",
"(",
"t",
"Token",
")",
"MarshalText",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"number",
":=",
"uint64",
"(",
"t",
")",
"\n",
"var",
"chars",
"[",
"]",
"byte",
"\n\n",
"if",
"number",
"==",
"0",
"{",
"return",
"chars",
",",
"nil",
"\n",
"}",
"\n\n",
"for",
"number",
">",
"0",
"{",
"result",
":=",
"number",
"/",
"base62Len",
"\n",
"remainder",
":=",
"number",
"%",
"base62Len",
"\n",
"chars",
"=",
"append",
"(",
"chars",
",",
"Base62",
"[",
"remainder",
"]",
")",
"\n",
"number",
"=",
"result",
"\n",
"}",
"\n\n",
"for",
"i",
",",
"j",
":=",
"0",
",",
"len",
"(",
"chars",
")",
"-",
"1",
";",
"i",
"<",
"j",
";",
"i",
",",
"j",
"=",
"i",
"+",
"1",
",",
"j",
"-",
"1",
"{",
"chars",
"[",
"i",
"]",
",",
"chars",
"[",
"j",
"]",
"=",
"chars",
"[",
"j",
"]",
",",
"chars",
"[",
"i",
"]",
"\n",
"}",
"\n\n",
"return",
"chars",
",",
"nil",
"\n",
"}"
] |
// MarshalText implements the `encoding.TextMarsheler` interface
|
[
"MarshalText",
"implements",
"the",
"encoding",
".",
"TextMarsheler",
"interface"
] |
27d8e59762a88663f89b6cf73cd01a485fae47e6
|
https://github.com/marksalpeter/token/blob/27d8e59762a88663f89b6cf73cd01a485fae47e6/Token.go#L89-L109
|
18,204 |
marksalpeter/token
|
Token.go
|
Decode
|
func Decode(token string) (Token, error) {
var t Token
err := (&t).UnmarshalText([]byte(token))
return t, err
}
|
go
|
func Decode(token string) (Token, error) {
var t Token
err := (&t).UnmarshalText([]byte(token))
return t, err
}
|
[
"func",
"Decode",
"(",
"token",
"string",
")",
"(",
"Token",
",",
"error",
")",
"{",
"var",
"t",
"Token",
"\n",
"err",
":=",
"(",
"&",
"t",
")",
".",
"UnmarshalText",
"(",
"[",
"]",
"byte",
"(",
"token",
")",
")",
"\n",
"return",
"t",
",",
"err",
"\n",
"}"
] |
// Decode returns a token from a 1-12 character base62 encoded string
|
[
"Decode",
"returns",
"a",
"token",
"from",
"a",
"1",
"-",
"12",
"character",
"base62",
"encoded",
"string"
] |
27d8e59762a88663f89b6cf73cd01a485fae47e6
|
https://github.com/marksalpeter/token/blob/27d8e59762a88663f89b6cf73cd01a485fae47e6/Token.go#L135-L139
|
18,205 |
marksalpeter/token
|
Token.go
|
maxHashInt
|
func maxHashInt(length int) uint64 {
return uint64(math.Max(0, math.Min(math.MaxUint64, math.Pow(float64(base62Len), float64(length)))))
}
|
go
|
func maxHashInt(length int) uint64 {
return uint64(math.Max(0, math.Min(math.MaxUint64, math.Pow(float64(base62Len), float64(length)))))
}
|
[
"func",
"maxHashInt",
"(",
"length",
"int",
")",
"uint64",
"{",
"return",
"uint64",
"(",
"math",
".",
"Max",
"(",
"0",
",",
"math",
".",
"Min",
"(",
"math",
".",
"MaxUint64",
",",
"math",
".",
"Pow",
"(",
"float64",
"(",
"base62Len",
")",
",",
"float64",
"(",
"length",
")",
")",
")",
")",
")",
"\n",
"}"
] |
// maxHashInt returns the largest possible int that will yeild a base62 encoded token of the specified length
|
[
"maxHashInt",
"returns",
"the",
"largest",
"possible",
"int",
"that",
"will",
"yeild",
"a",
"base62",
"encoded",
"token",
"of",
"the",
"specified",
"length"
] |
27d8e59762a88663f89b6cf73cd01a485fae47e6
|
https://github.com/marksalpeter/token/blob/27d8e59762a88663f89b6cf73cd01a485fae47e6/Token.go#L142-L144
|
18,206 |
crackcomm/nsqueue
|
consumer/consumer.go
|
New
|
func New() *Consumer {
return &Consumer{
Logger: nsqlog.Logger,
LogLevel: nsqlog.LogLevel,
handlers: make(map[topicChan]*queue),
}
}
|
go
|
func New() *Consumer {
return &Consumer{
Logger: nsqlog.Logger,
LogLevel: nsqlog.LogLevel,
handlers: make(map[topicChan]*queue),
}
}
|
[
"func",
"New",
"(",
")",
"*",
"Consumer",
"{",
"return",
"&",
"Consumer",
"{",
"Logger",
":",
"nsqlog",
".",
"Logger",
",",
"LogLevel",
":",
"nsqlog",
".",
"LogLevel",
",",
"handlers",
":",
"make",
"(",
"map",
"[",
"topicChan",
"]",
"*",
"queue",
")",
",",
"}",
"\n",
"}"
] |
// New - Creates a new consumer structure
|
[
"New",
"-",
"Creates",
"a",
"new",
"consumer",
"structure"
] |
6ee4382f836581113c3c3a6f8ee765138add72b3
|
https://github.com/crackcomm/nsqueue/blob/6ee4382f836581113c3c3a6f8ee765138add72b3/consumer/consumer.go#L28-L34
|
18,207 |
crackcomm/nsqueue
|
consumer/consumer.go
|
Connect
|
func (c *Consumer) Connect(addrs ...string) error {
for _, q := range c.handlers {
for _, addr := range addrs {
if err := q.ConnectToNSQD(addr); err != nil {
return err
}
}
}
return nil
}
|
go
|
func (c *Consumer) Connect(addrs ...string) error {
for _, q := range c.handlers {
for _, addr := range addrs {
if err := q.ConnectToNSQD(addr); err != nil {
return err
}
}
}
return nil
}
|
[
"func",
"(",
"c",
"*",
"Consumer",
")",
"Connect",
"(",
"addrs",
"...",
"string",
")",
"error",
"{",
"for",
"_",
",",
"q",
":=",
"range",
"c",
".",
"handlers",
"{",
"for",
"_",
",",
"addr",
":=",
"range",
"addrs",
"{",
"if",
"err",
":=",
"q",
".",
"ConnectToNSQD",
"(",
"addr",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Connect - Connects all readers to NSQ
|
[
"Connect",
"-",
"Connects",
"all",
"readers",
"to",
"NSQ"
] |
6ee4382f836581113c3c3a6f8ee765138add72b3
|
https://github.com/crackcomm/nsqueue/blob/6ee4382f836581113c3c3a6f8ee765138add72b3/consumer/consumer.go#L64-L73
|
18,208 |
crackcomm/nsqueue
|
consumer/consumer.go
|
ConnectLookupd
|
func (c *Consumer) ConnectLookupd(addrs ...string) error {
for _, q := range c.handlers {
for _, addr := range addrs {
if err := q.ConnectToNSQLookupd(addr); err != nil {
return err
}
}
}
return nil
}
|
go
|
func (c *Consumer) ConnectLookupd(addrs ...string) error {
for _, q := range c.handlers {
for _, addr := range addrs {
if err := q.ConnectToNSQLookupd(addr); err != nil {
return err
}
}
}
return nil
}
|
[
"func",
"(",
"c",
"*",
"Consumer",
")",
"ConnectLookupd",
"(",
"addrs",
"...",
"string",
")",
"error",
"{",
"for",
"_",
",",
"q",
":=",
"range",
"c",
".",
"handlers",
"{",
"for",
"_",
",",
"addr",
":=",
"range",
"addrs",
"{",
"if",
"err",
":=",
"q",
".",
"ConnectToNSQLookupd",
"(",
"addr",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// ConnectLookupd - Connects all readers to NSQ lookupd
|
[
"ConnectLookupd",
"-",
"Connects",
"all",
"readers",
"to",
"NSQ",
"lookupd"
] |
6ee4382f836581113c3c3a6f8ee765138add72b3
|
https://github.com/crackcomm/nsqueue/blob/6ee4382f836581113c3c3a6f8ee765138add72b3/consumer/consumer.go#L76-L85
|
18,209 |
crackcomm/nsqueue
|
consumer/consumer.go
|
Start
|
func (c *Consumer) Start(debug bool) error {
if debug {
for i := range c.handlers {
log.Printf("Handler: topic=%s channel=%s\n", i.topic, i.channel)
}
}
<-make(chan bool)
return nil
}
|
go
|
func (c *Consumer) Start(debug bool) error {
if debug {
for i := range c.handlers {
log.Printf("Handler: topic=%s channel=%s\n", i.topic, i.channel)
}
}
<-make(chan bool)
return nil
}
|
[
"func",
"(",
"c",
"*",
"Consumer",
")",
"Start",
"(",
"debug",
"bool",
")",
"error",
"{",
"if",
"debug",
"{",
"for",
"i",
":=",
"range",
"c",
".",
"handlers",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"i",
".",
"topic",
",",
"i",
".",
"channel",
")",
"\n",
"}",
"\n",
"}",
"\n",
"<-",
"make",
"(",
"chan",
"bool",
")",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Start - Just waits
|
[
"Start",
"-",
"Just",
"waits"
] |
6ee4382f836581113c3c3a6f8ee765138add72b3
|
https://github.com/crackcomm/nsqueue/blob/6ee4382f836581113c3c3a6f8ee765138add72b3/consumer/consumer.go#L88-L96
|
18,210 |
crackcomm/nsqueue
|
consumer/message.go
|
WithMessage
|
func WithMessage(ctx context.Context, msg *Message) context.Context {
return context.WithValue(ctx, msgkey, msg)
}
|
go
|
func WithMessage(ctx context.Context, msg *Message) context.Context {
return context.WithValue(ctx, msgkey, msg)
}
|
[
"func",
"WithMessage",
"(",
"ctx",
"context",
".",
"Context",
",",
"msg",
"*",
"Message",
")",
"context",
".",
"Context",
"{",
"return",
"context",
".",
"WithValue",
"(",
"ctx",
",",
"msgkey",
",",
"msg",
")",
"\n",
"}"
] |
// WithMessage - Returns nsq message from context.
|
[
"WithMessage",
"-",
"Returns",
"nsq",
"message",
"from",
"context",
"."
] |
6ee4382f836581113c3c3a6f8ee765138add72b3
|
https://github.com/crackcomm/nsqueue/blob/6ee4382f836581113c3c3a6f8ee765138add72b3/consumer/message.go#L18-L20
|
18,211 |
crackcomm/nsqueue
|
consumer/message.go
|
MessageFromContext
|
func MessageFromContext(ctx context.Context) (*Message, bool) {
value, ok := ctx.Value(msgkey).(*Message)
return value, ok
}
|
go
|
func MessageFromContext(ctx context.Context) (*Message, bool) {
value, ok := ctx.Value(msgkey).(*Message)
return value, ok
}
|
[
"func",
"MessageFromContext",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"*",
"Message",
",",
"bool",
")",
"{",
"value",
",",
"ok",
":=",
"ctx",
".",
"Value",
"(",
"msgkey",
")",
".",
"(",
"*",
"Message",
")",
"\n",
"return",
"value",
",",
"ok",
"\n",
"}"
] |
// MessageFromContext - Returns nsq message from context.
|
[
"MessageFromContext",
"-",
"Returns",
"nsq",
"message",
"from",
"context",
"."
] |
6ee4382f836581113c3c3a6f8ee765138add72b3
|
https://github.com/crackcomm/nsqueue/blob/6ee4382f836581113c3c3a6f8ee765138add72b3/consumer/message.go#L23-L26
|
18,212 |
crackcomm/nsqueue
|
consumer/message.go
|
Finish
|
func (m *Message) Finish(success bool) {
if success {
m.Message.Finish()
} else {
m.Message.Requeue(-1)
}
}
|
go
|
func (m *Message) Finish(success bool) {
if success {
m.Message.Finish()
} else {
m.Message.Requeue(-1)
}
}
|
[
"func",
"(",
"m",
"*",
"Message",
")",
"Finish",
"(",
"success",
"bool",
")",
"{",
"if",
"success",
"{",
"m",
".",
"Message",
".",
"Finish",
"(",
")",
"\n",
"}",
"else",
"{",
"m",
".",
"Message",
".",
"Requeue",
"(",
"-",
"1",
")",
"\n",
"}",
"\n",
"}"
] |
// Finish - Finish processing message
|
[
"Finish",
"-",
"Finish",
"processing",
"message"
] |
6ee4382f836581113c3c3a6f8ee765138add72b3
|
https://github.com/crackcomm/nsqueue/blob/6ee4382f836581113c3c3a6f8ee765138add72b3/consumer/message.go#L44-L50
|
18,213 |
crackcomm/nsqueue
|
consumer/message.go
|
ReadJSON
|
func (m *Message) ReadJSON(v interface{}) error {
return json.Unmarshal(m.Body, v)
}
|
go
|
func (m *Message) ReadJSON(v interface{}) error {
return json.Unmarshal(m.Body, v)
}
|
[
"func",
"(",
"m",
"*",
"Message",
")",
"ReadJSON",
"(",
"v",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"json",
".",
"Unmarshal",
"(",
"m",
".",
"Body",
",",
"v",
")",
"\n",
"}"
] |
// ReadJSON - Unmarshals JSON message body to interface.
|
[
"ReadJSON",
"-",
"Unmarshals",
"JSON",
"message",
"body",
"to",
"interface",
"."
] |
6ee4382f836581113c3c3a6f8ee765138add72b3
|
https://github.com/crackcomm/nsqueue/blob/6ee4382f836581113c3c3a6f8ee765138add72b3/consumer/message.go#L53-L55
|
18,214 |
crackcomm/nsqueue
|
producer/default.go
|
Publish
|
func Publish(topic string, body []byte) error {
return DefaultProducer.Publish(topic, body)
}
|
go
|
func Publish(topic string, body []byte) error {
return DefaultProducer.Publish(topic, body)
}
|
[
"func",
"Publish",
"(",
"topic",
"string",
",",
"body",
"[",
"]",
"byte",
")",
"error",
"{",
"return",
"DefaultProducer",
".",
"Publish",
"(",
"topic",
",",
"body",
")",
"\n",
"}"
] |
// Publish - sends message to nsq topic
|
[
"Publish",
"-",
"sends",
"message",
"to",
"nsq",
"topic"
] |
6ee4382f836581113c3c3a6f8ee765138add72b3
|
https://github.com/crackcomm/nsqueue/blob/6ee4382f836581113c3c3a6f8ee765138add72b3/producer/default.go#L15-L17
|
18,215 |
crackcomm/nsqueue
|
producer/default.go
|
PublishAsync
|
func PublishAsync(topic string, body []byte, doneChan chan *nsq.ProducerTransaction, args ...interface{}) error {
return DefaultProducer.PublishAsync(topic, body, doneChan, args...)
}
|
go
|
func PublishAsync(topic string, body []byte, doneChan chan *nsq.ProducerTransaction, args ...interface{}) error {
return DefaultProducer.PublishAsync(topic, body, doneChan, args...)
}
|
[
"func",
"PublishAsync",
"(",
"topic",
"string",
",",
"body",
"[",
"]",
"byte",
",",
"doneChan",
"chan",
"*",
"nsq",
".",
"ProducerTransaction",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"DefaultProducer",
".",
"PublishAsync",
"(",
"topic",
",",
"body",
",",
"doneChan",
",",
"args",
"...",
")",
"\n",
"}"
] |
// PublishAsync - sends a message to nsq topic asynchronously
|
[
"PublishAsync",
"-",
"sends",
"a",
"message",
"to",
"nsq",
"topic",
"asynchronously"
] |
6ee4382f836581113c3c3a6f8ee765138add72b3
|
https://github.com/crackcomm/nsqueue/blob/6ee4382f836581113c3c3a6f8ee765138add72b3/producer/default.go#L30-L32
|
18,216 |
crackcomm/nsqueue
|
producer/default.go
|
MultiPublish
|
func MultiPublish(topic string, body [][]byte) error {
return DefaultProducer.MultiPublish(topic, body)
}
|
go
|
func MultiPublish(topic string, body [][]byte) error {
return DefaultProducer.MultiPublish(topic, body)
}
|
[
"func",
"MultiPublish",
"(",
"topic",
"string",
",",
"body",
"[",
"]",
"[",
"]",
"byte",
")",
"error",
"{",
"return",
"DefaultProducer",
".",
"MultiPublish",
"(",
"topic",
",",
"body",
")",
"\n",
"}"
] |
// MultiPublish - sends multiple message to to nsq topic
|
[
"MultiPublish",
"-",
"sends",
"multiple",
"message",
"to",
"to",
"nsq",
"topic"
] |
6ee4382f836581113c3c3a6f8ee765138add72b3
|
https://github.com/crackcomm/nsqueue/blob/6ee4382f836581113c3c3a6f8ee765138add72b3/producer/default.go#L35-L37
|
18,217 |
crackcomm/nsqueue
|
producer/default.go
|
ConnectConfig
|
func ConnectConfig(addr string, config *nsq.Config) error {
return DefaultProducer.ConnectConfig(addr, config)
}
|
go
|
func ConnectConfig(addr string, config *nsq.Config) error {
return DefaultProducer.ConnectConfig(addr, config)
}
|
[
"func",
"ConnectConfig",
"(",
"addr",
"string",
",",
"config",
"*",
"nsq",
".",
"Config",
")",
"error",
"{",
"return",
"DefaultProducer",
".",
"ConnectConfig",
"(",
"addr",
",",
"config",
")",
"\n",
"}"
] |
// ConnectConfig method initialize the connection to nsq with config
|
[
"ConnectConfig",
"method",
"initialize",
"the",
"connection",
"to",
"nsq",
"with",
"config"
] |
6ee4382f836581113c3c3a6f8ee765138add72b3
|
https://github.com/crackcomm/nsqueue/blob/6ee4382f836581113c3c3a6f8ee765138add72b3/producer/default.go#L50-L52
|
18,218 |
crackcomm/nsqueue
|
producer/producer.go
|
Connect
|
func (p *Producer) Connect(addr string) (err error) {
return p.ConnectConfig(addr, nsq.NewConfig())
}
|
go
|
func (p *Producer) Connect(addr string) (err error) {
return p.ConnectConfig(addr, nsq.NewConfig())
}
|
[
"func",
"(",
"p",
"*",
"Producer",
")",
"Connect",
"(",
"addr",
"string",
")",
"(",
"err",
"error",
")",
"{",
"return",
"p",
".",
"ConnectConfig",
"(",
"addr",
",",
"nsq",
".",
"NewConfig",
"(",
")",
")",
"\n",
"}"
] |
// Connect - Connects prodocuer to nsq instance.
|
[
"Connect",
"-",
"Connects",
"prodocuer",
"to",
"nsq",
"instance",
"."
] |
6ee4382f836581113c3c3a6f8ee765138add72b3
|
https://github.com/crackcomm/nsqueue/blob/6ee4382f836581113c3c3a6f8ee765138add72b3/producer/producer.go#L28-L30
|
18,219 |
crackcomm/nsqueue
|
producer/producer.go
|
ConnectConfig
|
func (p *Producer) ConnectConfig(addr string, config *nsq.Config) (err error) {
p.Producer, err = nsq.NewProducer(addr, config)
p.Producer.SetLogger(p.Logger, p.LogLevel)
return
}
|
go
|
func (p *Producer) ConnectConfig(addr string, config *nsq.Config) (err error) {
p.Producer, err = nsq.NewProducer(addr, config)
p.Producer.SetLogger(p.Logger, p.LogLevel)
return
}
|
[
"func",
"(",
"p",
"*",
"Producer",
")",
"ConnectConfig",
"(",
"addr",
"string",
",",
"config",
"*",
"nsq",
".",
"Config",
")",
"(",
"err",
"error",
")",
"{",
"p",
".",
"Producer",
",",
"err",
"=",
"nsq",
".",
"NewProducer",
"(",
"addr",
",",
"config",
")",
"\n",
"p",
".",
"Producer",
".",
"SetLogger",
"(",
"p",
".",
"Logger",
",",
"p",
".",
"LogLevel",
")",
"\n",
"return",
"\n",
"}"
] |
// ConnectConfig method initialize the connection to nsq with config.
|
[
"ConnectConfig",
"method",
"initialize",
"the",
"connection",
"to",
"nsq",
"with",
"config",
"."
] |
6ee4382f836581113c3c3a6f8ee765138add72b3
|
https://github.com/crackcomm/nsqueue/blob/6ee4382f836581113c3c3a6f8ee765138add72b3/producer/producer.go#L33-L37
|
18,220 |
crackcomm/nsqueue
|
producer/producer.go
|
PublishJSON
|
func (p *Producer) PublishJSON(topic string, v interface{}) error {
body, err := json.Marshal(v)
if err != nil {
return err
}
return p.Publish(topic, body)
}
|
go
|
func (p *Producer) PublishJSON(topic string, v interface{}) error {
body, err := json.Marshal(v)
if err != nil {
return err
}
return p.Publish(topic, body)
}
|
[
"func",
"(",
"p",
"*",
"Producer",
")",
"PublishJSON",
"(",
"topic",
"string",
",",
"v",
"interface",
"{",
"}",
")",
"error",
"{",
"body",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"v",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"p",
".",
"Publish",
"(",
"topic",
",",
"body",
")",
"\n",
"}"
] |
// PublishJSON - sends message to nsq topic in json format
|
[
"PublishJSON",
"-",
"sends",
"message",
"to",
"nsq",
"topic",
"in",
"json",
"format"
] |
6ee4382f836581113c3c3a6f8ee765138add72b3
|
https://github.com/crackcomm/nsqueue/blob/6ee4382f836581113c3c3a6f8ee765138add72b3/producer/producer.go#L49-L55
|
18,221 |
atlassian/smith
|
pkg/store/crd.go
|
Get
|
func (s *Crd) Get(resource schema.GroupKind) (*apiext_v1b1.CustomResourceDefinition, error) {
objs, err := s.byIndex(byGroupKindIndexName, byGroupKindIndexKey(resource.Group, resource.Kind))
if err != nil {
return nil, err
}
switch len(objs) {
case 0:
return nil, nil
case 1:
crd := objs[0].(*apiext_v1b1.CustomResourceDefinition).DeepCopy()
// Objects from type-specific informers don't have GVK set
crd.Kind = "CustomResourceDefinition"
crd.APIVersion = apiext_v1b1.SchemeGroupVersion.String()
return crd, nil
default:
// Must never happen
panic(errors.Errorf("multiple CRDs by group %q and kind %q: %s", resource.Group, resource.Kind, objs))
}
}
|
go
|
func (s *Crd) Get(resource schema.GroupKind) (*apiext_v1b1.CustomResourceDefinition, error) {
objs, err := s.byIndex(byGroupKindIndexName, byGroupKindIndexKey(resource.Group, resource.Kind))
if err != nil {
return nil, err
}
switch len(objs) {
case 0:
return nil, nil
case 1:
crd := objs[0].(*apiext_v1b1.CustomResourceDefinition).DeepCopy()
// Objects from type-specific informers don't have GVK set
crd.Kind = "CustomResourceDefinition"
crd.APIVersion = apiext_v1b1.SchemeGroupVersion.String()
return crd, nil
default:
// Must never happen
panic(errors.Errorf("multiple CRDs by group %q and kind %q: %s", resource.Group, resource.Kind, objs))
}
}
|
[
"func",
"(",
"s",
"*",
"Crd",
")",
"Get",
"(",
"resource",
"schema",
".",
"GroupKind",
")",
"(",
"*",
"apiext_v1b1",
".",
"CustomResourceDefinition",
",",
"error",
")",
"{",
"objs",
",",
"err",
":=",
"s",
".",
"byIndex",
"(",
"byGroupKindIndexName",
",",
"byGroupKindIndexKey",
"(",
"resource",
".",
"Group",
",",
"resource",
".",
"Kind",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"switch",
"len",
"(",
"objs",
")",
"{",
"case",
"0",
":",
"return",
"nil",
",",
"nil",
"\n",
"case",
"1",
":",
"crd",
":=",
"objs",
"[",
"0",
"]",
".",
"(",
"*",
"apiext_v1b1",
".",
"CustomResourceDefinition",
")",
".",
"DeepCopy",
"(",
")",
"\n",
"// Objects from type-specific informers don't have GVK set",
"crd",
".",
"Kind",
"=",
"\"",
"\"",
"\n",
"crd",
".",
"APIVersion",
"=",
"apiext_v1b1",
".",
"SchemeGroupVersion",
".",
"String",
"(",
")",
"\n",
"return",
"crd",
",",
"nil",
"\n",
"default",
":",
"// Must never happen",
"panic",
"(",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"resource",
".",
"Group",
",",
"resource",
".",
"Kind",
",",
"objs",
")",
")",
"\n",
"}",
"\n",
"}"
] |
// Get returns the CRD that defines the resource of provided group and kind.
|
[
"Get",
"returns",
"the",
"CRD",
"that",
"defines",
"the",
"resource",
"of",
"provided",
"group",
"and",
"kind",
"."
] |
e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438
|
https://github.com/atlassian/smith/blob/e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438/pkg/store/crd.go#L31-L49
|
18,222 |
atlassian/smith
|
pkg/store/multi.go
|
AddInformer
|
func (s *Multi) AddInformer(gvk schema.GroupVersionKind, informer cache.SharedIndexInformer) error {
s.mx.Lock()
defer s.mx.Unlock()
if _, ok := s.informers[gvk]; ok {
return errors.New("informer is already registered")
}
f := informer.GetIndexer().GetIndexers()[ByNamespaceAndControllerUIDIndex]
if f == nil {
// Informer does not have this index yet i.e. this is the first/sole multistore it is added to.
err := informer.AddIndexers(cache.Indexers{
ByNamespaceAndControllerUIDIndex: byNamespaceAndControllerUIDIndex,
})
if err != nil {
return errors.WithStack(err)
}
}
s.informers[gvk] = informer
return nil
}
|
go
|
func (s *Multi) AddInformer(gvk schema.GroupVersionKind, informer cache.SharedIndexInformer) error {
s.mx.Lock()
defer s.mx.Unlock()
if _, ok := s.informers[gvk]; ok {
return errors.New("informer is already registered")
}
f := informer.GetIndexer().GetIndexers()[ByNamespaceAndControllerUIDIndex]
if f == nil {
// Informer does not have this index yet i.e. this is the first/sole multistore it is added to.
err := informer.AddIndexers(cache.Indexers{
ByNamespaceAndControllerUIDIndex: byNamespaceAndControllerUIDIndex,
})
if err != nil {
return errors.WithStack(err)
}
}
s.informers[gvk] = informer
return nil
}
|
[
"func",
"(",
"s",
"*",
"Multi",
")",
"AddInformer",
"(",
"gvk",
"schema",
".",
"GroupVersionKind",
",",
"informer",
"cache",
".",
"SharedIndexInformer",
")",
"error",
"{",
"s",
".",
"mx",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"mx",
".",
"Unlock",
"(",
")",
"\n",
"if",
"_",
",",
"ok",
":=",
"s",
".",
"informers",
"[",
"gvk",
"]",
";",
"ok",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"f",
":=",
"informer",
".",
"GetIndexer",
"(",
")",
".",
"GetIndexers",
"(",
")",
"[",
"ByNamespaceAndControllerUIDIndex",
"]",
"\n",
"if",
"f",
"==",
"nil",
"{",
"// Informer does not have this index yet i.e. this is the first/sole multistore it is added to.",
"err",
":=",
"informer",
".",
"AddIndexers",
"(",
"cache",
".",
"Indexers",
"{",
"ByNamespaceAndControllerUIDIndex",
":",
"byNamespaceAndControllerUIDIndex",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"WithStack",
"(",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"s",
".",
"informers",
"[",
"gvk",
"]",
"=",
"informer",
"\n",
"return",
"nil",
"\n",
"}"
] |
// AddInformer adds an Informer to the store.
// Can only be called with a not yet started informer. Otherwise bad things will happen.
|
[
"AddInformer",
"adds",
"an",
"Informer",
"to",
"the",
"store",
".",
"Can",
"only",
"be",
"called",
"with",
"a",
"not",
"yet",
"started",
"informer",
".",
"Otherwise",
"bad",
"things",
"will",
"happen",
"."
] |
e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438
|
https://github.com/atlassian/smith/blob/e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438/pkg/store/multi.go#L28-L46
|
18,223 |
atlassian/smith
|
pkg/specchecker/hash.go
|
HashConfigMap
|
func HashConfigMap(configMap *core_v1.ConfigMap, h hash.Hash, filter sets.String) bool {
keys := make([]string, 0, len(configMap.Data))
search := sets.NewString(filter.UnsortedList()...)
for k := range configMap.Data {
if filter.Len() == 0 || filter.Has(k) {
keys = append(keys, k)
}
}
for k := range configMap.BinaryData {
if filter.Len() == 0 || filter.Has(k) {
keys = append(keys, k)
}
}
search.Delete(keys...)
if search.Len() != 0 {
// not all the provided keys in filter were found
return false
}
sort.Strings(keys)
for _, k := range keys {
io.WriteString(h, k) // nolint: gosec, errcheck
h.Write([]byte{0}) // nolint: gosec, errcheck
// The key is either in Data or BinaryData
data, inData := configMap.Data[k]
if inData {
io.WriteString(h, data) // nolint: gosec, errcheck
} else {
binaryData := configMap.BinaryData[k]
h.Write(binaryData) // nolint: gosec, errcheck
}
h.Write([]byte{0}) // nolint: gosec, errcheck
}
return true
}
|
go
|
func HashConfigMap(configMap *core_v1.ConfigMap, h hash.Hash, filter sets.String) bool {
keys := make([]string, 0, len(configMap.Data))
search := sets.NewString(filter.UnsortedList()...)
for k := range configMap.Data {
if filter.Len() == 0 || filter.Has(k) {
keys = append(keys, k)
}
}
for k := range configMap.BinaryData {
if filter.Len() == 0 || filter.Has(k) {
keys = append(keys, k)
}
}
search.Delete(keys...)
if search.Len() != 0 {
// not all the provided keys in filter were found
return false
}
sort.Strings(keys)
for _, k := range keys {
io.WriteString(h, k) // nolint: gosec, errcheck
h.Write([]byte{0}) // nolint: gosec, errcheck
// The key is either in Data or BinaryData
data, inData := configMap.Data[k]
if inData {
io.WriteString(h, data) // nolint: gosec, errcheck
} else {
binaryData := configMap.BinaryData[k]
h.Write(binaryData) // nolint: gosec, errcheck
}
h.Write([]byte{0}) // nolint: gosec, errcheck
}
return true
}
|
[
"func",
"HashConfigMap",
"(",
"configMap",
"*",
"core_v1",
".",
"ConfigMap",
",",
"h",
"hash",
".",
"Hash",
",",
"filter",
"sets",
".",
"String",
")",
"bool",
"{",
"keys",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"len",
"(",
"configMap",
".",
"Data",
")",
")",
"\n",
"search",
":=",
"sets",
".",
"NewString",
"(",
"filter",
".",
"UnsortedList",
"(",
")",
"...",
")",
"\n",
"for",
"k",
":=",
"range",
"configMap",
".",
"Data",
"{",
"if",
"filter",
".",
"Len",
"(",
")",
"==",
"0",
"||",
"filter",
".",
"Has",
"(",
"k",
")",
"{",
"keys",
"=",
"append",
"(",
"keys",
",",
"k",
")",
"\n",
"}",
"\n",
"}",
"\n",
"for",
"k",
":=",
"range",
"configMap",
".",
"BinaryData",
"{",
"if",
"filter",
".",
"Len",
"(",
")",
"==",
"0",
"||",
"filter",
".",
"Has",
"(",
"k",
")",
"{",
"keys",
"=",
"append",
"(",
"keys",
",",
"k",
")",
"\n",
"}",
"\n",
"}",
"\n",
"search",
".",
"Delete",
"(",
"keys",
"...",
")",
"\n",
"if",
"search",
".",
"Len",
"(",
")",
"!=",
"0",
"{",
"// not all the provided keys in filter were found",
"return",
"false",
"\n",
"}",
"\n",
"sort",
".",
"Strings",
"(",
"keys",
")",
"\n",
"for",
"_",
",",
"k",
":=",
"range",
"keys",
"{",
"io",
".",
"WriteString",
"(",
"h",
",",
"k",
")",
"// nolint: gosec, errcheck",
"\n",
"h",
".",
"Write",
"(",
"[",
"]",
"byte",
"{",
"0",
"}",
")",
"// nolint: gosec, errcheck",
"\n\n",
"// The key is either in Data or BinaryData",
"data",
",",
"inData",
":=",
"configMap",
".",
"Data",
"[",
"k",
"]",
"\n",
"if",
"inData",
"{",
"io",
".",
"WriteString",
"(",
"h",
",",
"data",
")",
"// nolint: gosec, errcheck",
"\n",
"}",
"else",
"{",
"binaryData",
":=",
"configMap",
".",
"BinaryData",
"[",
"k",
"]",
"\n",
"h",
".",
"Write",
"(",
"binaryData",
")",
"// nolint: gosec, errcheck",
"\n",
"}",
"\n\n",
"h",
".",
"Write",
"(",
"[",
"]",
"byte",
"{",
"0",
"}",
")",
"// nolint: gosec, errcheck",
"\n",
"}",
"\n\n",
"return",
"true",
"\n",
"}"
] |
// HashConfigMap hashes the sorted values in the ConfigMap in sorted order
// with a NUL as a separator character between and within pairs of key + value.
|
[
"HashConfigMap",
"hashes",
"the",
"sorted",
"values",
"in",
"the",
"ConfigMap",
"in",
"sorted",
"order",
"with",
"a",
"NUL",
"as",
"a",
"separator",
"character",
"between",
"and",
"within",
"pairs",
"of",
"key",
"+",
"value",
"."
] |
e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438
|
https://github.com/atlassian/smith/blob/e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438/pkg/specchecker/hash.go#L55-L91
|
18,224 |
atlassian/smith
|
pkg/specchecker/hash.go
|
HashSecret
|
func HashSecret(secret *core_v1.Secret, h hash.Hash, filter sets.String) bool {
keys := make([]string, 0, len(secret.Data))
search := sets.NewString(filter.UnsortedList()...)
for k := range secret.Data {
if filter.Len() == 0 || filter.Has(k) {
keys = append(keys, k)
}
}
search.Delete(keys...)
if search.Len() != 0 {
// not all the provided keys in filter were found
return false
}
sort.Strings(keys)
for _, k := range keys {
io.WriteString(h, k) // nolint: gosec, errcheck
h.Write([]byte{0}) // nolint: gosec, errcheck
h.Write(secret.Data[k]) // nolint: gosec, errcheck
h.Write([]byte{0}) // nolint: gosec, errcheck
}
return true
}
|
go
|
func HashSecret(secret *core_v1.Secret, h hash.Hash, filter sets.String) bool {
keys := make([]string, 0, len(secret.Data))
search := sets.NewString(filter.UnsortedList()...)
for k := range secret.Data {
if filter.Len() == 0 || filter.Has(k) {
keys = append(keys, k)
}
}
search.Delete(keys...)
if search.Len() != 0 {
// not all the provided keys in filter were found
return false
}
sort.Strings(keys)
for _, k := range keys {
io.WriteString(h, k) // nolint: gosec, errcheck
h.Write([]byte{0}) // nolint: gosec, errcheck
h.Write(secret.Data[k]) // nolint: gosec, errcheck
h.Write([]byte{0}) // nolint: gosec, errcheck
}
return true
}
|
[
"func",
"HashSecret",
"(",
"secret",
"*",
"core_v1",
".",
"Secret",
",",
"h",
"hash",
".",
"Hash",
",",
"filter",
"sets",
".",
"String",
")",
"bool",
"{",
"keys",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"len",
"(",
"secret",
".",
"Data",
")",
")",
"\n",
"search",
":=",
"sets",
".",
"NewString",
"(",
"filter",
".",
"UnsortedList",
"(",
")",
"...",
")",
"\n",
"for",
"k",
":=",
"range",
"secret",
".",
"Data",
"{",
"if",
"filter",
".",
"Len",
"(",
")",
"==",
"0",
"||",
"filter",
".",
"Has",
"(",
"k",
")",
"{",
"keys",
"=",
"append",
"(",
"keys",
",",
"k",
")",
"\n",
"}",
"\n",
"}",
"\n",
"search",
".",
"Delete",
"(",
"keys",
"...",
")",
"\n",
"if",
"search",
".",
"Len",
"(",
")",
"!=",
"0",
"{",
"// not all the provided keys in filter were found",
"return",
"false",
"\n",
"}",
"\n",
"sort",
".",
"Strings",
"(",
"keys",
")",
"\n",
"for",
"_",
",",
"k",
":=",
"range",
"keys",
"{",
"io",
".",
"WriteString",
"(",
"h",
",",
"k",
")",
"// nolint: gosec, errcheck",
"\n",
"h",
".",
"Write",
"(",
"[",
"]",
"byte",
"{",
"0",
"}",
")",
"// nolint: gosec, errcheck",
"\n",
"h",
".",
"Write",
"(",
"secret",
".",
"Data",
"[",
"k",
"]",
")",
"// nolint: gosec, errcheck",
"\n",
"h",
".",
"Write",
"(",
"[",
"]",
"byte",
"{",
"0",
"}",
")",
"// nolint: gosec, errcheck",
"\n",
"}",
"\n\n",
"return",
"true",
"\n",
"}"
] |
// HashSecret hashes the sorted values in the secret in sorted order
// with a NUL as a separator character between and within pairs of key + value.
|
[
"HashSecret",
"hashes",
"the",
"sorted",
"values",
"in",
"the",
"secret",
"in",
"sorted",
"order",
"with",
"a",
"NUL",
"as",
"a",
"separator",
"character",
"between",
"and",
"within",
"pairs",
"of",
"key",
"+",
"value",
"."
] |
e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438
|
https://github.com/atlassian/smith/blob/e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438/pkg/specchecker/hash.go#L95-L117
|
18,225 |
atlassian/smith
|
pkg/client/clientset_generated/clientset/typed/smith/v1/bundle.go
|
newBundles
|
func newBundles(c *SmithV1Client, namespace string) *bundles {
return &bundles{
client: c.RESTClient(),
ns: namespace,
}
}
|
go
|
func newBundles(c *SmithV1Client, namespace string) *bundles {
return &bundles{
client: c.RESTClient(),
ns: namespace,
}
}
|
[
"func",
"newBundles",
"(",
"c",
"*",
"SmithV1Client",
",",
"namespace",
"string",
")",
"*",
"bundles",
"{",
"return",
"&",
"bundles",
"{",
"client",
":",
"c",
".",
"RESTClient",
"(",
")",
",",
"ns",
":",
"namespace",
",",
"}",
"\n",
"}"
] |
// newBundles returns a Bundles
|
[
"newBundles",
"returns",
"a",
"Bundles"
] |
e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438
|
https://github.com/atlassian/smith/blob/e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438/pkg/client/clientset_generated/clientset/typed/smith/v1/bundle.go#L45-L50
|
18,226 |
atlassian/smith
|
pkg/resources/crd_helpers.go
|
IsCrdConditionTrue
|
func IsCrdConditionTrue(crd *apiext_v1b1.CustomResourceDefinition, conditionType apiext_v1b1.CustomResourceDefinitionConditionType) bool {
return IsCrdConditionPresentAndEqual(crd, conditionType, apiext_v1b1.ConditionTrue)
}
|
go
|
func IsCrdConditionTrue(crd *apiext_v1b1.CustomResourceDefinition, conditionType apiext_v1b1.CustomResourceDefinitionConditionType) bool {
return IsCrdConditionPresentAndEqual(crd, conditionType, apiext_v1b1.ConditionTrue)
}
|
[
"func",
"IsCrdConditionTrue",
"(",
"crd",
"*",
"apiext_v1b1",
".",
"CustomResourceDefinition",
",",
"conditionType",
"apiext_v1b1",
".",
"CustomResourceDefinitionConditionType",
")",
"bool",
"{",
"return",
"IsCrdConditionPresentAndEqual",
"(",
"crd",
",",
"conditionType",
",",
"apiext_v1b1",
".",
"ConditionTrue",
")",
"\n",
"}"
] |
// IsCrdConditionTrue indicates if the condition is present and strictly true
|
[
"IsCrdConditionTrue",
"indicates",
"if",
"the",
"condition",
"is",
"present",
"and",
"strictly",
"true"
] |
e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438
|
https://github.com/atlassian/smith/blob/e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438/pkg/resources/crd_helpers.go#L133-L135
|
18,227 |
atlassian/smith
|
pkg/store/multi_basic.go
|
AddInformer
|
func (s *MultiBasic) AddInformer(gvk schema.GroupVersionKind, informer cache.SharedIndexInformer) error {
s.mx.Lock()
defer s.mx.Unlock()
if _, ok := s.informers[gvk]; ok {
return errors.New("informer is already registered")
}
s.informers[gvk] = informer
return nil
}
|
go
|
func (s *MultiBasic) AddInformer(gvk schema.GroupVersionKind, informer cache.SharedIndexInformer) error {
s.mx.Lock()
defer s.mx.Unlock()
if _, ok := s.informers[gvk]; ok {
return errors.New("informer is already registered")
}
s.informers[gvk] = informer
return nil
}
|
[
"func",
"(",
"s",
"*",
"MultiBasic",
")",
"AddInformer",
"(",
"gvk",
"schema",
".",
"GroupVersionKind",
",",
"informer",
"cache",
".",
"SharedIndexInformer",
")",
"error",
"{",
"s",
".",
"mx",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"mx",
".",
"Unlock",
"(",
")",
"\n",
"if",
"_",
",",
"ok",
":=",
"s",
".",
"informers",
"[",
"gvk",
"]",
";",
"ok",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"s",
".",
"informers",
"[",
"gvk",
"]",
"=",
"informer",
"\n",
"return",
"nil",
"\n",
"}"
] |
// AddInformer adds an Informer to the store.
|
[
"AddInformer",
"adds",
"an",
"Informer",
"to",
"the",
"store",
"."
] |
e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438
|
https://github.com/atlassian/smith/blob/e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438/pkg/store/multi_basic.go#L25-L33
|
18,228 |
atlassian/smith
|
pkg/store/multi_basic.go
|
GetInformers
|
func (s *MultiBasic) GetInformers() map[schema.GroupVersionKind]cache.SharedIndexInformer {
s.mx.RLock()
defer s.mx.RUnlock()
informers := make(map[schema.GroupVersionKind]cache.SharedIndexInformer, len(s.informers))
for gvk, inf := range s.informers {
informers[gvk] = inf
}
return informers
}
|
go
|
func (s *MultiBasic) GetInformers() map[schema.GroupVersionKind]cache.SharedIndexInformer {
s.mx.RLock()
defer s.mx.RUnlock()
informers := make(map[schema.GroupVersionKind]cache.SharedIndexInformer, len(s.informers))
for gvk, inf := range s.informers {
informers[gvk] = inf
}
return informers
}
|
[
"func",
"(",
"s",
"*",
"MultiBasic",
")",
"GetInformers",
"(",
")",
"map",
"[",
"schema",
".",
"GroupVersionKind",
"]",
"cache",
".",
"SharedIndexInformer",
"{",
"s",
".",
"mx",
".",
"RLock",
"(",
")",
"\n",
"defer",
"s",
".",
"mx",
".",
"RUnlock",
"(",
")",
"\n",
"informers",
":=",
"make",
"(",
"map",
"[",
"schema",
".",
"GroupVersionKind",
"]",
"cache",
".",
"SharedIndexInformer",
",",
"len",
"(",
"s",
".",
"informers",
")",
")",
"\n",
"for",
"gvk",
",",
"inf",
":=",
"range",
"s",
".",
"informers",
"{",
"informers",
"[",
"gvk",
"]",
"=",
"inf",
"\n",
"}",
"\n",
"return",
"informers",
"\n",
"}"
] |
// GetInformers gets all registered Informers.
|
[
"GetInformers",
"gets",
"all",
"registered",
"Informers",
"."
] |
e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438
|
https://github.com/atlassian/smith/blob/e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438/pkg/store/multi_basic.go#L46-L54
|
18,229 |
atlassian/smith
|
pkg/store/multi_basic.go
|
Get
|
func (s *MultiBasic) Get(gvk schema.GroupVersionKind, namespace, name string) (obj runtime.Object, exists bool, e error) {
var informer cache.SharedIndexInformer
func() {
s.mx.RLock()
defer s.mx.RUnlock()
informer = s.informers[gvk]
}()
if informer == nil {
return nil, false, errors.Errorf("no informer for %s is registered", gvk)
}
return s.getFromIndexer(informer.GetIndexer(), gvk, namespace, name)
}
|
go
|
func (s *MultiBasic) Get(gvk schema.GroupVersionKind, namespace, name string) (obj runtime.Object, exists bool, e error) {
var informer cache.SharedIndexInformer
func() {
s.mx.RLock()
defer s.mx.RUnlock()
informer = s.informers[gvk]
}()
if informer == nil {
return nil, false, errors.Errorf("no informer for %s is registered", gvk)
}
return s.getFromIndexer(informer.GetIndexer(), gvk, namespace, name)
}
|
[
"func",
"(",
"s",
"*",
"MultiBasic",
")",
"Get",
"(",
"gvk",
"schema",
".",
"GroupVersionKind",
",",
"namespace",
",",
"name",
"string",
")",
"(",
"obj",
"runtime",
".",
"Object",
",",
"exists",
"bool",
",",
"e",
"error",
")",
"{",
"var",
"informer",
"cache",
".",
"SharedIndexInformer",
"\n",
"func",
"(",
")",
"{",
"s",
".",
"mx",
".",
"RLock",
"(",
")",
"\n",
"defer",
"s",
".",
"mx",
".",
"RUnlock",
"(",
")",
"\n",
"informer",
"=",
"s",
".",
"informers",
"[",
"gvk",
"]",
"\n",
"}",
"(",
")",
"\n",
"if",
"informer",
"==",
"nil",
"{",
"return",
"nil",
",",
"false",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"gvk",
")",
"\n",
"}",
"\n",
"return",
"s",
".",
"getFromIndexer",
"(",
"informer",
".",
"GetIndexer",
"(",
")",
",",
"gvk",
",",
"namespace",
",",
"name",
")",
"\n",
"}"
] |
// Get looks up object of specified GVK in the specified namespace by name.
// A deep copy of the object is returned so it is safe to modify it.
|
[
"Get",
"looks",
"up",
"object",
"of",
"specified",
"GVK",
"in",
"the",
"specified",
"namespace",
"by",
"name",
".",
"A",
"deep",
"copy",
"of",
"the",
"object",
"is",
"returned",
"so",
"it",
"is",
"safe",
"to",
"modify",
"it",
"."
] |
e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438
|
https://github.com/atlassian/smith/blob/e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438/pkg/store/multi_basic.go#L58-L69
|
18,230 |
atlassian/smith
|
pkg/specchecker/checker.go
|
BeforeCreate
|
func (c *Checker) BeforeCreate(logger *zap.Logger, spec *unstructured.Unstructured) (*unstructured.Unstructured /*updatedSpec*/, error) {
processor, ok := c.KnownTypes[spec.GroupVersionKind().GroupKind()]
if !ok {
return spec, nil
}
ctx := &Context{
Logger: logger,
Store: c.Store,
}
updatedSpec, err := processor.BeforeCreate(ctx, spec)
if err != nil {
return nil, errors.Wrap(err, "failed to pre-process object specification")
}
return util.RuntimeToUnstructured(updatedSpec)
}
|
go
|
func (c *Checker) BeforeCreate(logger *zap.Logger, spec *unstructured.Unstructured) (*unstructured.Unstructured /*updatedSpec*/, error) {
processor, ok := c.KnownTypes[spec.GroupVersionKind().GroupKind()]
if !ok {
return spec, nil
}
ctx := &Context{
Logger: logger,
Store: c.Store,
}
updatedSpec, err := processor.BeforeCreate(ctx, spec)
if err != nil {
return nil, errors.Wrap(err, "failed to pre-process object specification")
}
return util.RuntimeToUnstructured(updatedSpec)
}
|
[
"func",
"(",
"c",
"*",
"Checker",
")",
"BeforeCreate",
"(",
"logger",
"*",
"zap",
".",
"Logger",
",",
"spec",
"*",
"unstructured",
".",
"Unstructured",
")",
"(",
"*",
"unstructured",
".",
"Unstructured",
"/*updatedSpec*/",
",",
"error",
")",
"{",
"processor",
",",
"ok",
":=",
"c",
".",
"KnownTypes",
"[",
"spec",
".",
"GroupVersionKind",
"(",
")",
".",
"GroupKind",
"(",
")",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"spec",
",",
"nil",
"\n",
"}",
"\n",
"ctx",
":=",
"&",
"Context",
"{",
"Logger",
":",
"logger",
",",
"Store",
":",
"c",
".",
"Store",
",",
"}",
"\n",
"updatedSpec",
",",
"err",
":=",
"processor",
".",
"BeforeCreate",
"(",
"ctx",
",",
"spec",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"util",
".",
"RuntimeToUnstructured",
"(",
"updatedSpec",
")",
"\n",
"}"
] |
// BeforeCreate pre-processes object specification and returns an updated version.
|
[
"BeforeCreate",
"pre",
"-",
"processes",
"object",
"specification",
"and",
"returns",
"an",
"updated",
"version",
"."
] |
e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438
|
https://github.com/atlassian/smith/blob/e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438/pkg/specchecker/checker.go#L38-L52
|
18,231 |
atlassian/smith
|
pkg/specchecker/builtin/process_service_instance.go
|
setSecretParametersChecksumAnnotation
|
func (s serviceInstance) setSecretParametersChecksumAnnotation(ctx *specchecker.Context, spec, actual *sc_v1b1.ServiceInstance) error {
if spec.Annotations[SecretParametersChecksumAnnotation] == Disabled {
return nil
}
var previousEncodedChecksum string
var updateCount int64
if actual != nil {
previousEncodedChecksum = actual.Annotations[SecretParametersChecksumAnnotation]
updateCount = actual.Spec.UpdateRequests
}
checkSum, err := s.calculateNewServiceInstanceCheckSum(ctx, spec)
if err != nil {
return errors.Wrap(err, "failed to generate new checksum")
}
if actual != nil && checkSum != previousEncodedChecksum {
spec.Spec.UpdateRequests = updateCount + 1
}
s.setInstanceAnnotation(spec, checkSum)
return nil
}
|
go
|
func (s serviceInstance) setSecretParametersChecksumAnnotation(ctx *specchecker.Context, spec, actual *sc_v1b1.ServiceInstance) error {
if spec.Annotations[SecretParametersChecksumAnnotation] == Disabled {
return nil
}
var previousEncodedChecksum string
var updateCount int64
if actual != nil {
previousEncodedChecksum = actual.Annotations[SecretParametersChecksumAnnotation]
updateCount = actual.Spec.UpdateRequests
}
checkSum, err := s.calculateNewServiceInstanceCheckSum(ctx, spec)
if err != nil {
return errors.Wrap(err, "failed to generate new checksum")
}
if actual != nil && checkSum != previousEncodedChecksum {
spec.Spec.UpdateRequests = updateCount + 1
}
s.setInstanceAnnotation(spec, checkSum)
return nil
}
|
[
"func",
"(",
"s",
"serviceInstance",
")",
"setSecretParametersChecksumAnnotation",
"(",
"ctx",
"*",
"specchecker",
".",
"Context",
",",
"spec",
",",
"actual",
"*",
"sc_v1b1",
".",
"ServiceInstance",
")",
"error",
"{",
"if",
"spec",
".",
"Annotations",
"[",
"SecretParametersChecksumAnnotation",
"]",
"==",
"Disabled",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"var",
"previousEncodedChecksum",
"string",
"\n",
"var",
"updateCount",
"int64",
"\n\n",
"if",
"actual",
"!=",
"nil",
"{",
"previousEncodedChecksum",
"=",
"actual",
".",
"Annotations",
"[",
"SecretParametersChecksumAnnotation",
"]",
"\n",
"updateCount",
"=",
"actual",
".",
"Spec",
".",
"UpdateRequests",
"\n",
"}",
"\n\n",
"checkSum",
",",
"err",
":=",
"s",
".",
"calculateNewServiceInstanceCheckSum",
"(",
"ctx",
",",
"spec",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"actual",
"!=",
"nil",
"&&",
"checkSum",
"!=",
"previousEncodedChecksum",
"{",
"spec",
".",
"Spec",
".",
"UpdateRequests",
"=",
"updateCount",
"+",
"1",
"\n",
"}",
"\n\n",
"s",
".",
"setInstanceAnnotation",
"(",
"spec",
",",
"checkSum",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// works around the fact that service catalog does not know when to send an update request if the
// parameters section would change as the result of changing a secret referenced in parametersFrom. To
// do this we record the contents of all referenced secrets in an annotation, compare that annotations value
// each time a service instance is processed, and force UpdateRequests to a higher value when those secrets
// change to trigger service catalog to send an update request.
//
// The annotation is only ever added to the spec object not the actual object. The modified spec is treated as
// if the user manually set the annotation. The annotation is always set to a value, even if no
// secrets referenced.
//
// This can be disabled by adding the annotation with the value 'disabled'
|
[
"works",
"around",
"the",
"fact",
"that",
"service",
"catalog",
"does",
"not",
"know",
"when",
"to",
"send",
"an",
"update",
"request",
"if",
"the",
"parameters",
"section",
"would",
"change",
"as",
"the",
"result",
"of",
"changing",
"a",
"secret",
"referenced",
"in",
"parametersFrom",
".",
"To",
"do",
"this",
"we",
"record",
"the",
"contents",
"of",
"all",
"referenced",
"secrets",
"in",
"an",
"annotation",
"compare",
"that",
"annotations",
"value",
"each",
"time",
"a",
"service",
"instance",
"is",
"processed",
"and",
"force",
"UpdateRequests",
"to",
"a",
"higher",
"value",
"when",
"those",
"secrets",
"change",
"to",
"trigger",
"service",
"catalog",
"to",
"send",
"an",
"update",
"request",
".",
"The",
"annotation",
"is",
"only",
"ever",
"added",
"to",
"the",
"spec",
"object",
"not",
"the",
"actual",
"object",
".",
"The",
"modified",
"spec",
"is",
"treated",
"as",
"if",
"the",
"user",
"manually",
"set",
"the",
"annotation",
".",
"The",
"annotation",
"is",
"always",
"set",
"to",
"a",
"value",
"even",
"if",
"no",
"secrets",
"referenced",
".",
"This",
"can",
"be",
"disabled",
"by",
"adding",
"the",
"annotation",
"with",
"the",
"value",
"disabled"
] |
e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438
|
https://github.com/atlassian/smith/blob/e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438/pkg/specchecker/builtin/process_service_instance.go#L82-L106
|
18,232 |
atlassian/smith
|
pkg/specchecker/builtin/process_deployment.go
|
setLastAppliedReplicasAnnotation
|
func (deployment) setLastAppliedReplicasAnnotation(ctx *specchecker.Context, spec, actual *apps_v1.Deployment) {
if spec.Annotations[LastAppliedReplicasAnnotation] == Disabled {
return
}
if spec.Spec.Replicas == nil {
var one int32 = 1
spec.Spec.Replicas = &one
}
specReplicas := *spec.Spec.Replicas
if actual == nil {
// add LastAppliedReplicas annotation if it doesn't exist
spec.Annotations[LastAppliedReplicasAnnotation] = strconv.Itoa(int(specReplicas))
return
}
lastAppliedReplicasConf, ok := actual.Annotations[LastAppliedReplicasAnnotation]
if !ok {
// add LastAppliedReplicas annotation if it doesn't exist
spec.Annotations[LastAppliedReplicasAnnotation] = strconv.Itoa(int(specReplicas))
return
}
// Parse last applied replicas from running config's annotation
// overrides with current replicas inside spec if parsing failure
lastAppliedReplicas, err := strconv.Atoi(strings.TrimSpace(lastAppliedReplicasConf))
if err != nil {
ctx.Logger.Warn("Overriding last applied replicas annotation due to parsing failure", zap.Error(err))
spec.Annotations[LastAppliedReplicasAnnotation] = strconv.Itoa(int(specReplicas))
return
}
if specReplicas == int32(lastAppliedReplicas) {
// spec not changed => use actual running config if it exists
// since it might be updated by other controller like HPA
// otherwise use spec replicas config
if actual.Spec.Replicas != nil {
*spec.Spec.Replicas = *actual.Spec.Replicas
}
} else {
// spec changed => update annotations and use spec replicas config
spec.Annotations[LastAppliedReplicasAnnotation] = strconv.Itoa(int(specReplicas))
}
}
|
go
|
func (deployment) setLastAppliedReplicasAnnotation(ctx *specchecker.Context, spec, actual *apps_v1.Deployment) {
if spec.Annotations[LastAppliedReplicasAnnotation] == Disabled {
return
}
if spec.Spec.Replicas == nil {
var one int32 = 1
spec.Spec.Replicas = &one
}
specReplicas := *spec.Spec.Replicas
if actual == nil {
// add LastAppliedReplicas annotation if it doesn't exist
spec.Annotations[LastAppliedReplicasAnnotation] = strconv.Itoa(int(specReplicas))
return
}
lastAppliedReplicasConf, ok := actual.Annotations[LastAppliedReplicasAnnotation]
if !ok {
// add LastAppliedReplicas annotation if it doesn't exist
spec.Annotations[LastAppliedReplicasAnnotation] = strconv.Itoa(int(specReplicas))
return
}
// Parse last applied replicas from running config's annotation
// overrides with current replicas inside spec if parsing failure
lastAppliedReplicas, err := strconv.Atoi(strings.TrimSpace(lastAppliedReplicasConf))
if err != nil {
ctx.Logger.Warn("Overriding last applied replicas annotation due to parsing failure", zap.Error(err))
spec.Annotations[LastAppliedReplicasAnnotation] = strconv.Itoa(int(specReplicas))
return
}
if specReplicas == int32(lastAppliedReplicas) {
// spec not changed => use actual running config if it exists
// since it might be updated by other controller like HPA
// otherwise use spec replicas config
if actual.Spec.Replicas != nil {
*spec.Spec.Replicas = *actual.Spec.Replicas
}
} else {
// spec changed => update annotations and use spec replicas config
spec.Annotations[LastAppliedReplicasAnnotation] = strconv.Itoa(int(specReplicas))
}
}
|
[
"func",
"(",
"deployment",
")",
"setLastAppliedReplicasAnnotation",
"(",
"ctx",
"*",
"specchecker",
".",
"Context",
",",
"spec",
",",
"actual",
"*",
"apps_v1",
".",
"Deployment",
")",
"{",
"if",
"spec",
".",
"Annotations",
"[",
"LastAppliedReplicasAnnotation",
"]",
"==",
"Disabled",
"{",
"return",
"\n",
"}",
"\n\n",
"if",
"spec",
".",
"Spec",
".",
"Replicas",
"==",
"nil",
"{",
"var",
"one",
"int32",
"=",
"1",
"\n",
"spec",
".",
"Spec",
".",
"Replicas",
"=",
"&",
"one",
"\n",
"}",
"\n\n",
"specReplicas",
":=",
"*",
"spec",
".",
"Spec",
".",
"Replicas",
"\n",
"if",
"actual",
"==",
"nil",
"{",
"// add LastAppliedReplicas annotation if it doesn't exist",
"spec",
".",
"Annotations",
"[",
"LastAppliedReplicasAnnotation",
"]",
"=",
"strconv",
".",
"Itoa",
"(",
"int",
"(",
"specReplicas",
")",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"lastAppliedReplicasConf",
",",
"ok",
":=",
"actual",
".",
"Annotations",
"[",
"LastAppliedReplicasAnnotation",
"]",
"\n",
"if",
"!",
"ok",
"{",
"// add LastAppliedReplicas annotation if it doesn't exist",
"spec",
".",
"Annotations",
"[",
"LastAppliedReplicasAnnotation",
"]",
"=",
"strconv",
".",
"Itoa",
"(",
"int",
"(",
"specReplicas",
")",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"// Parse last applied replicas from running config's annotation",
"// overrides with current replicas inside spec if parsing failure",
"lastAppliedReplicas",
",",
"err",
":=",
"strconv",
".",
"Atoi",
"(",
"strings",
".",
"TrimSpace",
"(",
"lastAppliedReplicasConf",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"ctx",
".",
"Logger",
".",
"Warn",
"(",
"\"",
"\"",
",",
"zap",
".",
"Error",
"(",
"err",
")",
")",
"\n",
"spec",
".",
"Annotations",
"[",
"LastAppliedReplicasAnnotation",
"]",
"=",
"strconv",
".",
"Itoa",
"(",
"int",
"(",
"specReplicas",
")",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"if",
"specReplicas",
"==",
"int32",
"(",
"lastAppliedReplicas",
")",
"{",
"// spec not changed => use actual running config if it exists",
"// since it might be updated by other controller like HPA",
"// otherwise use spec replicas config",
"if",
"actual",
".",
"Spec",
".",
"Replicas",
"!=",
"nil",
"{",
"*",
"spec",
".",
"Spec",
".",
"Replicas",
"=",
"*",
"actual",
".",
"Spec",
".",
"Replicas",
"\n",
"}",
"\n",
"}",
"else",
"{",
"// spec changed => update annotations and use spec replicas config",
"spec",
".",
"Annotations",
"[",
"LastAppliedReplicasAnnotation",
"]",
"=",
"strconv",
".",
"Itoa",
"(",
"int",
"(",
"specReplicas",
")",
")",
"\n",
"}",
"\n",
"}"
] |
// setLastAppliedReplicasAnnotation updates replicas based on LastAppliedReplicas annotation and running config
// to avoid conflicts with other controllers like HPA.
// actual may be nil.
|
[
"setLastAppliedReplicasAnnotation",
"updates",
"replicas",
"based",
"on",
"LastAppliedReplicas",
"annotation",
"and",
"running",
"config",
"to",
"avoid",
"conflicts",
"with",
"other",
"controllers",
"like",
"HPA",
".",
"actual",
"may",
"be",
"nil",
"."
] |
e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438
|
https://github.com/atlassian/smith/blob/e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438/pkg/specchecker/builtin/process_deployment.go#L76-L120
|
18,233 |
atlassian/smith
|
pkg/client/clientset_generated/clientset/fake/clientset_generated.go
|
SmithV1
|
func (c *Clientset) SmithV1() smithv1.SmithV1Interface {
return &fakesmithv1.FakeSmithV1{Fake: &c.Fake}
}
|
go
|
func (c *Clientset) SmithV1() smithv1.SmithV1Interface {
return &fakesmithv1.FakeSmithV1{Fake: &c.Fake}
}
|
[
"func",
"(",
"c",
"*",
"Clientset",
")",
"SmithV1",
"(",
")",
"smithv1",
".",
"SmithV1Interface",
"{",
"return",
"&",
"fakesmithv1",
".",
"FakeSmithV1",
"{",
"Fake",
":",
"&",
"c",
".",
"Fake",
"}",
"\n",
"}"
] |
// SmithV1 retrieves the SmithV1Client
|
[
"SmithV1",
"retrieves",
"the",
"SmithV1Client"
] |
e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438
|
https://github.com/atlassian/smith/blob/e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438/pkg/client/clientset_generated/clientset/fake/clientset_generated.go#L61-L63
|
18,234 |
atlassian/smith
|
pkg/client/clientset_generated/clientset/fake/clientset_generated.go
|
Smith
|
func (c *Clientset) Smith() smithv1.SmithV1Interface {
return &fakesmithv1.FakeSmithV1{Fake: &c.Fake}
}
|
go
|
func (c *Clientset) Smith() smithv1.SmithV1Interface {
return &fakesmithv1.FakeSmithV1{Fake: &c.Fake}
}
|
[
"func",
"(",
"c",
"*",
"Clientset",
")",
"Smith",
"(",
")",
"smithv1",
".",
"SmithV1Interface",
"{",
"return",
"&",
"fakesmithv1",
".",
"FakeSmithV1",
"{",
"Fake",
":",
"&",
"c",
".",
"Fake",
"}",
"\n",
"}"
] |
// Smith retrieves the SmithV1Client
|
[
"Smith",
"retrieves",
"the",
"SmithV1Client"
] |
e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438
|
https://github.com/atlassian/smith/blob/e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438/pkg/client/clientset_generated/clientset/fake/clientset_generated.go#L66-L68
|
18,235 |
atlassian/smith
|
pkg/specchecker/builtin/process_util.go
|
setEmptyFieldsFromActual
|
func setEmptyFieldsFromActual(requested, actual interface{}, fields ...string) error {
requestedValue := reflect.ValueOf(requested).Elem()
actualValue := reflect.ValueOf(actual).Elem()
if requestedValue.Type() != actualValue.Type() {
return errors.Errorf("attempted to set fields from different types: %q from %q",
requestedValue, actualValue)
}
for _, field := range fields {
requestedField := requestedValue.FieldByName(field)
if !requestedField.IsValid() {
return errors.Errorf("no such field %q to cleanup", field)
}
actualField := actualValue.FieldByName(field)
if !actualField.IsValid() {
return errors.Errorf("no such field %q to cleanup", field)
}
if reflect.DeepEqual(requestedField.Interface(), reflect.Zero(requestedField.Type()).Interface()) {
requestedField.Set(actualField)
}
}
return nil
}
|
go
|
func setEmptyFieldsFromActual(requested, actual interface{}, fields ...string) error {
requestedValue := reflect.ValueOf(requested).Elem()
actualValue := reflect.ValueOf(actual).Elem()
if requestedValue.Type() != actualValue.Type() {
return errors.Errorf("attempted to set fields from different types: %q from %q",
requestedValue, actualValue)
}
for _, field := range fields {
requestedField := requestedValue.FieldByName(field)
if !requestedField.IsValid() {
return errors.Errorf("no such field %q to cleanup", field)
}
actualField := actualValue.FieldByName(field)
if !actualField.IsValid() {
return errors.Errorf("no such field %q to cleanup", field)
}
if reflect.DeepEqual(requestedField.Interface(), reflect.Zero(requestedField.Type()).Interface()) {
requestedField.Set(actualField)
}
}
return nil
}
|
[
"func",
"setEmptyFieldsFromActual",
"(",
"requested",
",",
"actual",
"interface",
"{",
"}",
",",
"fields",
"...",
"string",
")",
"error",
"{",
"requestedValue",
":=",
"reflect",
".",
"ValueOf",
"(",
"requested",
")",
".",
"Elem",
"(",
")",
"\n",
"actualValue",
":=",
"reflect",
".",
"ValueOf",
"(",
"actual",
")",
".",
"Elem",
"(",
")",
"\n\n",
"if",
"requestedValue",
".",
"Type",
"(",
")",
"!=",
"actualValue",
".",
"Type",
"(",
")",
"{",
"return",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"requestedValue",
",",
"actualValue",
")",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"field",
":=",
"range",
"fields",
"{",
"requestedField",
":=",
"requestedValue",
".",
"FieldByName",
"(",
"field",
")",
"\n",
"if",
"!",
"requestedField",
".",
"IsValid",
"(",
")",
"{",
"return",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"field",
")",
"\n",
"}",
"\n",
"actualField",
":=",
"actualValue",
".",
"FieldByName",
"(",
"field",
")",
"\n",
"if",
"!",
"actualField",
".",
"IsValid",
"(",
")",
"{",
"return",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"field",
")",
"\n",
"}",
"\n\n",
"if",
"reflect",
".",
"DeepEqual",
"(",
"requestedField",
".",
"Interface",
"(",
")",
",",
"reflect",
".",
"Zero",
"(",
"requestedField",
".",
"Type",
"(",
")",
")",
".",
"Interface",
"(",
")",
")",
"{",
"requestedField",
".",
"Set",
"(",
"actualField",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// setFieldsFromActual mutates the target with fields from the instantiated object,
// iff that field was not set in the original object.
|
[
"setFieldsFromActual",
"mutates",
"the",
"target",
"with",
"fields",
"from",
"the",
"instantiated",
"object",
"iff",
"that",
"field",
"was",
"not",
"set",
"in",
"the",
"original",
"object",
"."
] |
e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438
|
https://github.com/atlassian/smith/blob/e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438/pkg/specchecker/builtin/process_util.go#L28-L53
|
18,236 |
atlassian/smith
|
pkg/controller/bundlec/controller.go
|
Prepare
|
func (c *Controller) Prepare(crdInf cache.SharedIndexInformer, resourceInfs map[schema.GroupVersionKind]cache.SharedIndexInformer) error {
c.crdContext, c.crdContextCancel = context.WithCancel(context.Background())
crdInf.AddEventHandler(&crdEventHandler{
controller: c,
watchers: make(map[string]watchState),
})
deploymentInf := resourceInfs[apps_v1.SchemeGroupVersion.WithKind("Deployment")]
err := deploymentInf.AddIndexers(cache.Indexers{
byConfigMapNamespaceNameIndexName: deploymentByConfigMapNamespaceNameIndex,
bySecretNamespaceNameIndexName: deploymentBySecretNamespaceNameIndex,
})
if err != nil {
return errors.WithStack(err)
}
deploymentByIndex := deploymentInf.GetIndexer().ByIndex
// ConfigMap -> Deployment -> Bundle event propagation
configMapGVK := core_v1.SchemeGroupVersion.WithKind("ConfigMap")
configMapInf := resourceInfs[configMapGVK]
configMapInf.AddEventHandler(&handlers.LookupHandler{
Logger: c.Logger,
WorkQueue: c.WorkQueue,
Gvk: configMapGVK,
Lookup: c.lookupBundleByObjectByIndex(deploymentByIndex, byConfigMapNamespaceNameIndexName, byNamespaceNameIndexKey),
})
// Secret -> Deployment -> Bundle event propagation
secretGVK := core_v1.SchemeGroupVersion.WithKind("Secret")
secretInf := resourceInfs[secretGVK]
secretInf.AddEventHandler(&handlers.LookupHandler{
Logger: c.Logger,
WorkQueue: c.WorkQueue,
Gvk: secretGVK,
Lookup: c.lookupBundleByObjectByIndex(deploymentByIndex, bySecretNamespaceNameIndexName, byNamespaceNameIndexKey),
})
serviceInstanceInf, ok := resourceInfs[sc_v1b1.SchemeGroupVersion.WithKind("ServiceInstance")]
if ok { // Service Catalog support is enabled
// Secret -> ServiceInstance -> Bundle event propagation
err := serviceInstanceInf.AddIndexers(cache.Indexers{
bySecretNamespaceNameIndexName: serviceInstanceBySecretNamespaceNameIndex,
})
if err != nil {
return errors.WithStack(err)
}
serviceInstanceByIndex := serviceInstanceInf.GetIndexer().ByIndex
secretInf.AddEventHandler(&handlers.LookupHandler{
Logger: c.Logger,
WorkQueue: c.WorkQueue,
Gvk: secretGVK,
Lookup: c.lookupBundleByObjectByIndex(serviceInstanceByIndex, bySecretNamespaceNameIndexName, byNamespaceNameIndexKey),
})
// Secret -> ServiceBinding -> Bundle event propagation
serviceBindingInf := resourceInfs[sc_v1b1.SchemeGroupVersion.WithKind("ServiceBinding")]
err = serviceBindingInf.AddIndexers(cache.Indexers{
bySecretNamespaceNameIndexName: serviceBindingBySecretNamespaceNameIndex,
})
if err != nil {
return errors.WithStack(err)
}
serviceBindingByIndex := serviceBindingInf.GetIndexer().ByIndex
secretInf.AddEventHandler(&handlers.LookupHandler{
Logger: c.Logger,
WorkQueue: c.WorkQueue,
Gvk: secretGVK,
Lookup: c.lookupBundleByObjectByIndex(serviceBindingByIndex, bySecretNamespaceNameIndexName, byNamespaceNameIndexKey),
})
}
// Standard handler
for gvk, resourceInf := range resourceInfs {
resourceInf.AddEventHandler(&handlers.ControlledResourceHandler{
Logger: c.Logger,
WorkQueue: c.WorkQueue,
ControllerIndex: &controllerIndexAdapter{bundleStore: c.BundleStore},
ControllerGvk: smith_v1.BundleGVK,
Gvk: gvk,
})
}
return nil
}
|
go
|
func (c *Controller) Prepare(crdInf cache.SharedIndexInformer, resourceInfs map[schema.GroupVersionKind]cache.SharedIndexInformer) error {
c.crdContext, c.crdContextCancel = context.WithCancel(context.Background())
crdInf.AddEventHandler(&crdEventHandler{
controller: c,
watchers: make(map[string]watchState),
})
deploymentInf := resourceInfs[apps_v1.SchemeGroupVersion.WithKind("Deployment")]
err := deploymentInf.AddIndexers(cache.Indexers{
byConfigMapNamespaceNameIndexName: deploymentByConfigMapNamespaceNameIndex,
bySecretNamespaceNameIndexName: deploymentBySecretNamespaceNameIndex,
})
if err != nil {
return errors.WithStack(err)
}
deploymentByIndex := deploymentInf.GetIndexer().ByIndex
// ConfigMap -> Deployment -> Bundle event propagation
configMapGVK := core_v1.SchemeGroupVersion.WithKind("ConfigMap")
configMapInf := resourceInfs[configMapGVK]
configMapInf.AddEventHandler(&handlers.LookupHandler{
Logger: c.Logger,
WorkQueue: c.WorkQueue,
Gvk: configMapGVK,
Lookup: c.lookupBundleByObjectByIndex(deploymentByIndex, byConfigMapNamespaceNameIndexName, byNamespaceNameIndexKey),
})
// Secret -> Deployment -> Bundle event propagation
secretGVK := core_v1.SchemeGroupVersion.WithKind("Secret")
secretInf := resourceInfs[secretGVK]
secretInf.AddEventHandler(&handlers.LookupHandler{
Logger: c.Logger,
WorkQueue: c.WorkQueue,
Gvk: secretGVK,
Lookup: c.lookupBundleByObjectByIndex(deploymentByIndex, bySecretNamespaceNameIndexName, byNamespaceNameIndexKey),
})
serviceInstanceInf, ok := resourceInfs[sc_v1b1.SchemeGroupVersion.WithKind("ServiceInstance")]
if ok { // Service Catalog support is enabled
// Secret -> ServiceInstance -> Bundle event propagation
err := serviceInstanceInf.AddIndexers(cache.Indexers{
bySecretNamespaceNameIndexName: serviceInstanceBySecretNamespaceNameIndex,
})
if err != nil {
return errors.WithStack(err)
}
serviceInstanceByIndex := serviceInstanceInf.GetIndexer().ByIndex
secretInf.AddEventHandler(&handlers.LookupHandler{
Logger: c.Logger,
WorkQueue: c.WorkQueue,
Gvk: secretGVK,
Lookup: c.lookupBundleByObjectByIndex(serviceInstanceByIndex, bySecretNamespaceNameIndexName, byNamespaceNameIndexKey),
})
// Secret -> ServiceBinding -> Bundle event propagation
serviceBindingInf := resourceInfs[sc_v1b1.SchemeGroupVersion.WithKind("ServiceBinding")]
err = serviceBindingInf.AddIndexers(cache.Indexers{
bySecretNamespaceNameIndexName: serviceBindingBySecretNamespaceNameIndex,
})
if err != nil {
return errors.WithStack(err)
}
serviceBindingByIndex := serviceBindingInf.GetIndexer().ByIndex
secretInf.AddEventHandler(&handlers.LookupHandler{
Logger: c.Logger,
WorkQueue: c.WorkQueue,
Gvk: secretGVK,
Lookup: c.lookupBundleByObjectByIndex(serviceBindingByIndex, bySecretNamespaceNameIndexName, byNamespaceNameIndexKey),
})
}
// Standard handler
for gvk, resourceInf := range resourceInfs {
resourceInf.AddEventHandler(&handlers.ControlledResourceHandler{
Logger: c.Logger,
WorkQueue: c.WorkQueue,
ControllerIndex: &controllerIndexAdapter{bundleStore: c.BundleStore},
ControllerGvk: smith_v1.BundleGVK,
Gvk: gvk,
})
}
return nil
}
|
[
"func",
"(",
"c",
"*",
"Controller",
")",
"Prepare",
"(",
"crdInf",
"cache",
".",
"SharedIndexInformer",
",",
"resourceInfs",
"map",
"[",
"schema",
".",
"GroupVersionKind",
"]",
"cache",
".",
"SharedIndexInformer",
")",
"error",
"{",
"c",
".",
"crdContext",
",",
"c",
".",
"crdContextCancel",
"=",
"context",
".",
"WithCancel",
"(",
"context",
".",
"Background",
"(",
")",
")",
"\n",
"crdInf",
".",
"AddEventHandler",
"(",
"&",
"crdEventHandler",
"{",
"controller",
":",
"c",
",",
"watchers",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"watchState",
")",
",",
"}",
")",
"\n",
"deploymentInf",
":=",
"resourceInfs",
"[",
"apps_v1",
".",
"SchemeGroupVersion",
".",
"WithKind",
"(",
"\"",
"\"",
")",
"]",
"\n",
"err",
":=",
"deploymentInf",
".",
"AddIndexers",
"(",
"cache",
".",
"Indexers",
"{",
"byConfigMapNamespaceNameIndexName",
":",
"deploymentByConfigMapNamespaceNameIndex",
",",
"bySecretNamespaceNameIndexName",
":",
"deploymentBySecretNamespaceNameIndex",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"WithStack",
"(",
"err",
")",
"\n",
"}",
"\n",
"deploymentByIndex",
":=",
"deploymentInf",
".",
"GetIndexer",
"(",
")",
".",
"ByIndex",
"\n",
"// ConfigMap -> Deployment -> Bundle event propagation",
"configMapGVK",
":=",
"core_v1",
".",
"SchemeGroupVersion",
".",
"WithKind",
"(",
"\"",
"\"",
")",
"\n",
"configMapInf",
":=",
"resourceInfs",
"[",
"configMapGVK",
"]",
"\n",
"configMapInf",
".",
"AddEventHandler",
"(",
"&",
"handlers",
".",
"LookupHandler",
"{",
"Logger",
":",
"c",
".",
"Logger",
",",
"WorkQueue",
":",
"c",
".",
"WorkQueue",
",",
"Gvk",
":",
"configMapGVK",
",",
"Lookup",
":",
"c",
".",
"lookupBundleByObjectByIndex",
"(",
"deploymentByIndex",
",",
"byConfigMapNamespaceNameIndexName",
",",
"byNamespaceNameIndexKey",
")",
",",
"}",
")",
"\n",
"// Secret -> Deployment -> Bundle event propagation",
"secretGVK",
":=",
"core_v1",
".",
"SchemeGroupVersion",
".",
"WithKind",
"(",
"\"",
"\"",
")",
"\n",
"secretInf",
":=",
"resourceInfs",
"[",
"secretGVK",
"]",
"\n",
"secretInf",
".",
"AddEventHandler",
"(",
"&",
"handlers",
".",
"LookupHandler",
"{",
"Logger",
":",
"c",
".",
"Logger",
",",
"WorkQueue",
":",
"c",
".",
"WorkQueue",
",",
"Gvk",
":",
"secretGVK",
",",
"Lookup",
":",
"c",
".",
"lookupBundleByObjectByIndex",
"(",
"deploymentByIndex",
",",
"bySecretNamespaceNameIndexName",
",",
"byNamespaceNameIndexKey",
")",
",",
"}",
")",
"\n",
"serviceInstanceInf",
",",
"ok",
":=",
"resourceInfs",
"[",
"sc_v1b1",
".",
"SchemeGroupVersion",
".",
"WithKind",
"(",
"\"",
"\"",
")",
"]",
"\n",
"if",
"ok",
"{",
"// Service Catalog support is enabled",
"// Secret -> ServiceInstance -> Bundle event propagation",
"err",
":=",
"serviceInstanceInf",
".",
"AddIndexers",
"(",
"cache",
".",
"Indexers",
"{",
"bySecretNamespaceNameIndexName",
":",
"serviceInstanceBySecretNamespaceNameIndex",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"WithStack",
"(",
"err",
")",
"\n",
"}",
"\n",
"serviceInstanceByIndex",
":=",
"serviceInstanceInf",
".",
"GetIndexer",
"(",
")",
".",
"ByIndex",
"\n",
"secretInf",
".",
"AddEventHandler",
"(",
"&",
"handlers",
".",
"LookupHandler",
"{",
"Logger",
":",
"c",
".",
"Logger",
",",
"WorkQueue",
":",
"c",
".",
"WorkQueue",
",",
"Gvk",
":",
"secretGVK",
",",
"Lookup",
":",
"c",
".",
"lookupBundleByObjectByIndex",
"(",
"serviceInstanceByIndex",
",",
"bySecretNamespaceNameIndexName",
",",
"byNamespaceNameIndexKey",
")",
",",
"}",
")",
"\n",
"// Secret -> ServiceBinding -> Bundle event propagation",
"serviceBindingInf",
":=",
"resourceInfs",
"[",
"sc_v1b1",
".",
"SchemeGroupVersion",
".",
"WithKind",
"(",
"\"",
"\"",
")",
"]",
"\n",
"err",
"=",
"serviceBindingInf",
".",
"AddIndexers",
"(",
"cache",
".",
"Indexers",
"{",
"bySecretNamespaceNameIndexName",
":",
"serviceBindingBySecretNamespaceNameIndex",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"WithStack",
"(",
"err",
")",
"\n",
"}",
"\n",
"serviceBindingByIndex",
":=",
"serviceBindingInf",
".",
"GetIndexer",
"(",
")",
".",
"ByIndex",
"\n",
"secretInf",
".",
"AddEventHandler",
"(",
"&",
"handlers",
".",
"LookupHandler",
"{",
"Logger",
":",
"c",
".",
"Logger",
",",
"WorkQueue",
":",
"c",
".",
"WorkQueue",
",",
"Gvk",
":",
"secretGVK",
",",
"Lookup",
":",
"c",
".",
"lookupBundleByObjectByIndex",
"(",
"serviceBindingByIndex",
",",
"bySecretNamespaceNameIndexName",
",",
"byNamespaceNameIndexKey",
")",
",",
"}",
")",
"\n",
"}",
"\n",
"// Standard handler",
"for",
"gvk",
",",
"resourceInf",
":=",
"range",
"resourceInfs",
"{",
"resourceInf",
".",
"AddEventHandler",
"(",
"&",
"handlers",
".",
"ControlledResourceHandler",
"{",
"Logger",
":",
"c",
".",
"Logger",
",",
"WorkQueue",
":",
"c",
".",
"WorkQueue",
",",
"ControllerIndex",
":",
"&",
"controllerIndexAdapter",
"{",
"bundleStore",
":",
"c",
".",
"BundleStore",
"}",
",",
"ControllerGvk",
":",
"smith_v1",
".",
"BundleGVK",
",",
"Gvk",
":",
"gvk",
",",
"}",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Prepare prepares the controller to be run.
|
[
"Prepare",
"prepares",
"the",
"controller",
"to",
"be",
"run",
"."
] |
e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438
|
https://github.com/atlassian/smith/blob/e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438/pkg/controller/bundlec/controller.go#L82-L158
|
18,237 |
atlassian/smith
|
pkg/controller/bundlec/controller.go
|
Run
|
func (c *Controller) Run(ctx context.Context) {
defer c.wg.Wait()
defer c.crdContextCancel() // should be executed after stopping is set to true
defer func() {
c.wgLock.Lock()
defer c.wgLock.Unlock()
c.stopping = true
}()
c.Logger.Info("Starting Bundle controller")
defer c.Logger.Info("Shutting down Bundle controller")
sink := core_v1_client.EventSinkImpl{
Interface: c.MainClient.CoreV1().Events(meta_v1.NamespaceNone),
}
recordingWatch := c.Broadcaster.StartRecordingToSink(&sink)
defer recordingWatch.Stop()
c.ReadyForWork()
<-ctx.Done()
}
|
go
|
func (c *Controller) Run(ctx context.Context) {
defer c.wg.Wait()
defer c.crdContextCancel() // should be executed after stopping is set to true
defer func() {
c.wgLock.Lock()
defer c.wgLock.Unlock()
c.stopping = true
}()
c.Logger.Info("Starting Bundle controller")
defer c.Logger.Info("Shutting down Bundle controller")
sink := core_v1_client.EventSinkImpl{
Interface: c.MainClient.CoreV1().Events(meta_v1.NamespaceNone),
}
recordingWatch := c.Broadcaster.StartRecordingToSink(&sink)
defer recordingWatch.Stop()
c.ReadyForWork()
<-ctx.Done()
}
|
[
"func",
"(",
"c",
"*",
"Controller",
")",
"Run",
"(",
"ctx",
"context",
".",
"Context",
")",
"{",
"defer",
"c",
".",
"wg",
".",
"Wait",
"(",
")",
"\n",
"defer",
"c",
".",
"crdContextCancel",
"(",
")",
"// should be executed after stopping is set to true",
"\n",
"defer",
"func",
"(",
")",
"{",
"c",
".",
"wgLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"wgLock",
".",
"Unlock",
"(",
")",
"\n",
"c",
".",
"stopping",
"=",
"true",
"\n",
"}",
"(",
")",
"\n\n",
"c",
".",
"Logger",
".",
"Info",
"(",
"\"",
"\"",
")",
"\n",
"defer",
"c",
".",
"Logger",
".",
"Info",
"(",
"\"",
"\"",
")",
"\n\n",
"sink",
":=",
"core_v1_client",
".",
"EventSinkImpl",
"{",
"Interface",
":",
"c",
".",
"MainClient",
".",
"CoreV1",
"(",
")",
".",
"Events",
"(",
"meta_v1",
".",
"NamespaceNone",
")",
",",
"}",
"\n",
"recordingWatch",
":=",
"c",
".",
"Broadcaster",
".",
"StartRecordingToSink",
"(",
"&",
"sink",
")",
"\n",
"defer",
"recordingWatch",
".",
"Stop",
"(",
")",
"\n\n",
"c",
".",
"ReadyForWork",
"(",
")",
"\n\n",
"<-",
"ctx",
".",
"Done",
"(",
")",
"\n",
"}"
] |
// Run begins watching and syncing.
// All informers must be synced before this method is invoked.
|
[
"Run",
"begins",
"watching",
"and",
"syncing",
".",
"All",
"informers",
"must",
"be",
"synced",
"before",
"this",
"method",
"is",
"invoked",
"."
] |
e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438
|
https://github.com/atlassian/smith/blob/e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438/pkg/controller/bundlec/controller.go#L162-L183
|
18,238 |
atlassian/smith
|
pkg/controller/bundlec/controller.go
|
lookupBundleByObjectByIndex
|
func (c *Controller) lookupBundleByObjectByIndex(byIndex byIndexFunc, indexName string, indexKey indexKeyFunc) func(runtime.Object) ([]runtime.Object, error) {
return func(obj runtime.Object) ([]runtime.Object /*bundles*/, error) {
// obj is an object that is referred by some other object that might be in a Bundle
objMeta := obj.(meta_v1.Object)
// find all object that reference this obj
objsFromIndex, err := byIndex(indexName, indexKey(objMeta.GetNamespace(), objMeta.GetName()))
if err != nil {
return nil, err
}
var bundles []runtime.Object
for _, objFromIndex := range objsFromIndex {
runtimeObjFromIndex := objFromIndex.(runtime.Object)
metaObjFromIndex := objFromIndex.(meta_v1.Object)
gvks, _, err := c.Scheme.ObjectKinds(runtimeObjFromIndex)
if err != nil {
// Log and continue to try to process other objects if there are any more in objsFromIndex
// This shouldn't happen normally
c.Logger.
With(zap.Error(err), logz.Namespace(metaObjFromIndex), logz.Object(metaObjFromIndex)).
Sugar().Errorf("Could not determine GVK of an object")
continue
}
gks := make(map[schema.GroupKind]struct{}, len(gvks)) // not clear if duplicates are allowed, so de-dupe
for _, gvk := range gvks {
gks[gvk.GroupKind()] = struct{}{}
}
// find all Bundles that contain this object
for gk := range gks {
bundlesForObject, err := c.BundleStore.GetBundlesByObject(gk, metaObjFromIndex.GetNamespace(), metaObjFromIndex.GetName())
if err != nil {
// Log and continue to try to process other GKs
c.Logger.
With(zap.Error(err), logz.Namespace(metaObjFromIndex), logz.Object(metaObjFromIndex)).
Sugar().Errorf("Failed to get Bundles by object")
continue
}
for _, bundle := range bundlesForObject {
bundles = append(bundles, bundle)
}
}
}
return bundles, nil
}
}
|
go
|
func (c *Controller) lookupBundleByObjectByIndex(byIndex byIndexFunc, indexName string, indexKey indexKeyFunc) func(runtime.Object) ([]runtime.Object, error) {
return func(obj runtime.Object) ([]runtime.Object /*bundles*/, error) {
// obj is an object that is referred by some other object that might be in a Bundle
objMeta := obj.(meta_v1.Object)
// find all object that reference this obj
objsFromIndex, err := byIndex(indexName, indexKey(objMeta.GetNamespace(), objMeta.GetName()))
if err != nil {
return nil, err
}
var bundles []runtime.Object
for _, objFromIndex := range objsFromIndex {
runtimeObjFromIndex := objFromIndex.(runtime.Object)
metaObjFromIndex := objFromIndex.(meta_v1.Object)
gvks, _, err := c.Scheme.ObjectKinds(runtimeObjFromIndex)
if err != nil {
// Log and continue to try to process other objects if there are any more in objsFromIndex
// This shouldn't happen normally
c.Logger.
With(zap.Error(err), logz.Namespace(metaObjFromIndex), logz.Object(metaObjFromIndex)).
Sugar().Errorf("Could not determine GVK of an object")
continue
}
gks := make(map[schema.GroupKind]struct{}, len(gvks)) // not clear if duplicates are allowed, so de-dupe
for _, gvk := range gvks {
gks[gvk.GroupKind()] = struct{}{}
}
// find all Bundles that contain this object
for gk := range gks {
bundlesForObject, err := c.BundleStore.GetBundlesByObject(gk, metaObjFromIndex.GetNamespace(), metaObjFromIndex.GetName())
if err != nil {
// Log and continue to try to process other GKs
c.Logger.
With(zap.Error(err), logz.Namespace(metaObjFromIndex), logz.Object(metaObjFromIndex)).
Sugar().Errorf("Failed to get Bundles by object")
continue
}
for _, bundle := range bundlesForObject {
bundles = append(bundles, bundle)
}
}
}
return bundles, nil
}
}
|
[
"func",
"(",
"c",
"*",
"Controller",
")",
"lookupBundleByObjectByIndex",
"(",
"byIndex",
"byIndexFunc",
",",
"indexName",
"string",
",",
"indexKey",
"indexKeyFunc",
")",
"func",
"(",
"runtime",
".",
"Object",
")",
"(",
"[",
"]",
"runtime",
".",
"Object",
",",
"error",
")",
"{",
"return",
"func",
"(",
"obj",
"runtime",
".",
"Object",
")",
"(",
"[",
"]",
"runtime",
".",
"Object",
"/*bundles*/",
",",
"error",
")",
"{",
"// obj is an object that is referred by some other object that might be in a Bundle",
"objMeta",
":=",
"obj",
".",
"(",
"meta_v1",
".",
"Object",
")",
"\n",
"// find all object that reference this obj",
"objsFromIndex",
",",
"err",
":=",
"byIndex",
"(",
"indexName",
",",
"indexKey",
"(",
"objMeta",
".",
"GetNamespace",
"(",
")",
",",
"objMeta",
".",
"GetName",
"(",
")",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"var",
"bundles",
"[",
"]",
"runtime",
".",
"Object",
"\n",
"for",
"_",
",",
"objFromIndex",
":=",
"range",
"objsFromIndex",
"{",
"runtimeObjFromIndex",
":=",
"objFromIndex",
".",
"(",
"runtime",
".",
"Object",
")",
"\n",
"metaObjFromIndex",
":=",
"objFromIndex",
".",
"(",
"meta_v1",
".",
"Object",
")",
"\n",
"gvks",
",",
"_",
",",
"err",
":=",
"c",
".",
"Scheme",
".",
"ObjectKinds",
"(",
"runtimeObjFromIndex",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"// Log and continue to try to process other objects if there are any more in objsFromIndex",
"// This shouldn't happen normally",
"c",
".",
"Logger",
".",
"With",
"(",
"zap",
".",
"Error",
"(",
"err",
")",
",",
"logz",
".",
"Namespace",
"(",
"metaObjFromIndex",
")",
",",
"logz",
".",
"Object",
"(",
"metaObjFromIndex",
")",
")",
".",
"Sugar",
"(",
")",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"gks",
":=",
"make",
"(",
"map",
"[",
"schema",
".",
"GroupKind",
"]",
"struct",
"{",
"}",
",",
"len",
"(",
"gvks",
")",
")",
"// not clear if duplicates are allowed, so de-dupe",
"\n",
"for",
"_",
",",
"gvk",
":=",
"range",
"gvks",
"{",
"gks",
"[",
"gvk",
".",
"GroupKind",
"(",
")",
"]",
"=",
"struct",
"{",
"}",
"{",
"}",
"\n",
"}",
"\n\n",
"// find all Bundles that contain this object",
"for",
"gk",
":=",
"range",
"gks",
"{",
"bundlesForObject",
",",
"err",
":=",
"c",
".",
"BundleStore",
".",
"GetBundlesByObject",
"(",
"gk",
",",
"metaObjFromIndex",
".",
"GetNamespace",
"(",
")",
",",
"metaObjFromIndex",
".",
"GetName",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"// Log and continue to try to process other GKs",
"c",
".",
"Logger",
".",
"With",
"(",
"zap",
".",
"Error",
"(",
"err",
")",
",",
"logz",
".",
"Namespace",
"(",
"metaObjFromIndex",
")",
",",
"logz",
".",
"Object",
"(",
"metaObjFromIndex",
")",
")",
".",
"Sugar",
"(",
")",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"for",
"_",
",",
"bundle",
":=",
"range",
"bundlesForObject",
"{",
"bundles",
"=",
"append",
"(",
"bundles",
",",
"bundle",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"bundles",
",",
"nil",
"\n",
"}",
"\n",
"}"
] |
// lookupBundleByObjectByIndex returns a function that can be used to perform lookups of Bundles that contain
// objects returned from an index.
|
[
"lookupBundleByObjectByIndex",
"returns",
"a",
"function",
"that",
"can",
"be",
"used",
"to",
"perform",
"lookups",
"of",
"Bundles",
"that",
"contain",
"objects",
"returned",
"from",
"an",
"index",
"."
] |
e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438
|
https://github.com/atlassian/smith/blob/e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438/pkg/controller/bundlec/controller.go#L187-L231
|
18,239 |
atlassian/smith
|
examples/sleeper/pkg/apis/sleeper/v1/zz_generated.deepcopy.go
|
DeepCopy
|
func (in *Sleeper) DeepCopy() *Sleeper {
if in == nil {
return nil
}
out := new(Sleeper)
in.DeepCopyInto(out)
return out
}
|
go
|
func (in *Sleeper) DeepCopy() *Sleeper {
if in == nil {
return nil
}
out := new(Sleeper)
in.DeepCopyInto(out)
return out
}
|
[
"func",
"(",
"in",
"*",
"Sleeper",
")",
"DeepCopy",
"(",
")",
"*",
"Sleeper",
"{",
"if",
"in",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"out",
":=",
"new",
"(",
"Sleeper",
")",
"\n",
"in",
".",
"DeepCopyInto",
"(",
"out",
")",
"\n",
"return",
"out",
"\n",
"}"
] |
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Sleeper.
|
[
"DeepCopy",
"is",
"an",
"autogenerated",
"deepcopy",
"function",
"copying",
"the",
"receiver",
"creating",
"a",
"new",
"Sleeper",
"."
] |
e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438
|
https://github.com/atlassian/smith/blob/e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438/examples/sleeper/pkg/apis/sleeper/v1/zz_generated.deepcopy.go#L24-L31
|
18,240 |
atlassian/smith
|
examples/sleeper/pkg/apis/sleeper/v1/zz_generated.deepcopy.go
|
DeepCopy
|
func (in *SleeperList) DeepCopy() *SleeperList {
if in == nil {
return nil
}
out := new(SleeperList)
in.DeepCopyInto(out)
return out
}
|
go
|
func (in *SleeperList) DeepCopy() *SleeperList {
if in == nil {
return nil
}
out := new(SleeperList)
in.DeepCopyInto(out)
return out
}
|
[
"func",
"(",
"in",
"*",
"SleeperList",
")",
"DeepCopy",
"(",
")",
"*",
"SleeperList",
"{",
"if",
"in",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"out",
":=",
"new",
"(",
"SleeperList",
")",
"\n",
"in",
".",
"DeepCopyInto",
"(",
"out",
")",
"\n",
"return",
"out",
"\n",
"}"
] |
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SleeperList.
|
[
"DeepCopy",
"is",
"an",
"autogenerated",
"deepcopy",
"function",
"copying",
"the",
"receiver",
"creating",
"a",
"new",
"SleeperList",
"."
] |
e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438
|
https://github.com/atlassian/smith/blob/e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438/examples/sleeper/pkg/apis/sleeper/v1/zz_generated.deepcopy.go#L57-L64
|
18,241 |
atlassian/smith
|
examples/sleeper/pkg/apis/sleeper/v1/zz_generated.deepcopy.go
|
DeepCopy
|
func (in *SleeperSpec) DeepCopy() *SleeperSpec {
if in == nil {
return nil
}
out := new(SleeperSpec)
in.DeepCopyInto(out)
return out
}
|
go
|
func (in *SleeperSpec) DeepCopy() *SleeperSpec {
if in == nil {
return nil
}
out := new(SleeperSpec)
in.DeepCopyInto(out)
return out
}
|
[
"func",
"(",
"in",
"*",
"SleeperSpec",
")",
"DeepCopy",
"(",
")",
"*",
"SleeperSpec",
"{",
"if",
"in",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"out",
":=",
"new",
"(",
"SleeperSpec",
")",
"\n",
"in",
".",
"DeepCopyInto",
"(",
"out",
")",
"\n",
"return",
"out",
"\n",
"}"
] |
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SleeperSpec.
|
[
"DeepCopy",
"is",
"an",
"autogenerated",
"deepcopy",
"function",
"copying",
"the",
"receiver",
"creating",
"a",
"new",
"SleeperSpec",
"."
] |
e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438
|
https://github.com/atlassian/smith/blob/e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438/examples/sleeper/pkg/apis/sleeper/v1/zz_generated.deepcopy.go#L81-L88
|
18,242 |
atlassian/smith
|
examples/sleeper/pkg/apis/sleeper/v1/zz_generated.deepcopy.go
|
DeepCopy
|
func (in *SleeperStatus) DeepCopy() *SleeperStatus {
if in == nil {
return nil
}
out := new(SleeperStatus)
in.DeepCopyInto(out)
return out
}
|
go
|
func (in *SleeperStatus) DeepCopy() *SleeperStatus {
if in == nil {
return nil
}
out := new(SleeperStatus)
in.DeepCopyInto(out)
return out
}
|
[
"func",
"(",
"in",
"*",
"SleeperStatus",
")",
"DeepCopy",
"(",
")",
"*",
"SleeperStatus",
"{",
"if",
"in",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"out",
":=",
"new",
"(",
"SleeperStatus",
")",
"\n",
"in",
".",
"DeepCopyInto",
"(",
"out",
")",
"\n",
"return",
"out",
"\n",
"}"
] |
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SleeperStatus.
|
[
"DeepCopy",
"is",
"an",
"autogenerated",
"deepcopy",
"function",
"copying",
"the",
"receiver",
"creating",
"a",
"new",
"SleeperStatus",
"."
] |
e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438
|
https://github.com/atlassian/smith/blob/e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438/examples/sleeper/pkg/apis/sleeper/v1/zz_generated.deepcopy.go#L97-L104
|
18,243 |
atlassian/smith
|
pkg/store/bundle.go
|
Get
|
func (s *BundleStore) Get(namespace, bundleName string) (*smith_v1.Bundle, error) {
bundle, exists, err := s.store.Get(smith_v1.BundleGVK, namespace, bundleName)
if err != nil || !exists {
return nil, err
}
return bundle.(*smith_v1.Bundle), nil
}
|
go
|
func (s *BundleStore) Get(namespace, bundleName string) (*smith_v1.Bundle, error) {
bundle, exists, err := s.store.Get(smith_v1.BundleGVK, namespace, bundleName)
if err != nil || !exists {
return nil, err
}
return bundle.(*smith_v1.Bundle), nil
}
|
[
"func",
"(",
"s",
"*",
"BundleStore",
")",
"Get",
"(",
"namespace",
",",
"bundleName",
"string",
")",
"(",
"*",
"smith_v1",
".",
"Bundle",
",",
"error",
")",
"{",
"bundle",
",",
"exists",
",",
"err",
":=",
"s",
".",
"store",
".",
"Get",
"(",
"smith_v1",
".",
"BundleGVK",
",",
"namespace",
",",
"bundleName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"||",
"!",
"exists",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"bundle",
".",
"(",
"*",
"smith_v1",
".",
"Bundle",
")",
",",
"nil",
"\n",
"}"
] |
// Get returns a bundle by its namespace and name.
// nil is returned if bundle does not exist.
|
[
"Get",
"returns",
"a",
"bundle",
"by",
"its",
"namespace",
"and",
"name",
".",
"nil",
"is",
"returned",
"if",
"bundle",
"does",
"not",
"exist",
"."
] |
e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438
|
https://github.com/atlassian/smith/blob/e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438/pkg/store/bundle.go#L49-L55
|
18,244 |
atlassian/smith
|
pkg/store/bundle.go
|
GetBundlesByCrd
|
func (s *BundleStore) GetBundlesByCrd(crd *apiext_v1b1.CustomResourceDefinition) ([]*smith_v1.Bundle, error) {
return s.getBundles(byCrdGroupKindIndexName, byCrdGroupKindIndexKey(crd.Spec.Group, crd.Spec.Names.Kind))
}
|
go
|
func (s *BundleStore) GetBundlesByCrd(crd *apiext_v1b1.CustomResourceDefinition) ([]*smith_v1.Bundle, error) {
return s.getBundles(byCrdGroupKindIndexName, byCrdGroupKindIndexKey(crd.Spec.Group, crd.Spec.Names.Kind))
}
|
[
"func",
"(",
"s",
"*",
"BundleStore",
")",
"GetBundlesByCrd",
"(",
"crd",
"*",
"apiext_v1b1",
".",
"CustomResourceDefinition",
")",
"(",
"[",
"]",
"*",
"smith_v1",
".",
"Bundle",
",",
"error",
")",
"{",
"return",
"s",
".",
"getBundles",
"(",
"byCrdGroupKindIndexName",
",",
"byCrdGroupKindIndexKey",
"(",
"crd",
".",
"Spec",
".",
"Group",
",",
"crd",
".",
"Spec",
".",
"Names",
".",
"Kind",
")",
")",
"\n",
"}"
] |
// GetBundlesByCrd returns Bundles which have a resource defined by CRD.
|
[
"GetBundlesByCrd",
"returns",
"Bundles",
"which",
"have",
"a",
"resource",
"defined",
"by",
"CRD",
"."
] |
e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438
|
https://github.com/atlassian/smith/blob/e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438/pkg/store/bundle.go#L58-L60
|
18,245 |
atlassian/smith
|
pkg/store/bundle.go
|
GetBundlesByObject
|
func (s *BundleStore) GetBundlesByObject(gk schema.GroupKind, namespace, name string) ([]*smith_v1.Bundle, error) {
return s.getBundles(byObjectIndexName, byObjectIndexKey(gk, namespace, name))
}
|
go
|
func (s *BundleStore) GetBundlesByObject(gk schema.GroupKind, namespace, name string) ([]*smith_v1.Bundle, error) {
return s.getBundles(byObjectIndexName, byObjectIndexKey(gk, namespace, name))
}
|
[
"func",
"(",
"s",
"*",
"BundleStore",
")",
"GetBundlesByObject",
"(",
"gk",
"schema",
".",
"GroupKind",
",",
"namespace",
",",
"name",
"string",
")",
"(",
"[",
"]",
"*",
"smith_v1",
".",
"Bundle",
",",
"error",
")",
"{",
"return",
"s",
".",
"getBundles",
"(",
"byObjectIndexName",
",",
"byObjectIndexKey",
"(",
"gk",
",",
"namespace",
",",
"name",
")",
")",
"\n",
"}"
] |
// GetBundlesByObject returns bundles where a resource with specified GVK, namespace and name is defined.
|
[
"GetBundlesByObject",
"returns",
"bundles",
"where",
"a",
"resource",
"with",
"specified",
"GVK",
"namespace",
"and",
"name",
"is",
"defined",
"."
] |
e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438
|
https://github.com/atlassian/smith/blob/e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438/pkg/store/bundle.go#L63-L65
|
18,246 |
atlassian/smith
|
pkg/client/clientset_generated/clientset/typed/smith/v1/fake/fake_bundle.go
|
Get
|
func (c *FakeBundles) Get(name string, options v1.GetOptions) (result *smithv1.Bundle, err error) {
obj, err := c.Fake.
Invokes(testing.NewGetAction(bundlesResource, c.ns, name), &smithv1.Bundle{})
if obj == nil {
return nil, err
}
return obj.(*smithv1.Bundle), err
}
|
go
|
func (c *FakeBundles) Get(name string, options v1.GetOptions) (result *smithv1.Bundle, err error) {
obj, err := c.Fake.
Invokes(testing.NewGetAction(bundlesResource, c.ns, name), &smithv1.Bundle{})
if obj == nil {
return nil, err
}
return obj.(*smithv1.Bundle), err
}
|
[
"func",
"(",
"c",
"*",
"FakeBundles",
")",
"Get",
"(",
"name",
"string",
",",
"options",
"v1",
".",
"GetOptions",
")",
"(",
"result",
"*",
"smithv1",
".",
"Bundle",
",",
"err",
"error",
")",
"{",
"obj",
",",
"err",
":=",
"c",
".",
"Fake",
".",
"Invokes",
"(",
"testing",
".",
"NewGetAction",
"(",
"bundlesResource",
",",
"c",
".",
"ns",
",",
"name",
")",
",",
"&",
"smithv1",
".",
"Bundle",
"{",
"}",
")",
"\n\n",
"if",
"obj",
"==",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"obj",
".",
"(",
"*",
"smithv1",
".",
"Bundle",
")",
",",
"err",
"\n",
"}"
] |
// Get takes name of the bundle, and returns the corresponding bundle object, and an error if there is any.
|
[
"Get",
"takes",
"name",
"of",
"the",
"bundle",
"and",
"returns",
"the",
"corresponding",
"bundle",
"object",
"and",
"an",
"error",
"if",
"there",
"is",
"any",
"."
] |
e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438
|
https://github.com/atlassian/smith/blob/e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438/pkg/client/clientset_generated/clientset/typed/smith/v1/fake/fake_bundle.go#L28-L36
|
18,247 |
atlassian/smith
|
pkg/client/clientset_generated/clientset/typed/smith/v1/fake/fake_bundle.go
|
List
|
func (c *FakeBundles) List(opts v1.ListOptions) (result *smithv1.BundleList, err error) {
obj, err := c.Fake.
Invokes(testing.NewListAction(bundlesResource, bundlesKind, c.ns, opts), &smithv1.BundleList{})
if obj == nil {
return nil, err
}
label, _, _ := testing.ExtractFromListOptions(opts)
if label == nil {
label = labels.Everything()
}
list := &smithv1.BundleList{ListMeta: obj.(*smithv1.BundleList).ListMeta}
for _, item := range obj.(*smithv1.BundleList).Items {
if label.Matches(labels.Set(item.Labels)) {
list.Items = append(list.Items, item)
}
}
return list, err
}
|
go
|
func (c *FakeBundles) List(opts v1.ListOptions) (result *smithv1.BundleList, err error) {
obj, err := c.Fake.
Invokes(testing.NewListAction(bundlesResource, bundlesKind, c.ns, opts), &smithv1.BundleList{})
if obj == nil {
return nil, err
}
label, _, _ := testing.ExtractFromListOptions(opts)
if label == nil {
label = labels.Everything()
}
list := &smithv1.BundleList{ListMeta: obj.(*smithv1.BundleList).ListMeta}
for _, item := range obj.(*smithv1.BundleList).Items {
if label.Matches(labels.Set(item.Labels)) {
list.Items = append(list.Items, item)
}
}
return list, err
}
|
[
"func",
"(",
"c",
"*",
"FakeBundles",
")",
"List",
"(",
"opts",
"v1",
".",
"ListOptions",
")",
"(",
"result",
"*",
"smithv1",
".",
"BundleList",
",",
"err",
"error",
")",
"{",
"obj",
",",
"err",
":=",
"c",
".",
"Fake",
".",
"Invokes",
"(",
"testing",
".",
"NewListAction",
"(",
"bundlesResource",
",",
"bundlesKind",
",",
"c",
".",
"ns",
",",
"opts",
")",
",",
"&",
"smithv1",
".",
"BundleList",
"{",
"}",
")",
"\n\n",
"if",
"obj",
"==",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"label",
",",
"_",
",",
"_",
":=",
"testing",
".",
"ExtractFromListOptions",
"(",
"opts",
")",
"\n",
"if",
"label",
"==",
"nil",
"{",
"label",
"=",
"labels",
".",
"Everything",
"(",
")",
"\n",
"}",
"\n",
"list",
":=",
"&",
"smithv1",
".",
"BundleList",
"{",
"ListMeta",
":",
"obj",
".",
"(",
"*",
"smithv1",
".",
"BundleList",
")",
".",
"ListMeta",
"}",
"\n",
"for",
"_",
",",
"item",
":=",
"range",
"obj",
".",
"(",
"*",
"smithv1",
".",
"BundleList",
")",
".",
"Items",
"{",
"if",
"label",
".",
"Matches",
"(",
"labels",
".",
"Set",
"(",
"item",
".",
"Labels",
")",
")",
"{",
"list",
".",
"Items",
"=",
"append",
"(",
"list",
".",
"Items",
",",
"item",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"list",
",",
"err",
"\n",
"}"
] |
// List takes label and field selectors, and returns the list of Bundles that match those selectors.
|
[
"List",
"takes",
"label",
"and",
"field",
"selectors",
"and",
"returns",
"the",
"list",
"of",
"Bundles",
"that",
"match",
"those",
"selectors",
"."
] |
e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438
|
https://github.com/atlassian/smith/blob/e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438/pkg/client/clientset_generated/clientset/typed/smith/v1/fake/fake_bundle.go#L39-L58
|
18,248 |
atlassian/smith
|
pkg/client/clientset_generated/clientset/typed/smith/v1/fake/fake_bundle.go
|
Watch
|
func (c *FakeBundles) Watch(opts v1.ListOptions) (watch.Interface, error) {
return c.Fake.
InvokesWatch(testing.NewWatchAction(bundlesResource, c.ns, opts))
}
|
go
|
func (c *FakeBundles) Watch(opts v1.ListOptions) (watch.Interface, error) {
return c.Fake.
InvokesWatch(testing.NewWatchAction(bundlesResource, c.ns, opts))
}
|
[
"func",
"(",
"c",
"*",
"FakeBundles",
")",
"Watch",
"(",
"opts",
"v1",
".",
"ListOptions",
")",
"(",
"watch",
".",
"Interface",
",",
"error",
")",
"{",
"return",
"c",
".",
"Fake",
".",
"InvokesWatch",
"(",
"testing",
".",
"NewWatchAction",
"(",
"bundlesResource",
",",
"c",
".",
"ns",
",",
"opts",
")",
")",
"\n\n",
"}"
] |
// Watch returns a watch.Interface that watches the requested bundles.
|
[
"Watch",
"returns",
"a",
"watch",
".",
"Interface",
"that",
"watches",
"the",
"requested",
"bundles",
"."
] |
e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438
|
https://github.com/atlassian/smith/blob/e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438/pkg/client/clientset_generated/clientset/typed/smith/v1/fake/fake_bundle.go#L61-L65
|
18,249 |
atlassian/smith
|
pkg/client/clientset_generated/clientset/typed/smith/v1/fake/fake_bundle.go
|
Delete
|
func (c *FakeBundles) Delete(name string, options *v1.DeleteOptions) error {
_, err := c.Fake.
Invokes(testing.NewDeleteAction(bundlesResource, c.ns, name), &smithv1.Bundle{})
return err
}
|
go
|
func (c *FakeBundles) Delete(name string, options *v1.DeleteOptions) error {
_, err := c.Fake.
Invokes(testing.NewDeleteAction(bundlesResource, c.ns, name), &smithv1.Bundle{})
return err
}
|
[
"func",
"(",
"c",
"*",
"FakeBundles",
")",
"Delete",
"(",
"name",
"string",
",",
"options",
"*",
"v1",
".",
"DeleteOptions",
")",
"error",
"{",
"_",
",",
"err",
":=",
"c",
".",
"Fake",
".",
"Invokes",
"(",
"testing",
".",
"NewDeleteAction",
"(",
"bundlesResource",
",",
"c",
".",
"ns",
",",
"name",
")",
",",
"&",
"smithv1",
".",
"Bundle",
"{",
"}",
")",
"\n\n",
"return",
"err",
"\n",
"}"
] |
// Delete takes name of the bundle and deletes it. Returns an error if one occurs.
|
[
"Delete",
"takes",
"name",
"of",
"the",
"bundle",
"and",
"deletes",
"it",
".",
"Returns",
"an",
"error",
"if",
"one",
"occurs",
"."
] |
e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438
|
https://github.com/atlassian/smith/blob/e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438/pkg/client/clientset_generated/clientset/typed/smith/v1/fake/fake_bundle.go#L102-L107
|
18,250 |
atlassian/smith
|
pkg/client/clientset_generated/clientset/typed/smith/v1/fake/fake_bundle.go
|
Patch
|
func (c *FakeBundles) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *smithv1.Bundle, err error) {
obj, err := c.Fake.
Invokes(testing.NewPatchSubresourceAction(bundlesResource, c.ns, name, pt, data, subresources...), &smithv1.Bundle{})
if obj == nil {
return nil, err
}
return obj.(*smithv1.Bundle), err
}
|
go
|
func (c *FakeBundles) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *smithv1.Bundle, err error) {
obj, err := c.Fake.
Invokes(testing.NewPatchSubresourceAction(bundlesResource, c.ns, name, pt, data, subresources...), &smithv1.Bundle{})
if obj == nil {
return nil, err
}
return obj.(*smithv1.Bundle), err
}
|
[
"func",
"(",
"c",
"*",
"FakeBundles",
")",
"Patch",
"(",
"name",
"string",
",",
"pt",
"types",
".",
"PatchType",
",",
"data",
"[",
"]",
"byte",
",",
"subresources",
"...",
"string",
")",
"(",
"result",
"*",
"smithv1",
".",
"Bundle",
",",
"err",
"error",
")",
"{",
"obj",
",",
"err",
":=",
"c",
".",
"Fake",
".",
"Invokes",
"(",
"testing",
".",
"NewPatchSubresourceAction",
"(",
"bundlesResource",
",",
"c",
".",
"ns",
",",
"name",
",",
"pt",
",",
"data",
",",
"subresources",
"...",
")",
",",
"&",
"smithv1",
".",
"Bundle",
"{",
"}",
")",
"\n\n",
"if",
"obj",
"==",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"obj",
".",
"(",
"*",
"smithv1",
".",
"Bundle",
")",
",",
"err",
"\n",
"}"
] |
// Patch applies the patch and returns the patched bundle.
|
[
"Patch",
"applies",
"the",
"patch",
"and",
"returns",
"the",
"patched",
"bundle",
"."
] |
e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438
|
https://github.com/atlassian/smith/blob/e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438/pkg/client/clientset_generated/clientset/typed/smith/v1/fake/fake_bundle.go#L118-L126
|
18,251 |
atlassian/smith
|
pkg/controller/bundlec/controller_crd_event_handler.go
|
ensureWatch
|
func (h *crdEventHandler) ensureWatch(logger *zap.Logger, crd *apiext_v1b1.CustomResourceDefinition) bool {
if crd.Name == smith_v1.BundleResourceName {
return false
}
if _, ok := h.watchers[crd.Name]; ok {
return true
}
if !resources.IsCrdConditionTrue(crd, apiext_v1b1.Established) {
logger.Info("Not adding a watch for CRD because it hasn't been established")
return false
}
if !resources.IsCrdConditionTrue(crd, apiext_v1b1.NamesAccepted) {
logger.Info("Not adding a watch for CRD because its names haven't been accepted")
return false
}
gvk := schema.GroupVersionKind{
Group: crd.Spec.Group,
Version: crd.Spec.Versions[0].Name,
Kind: crd.Spec.Names.Kind,
}
logger.Info("Configuring watch for CRD")
res, err := h.controller.SmartClient.ForGVK(gvk, h.controller.Namespace)
if err != nil {
logger.Error("Failed to get client for CRD", zap.Error(err))
return false
}
crdInf := cache.NewSharedIndexInformer(&cache.ListWatch{
ListFunc: func(options meta_v1.ListOptions) (runtime.Object, error) {
return res.List(options)
},
WatchFunc: res.Watch,
}, &unstructured.Unstructured{}, h.controller.CrdResyncPeriod, cache.Indexers{})
h.controller.wgLock.Lock()
defer h.controller.wgLock.Unlock()
if h.controller.stopping {
return false
}
resourceHandler := &handlers.ControlledResourceHandler{
Logger: h.controller.Logger,
WorkQueue: h.controller.WorkQueue,
ControllerIndex: &controllerIndexAdapter{bundleStore: h.controller.BundleStore},
ControllerGvk: smith_v1.BundleGVK,
Gvk: gvk,
}
crdInf.AddEventHandler(resourceHandler)
err = h.controller.Store.AddInformer(gvk, crdInf)
if err != nil {
logger.Error("Failed to add informer for CRD to multisore", zap.Error(err))
return false
}
ctx, cancel := context.WithCancel(h.controller.crdContext)
h.watchers[crd.Name] = watchState{cancel: cancel}
h.controller.wg.StartWithChannel(ctx.Done(), crdInf.Run)
return true
}
|
go
|
func (h *crdEventHandler) ensureWatch(logger *zap.Logger, crd *apiext_v1b1.CustomResourceDefinition) bool {
if crd.Name == smith_v1.BundleResourceName {
return false
}
if _, ok := h.watchers[crd.Name]; ok {
return true
}
if !resources.IsCrdConditionTrue(crd, apiext_v1b1.Established) {
logger.Info("Not adding a watch for CRD because it hasn't been established")
return false
}
if !resources.IsCrdConditionTrue(crd, apiext_v1b1.NamesAccepted) {
logger.Info("Not adding a watch for CRD because its names haven't been accepted")
return false
}
gvk := schema.GroupVersionKind{
Group: crd.Spec.Group,
Version: crd.Spec.Versions[0].Name,
Kind: crd.Spec.Names.Kind,
}
logger.Info("Configuring watch for CRD")
res, err := h.controller.SmartClient.ForGVK(gvk, h.controller.Namespace)
if err != nil {
logger.Error("Failed to get client for CRD", zap.Error(err))
return false
}
crdInf := cache.NewSharedIndexInformer(&cache.ListWatch{
ListFunc: func(options meta_v1.ListOptions) (runtime.Object, error) {
return res.List(options)
},
WatchFunc: res.Watch,
}, &unstructured.Unstructured{}, h.controller.CrdResyncPeriod, cache.Indexers{})
h.controller.wgLock.Lock()
defer h.controller.wgLock.Unlock()
if h.controller.stopping {
return false
}
resourceHandler := &handlers.ControlledResourceHandler{
Logger: h.controller.Logger,
WorkQueue: h.controller.WorkQueue,
ControllerIndex: &controllerIndexAdapter{bundleStore: h.controller.BundleStore},
ControllerGvk: smith_v1.BundleGVK,
Gvk: gvk,
}
crdInf.AddEventHandler(resourceHandler)
err = h.controller.Store.AddInformer(gvk, crdInf)
if err != nil {
logger.Error("Failed to add informer for CRD to multisore", zap.Error(err))
return false
}
ctx, cancel := context.WithCancel(h.controller.crdContext)
h.watchers[crd.Name] = watchState{cancel: cancel}
h.controller.wg.StartWithChannel(ctx.Done(), crdInf.Run)
return true
}
|
[
"func",
"(",
"h",
"*",
"crdEventHandler",
")",
"ensureWatch",
"(",
"logger",
"*",
"zap",
".",
"Logger",
",",
"crd",
"*",
"apiext_v1b1",
".",
"CustomResourceDefinition",
")",
"bool",
"{",
"if",
"crd",
".",
"Name",
"==",
"smith_v1",
".",
"BundleResourceName",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"_",
",",
"ok",
":=",
"h",
".",
"watchers",
"[",
"crd",
".",
"Name",
"]",
";",
"ok",
"{",
"return",
"true",
"\n",
"}",
"\n",
"if",
"!",
"resources",
".",
"IsCrdConditionTrue",
"(",
"crd",
",",
"apiext_v1b1",
".",
"Established",
")",
"{",
"logger",
".",
"Info",
"(",
"\"",
"\"",
")",
"\n",
"return",
"false",
"\n",
"}",
"\n",
"if",
"!",
"resources",
".",
"IsCrdConditionTrue",
"(",
"crd",
",",
"apiext_v1b1",
".",
"NamesAccepted",
")",
"{",
"logger",
".",
"Info",
"(",
"\"",
"\"",
")",
"\n",
"return",
"false",
"\n",
"}",
"\n",
"gvk",
":=",
"schema",
".",
"GroupVersionKind",
"{",
"Group",
":",
"crd",
".",
"Spec",
".",
"Group",
",",
"Version",
":",
"crd",
".",
"Spec",
".",
"Versions",
"[",
"0",
"]",
".",
"Name",
",",
"Kind",
":",
"crd",
".",
"Spec",
".",
"Names",
".",
"Kind",
",",
"}",
"\n",
"logger",
".",
"Info",
"(",
"\"",
"\"",
")",
"\n",
"res",
",",
"err",
":=",
"h",
".",
"controller",
".",
"SmartClient",
".",
"ForGVK",
"(",
"gvk",
",",
"h",
".",
"controller",
".",
"Namespace",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logger",
".",
"Error",
"(",
"\"",
"\"",
",",
"zap",
".",
"Error",
"(",
"err",
")",
")",
"\n",
"return",
"false",
"\n",
"}",
"\n",
"crdInf",
":=",
"cache",
".",
"NewSharedIndexInformer",
"(",
"&",
"cache",
".",
"ListWatch",
"{",
"ListFunc",
":",
"func",
"(",
"options",
"meta_v1",
".",
"ListOptions",
")",
"(",
"runtime",
".",
"Object",
",",
"error",
")",
"{",
"return",
"res",
".",
"List",
"(",
"options",
")",
"\n",
"}",
",",
"WatchFunc",
":",
"res",
".",
"Watch",
",",
"}",
",",
"&",
"unstructured",
".",
"Unstructured",
"{",
"}",
",",
"h",
".",
"controller",
".",
"CrdResyncPeriod",
",",
"cache",
".",
"Indexers",
"{",
"}",
")",
"\n",
"h",
".",
"controller",
".",
"wgLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"h",
".",
"controller",
".",
"wgLock",
".",
"Unlock",
"(",
")",
"\n",
"if",
"h",
".",
"controller",
".",
"stopping",
"{",
"return",
"false",
"\n",
"}",
"\n",
"resourceHandler",
":=",
"&",
"handlers",
".",
"ControlledResourceHandler",
"{",
"Logger",
":",
"h",
".",
"controller",
".",
"Logger",
",",
"WorkQueue",
":",
"h",
".",
"controller",
".",
"WorkQueue",
",",
"ControllerIndex",
":",
"&",
"controllerIndexAdapter",
"{",
"bundleStore",
":",
"h",
".",
"controller",
".",
"BundleStore",
"}",
",",
"ControllerGvk",
":",
"smith_v1",
".",
"BundleGVK",
",",
"Gvk",
":",
"gvk",
",",
"}",
"\n",
"crdInf",
".",
"AddEventHandler",
"(",
"resourceHandler",
")",
"\n",
"err",
"=",
"h",
".",
"controller",
".",
"Store",
".",
"AddInformer",
"(",
"gvk",
",",
"crdInf",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logger",
".",
"Error",
"(",
"\"",
"\"",
",",
"zap",
".",
"Error",
"(",
"err",
")",
")",
"\n",
"return",
"false",
"\n",
"}",
"\n",
"ctx",
",",
"cancel",
":=",
"context",
".",
"WithCancel",
"(",
"h",
".",
"controller",
".",
"crdContext",
")",
"\n",
"h",
".",
"watchers",
"[",
"crd",
".",
"Name",
"]",
"=",
"watchState",
"{",
"cancel",
":",
"cancel",
"}",
"\n",
"h",
".",
"controller",
".",
"wg",
".",
"StartWithChannel",
"(",
"ctx",
".",
"Done",
"(",
")",
",",
"crdInf",
".",
"Run",
")",
"\n",
"return",
"true",
"\n",
"}"
] |
// ensureWatch ensures there is a watch for CRs of a CRD.
// Returns true if a watch was found or set up successfully and false if there is no watch and it was not set up for
// some reason.
|
[
"ensureWatch",
"ensures",
"there",
"is",
"a",
"watch",
"for",
"CRs",
"of",
"a",
"CRD",
".",
"Returns",
"true",
"if",
"a",
"watch",
"was",
"found",
"or",
"set",
"up",
"successfully",
"and",
"false",
"if",
"there",
"is",
"no",
"watch",
"and",
"it",
"was",
"not",
"set",
"up",
"for",
"some",
"reason",
"."
] |
e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438
|
https://github.com/atlassian/smith/blob/e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438/pkg/controller/bundlec/controller_crd_event_handler.go#L90-L144
|
18,252 |
atlassian/smith
|
pkg/controller/bundlec/controller_crd_event_handler.go
|
ensureNoWatch
|
func (h *crdEventHandler) ensureNoWatch(logger *zap.Logger, crd *apiext_v1b1.CustomResourceDefinition) bool {
crdWatch, ok := h.watchers[crd.Name]
if !ok {
// Nothing to do. This can happen if there was an error adding a watch
return false
}
logger.Info("Removing watch for CRD")
crdWatch.cancel()
delete(h.watchers, crd.Name)
gvk := schema.GroupVersionKind{
Group: crd.Spec.Group,
Version: crd.Spec.Versions[0].Name,
Kind: crd.Spec.Names.Kind,
}
h.controller.Store.RemoveInformer(gvk)
return true
}
|
go
|
func (h *crdEventHandler) ensureNoWatch(logger *zap.Logger, crd *apiext_v1b1.CustomResourceDefinition) bool {
crdWatch, ok := h.watchers[crd.Name]
if !ok {
// Nothing to do. This can happen if there was an error adding a watch
return false
}
logger.Info("Removing watch for CRD")
crdWatch.cancel()
delete(h.watchers, crd.Name)
gvk := schema.GroupVersionKind{
Group: crd.Spec.Group,
Version: crd.Spec.Versions[0].Name,
Kind: crd.Spec.Names.Kind,
}
h.controller.Store.RemoveInformer(gvk)
return true
}
|
[
"func",
"(",
"h",
"*",
"crdEventHandler",
")",
"ensureNoWatch",
"(",
"logger",
"*",
"zap",
".",
"Logger",
",",
"crd",
"*",
"apiext_v1b1",
".",
"CustomResourceDefinition",
")",
"bool",
"{",
"crdWatch",
",",
"ok",
":=",
"h",
".",
"watchers",
"[",
"crd",
".",
"Name",
"]",
"\n",
"if",
"!",
"ok",
"{",
"// Nothing to do. This can happen if there was an error adding a watch",
"return",
"false",
"\n",
"}",
"\n",
"logger",
".",
"Info",
"(",
"\"",
"\"",
")",
"\n",
"crdWatch",
".",
"cancel",
"(",
")",
"\n",
"delete",
"(",
"h",
".",
"watchers",
",",
"crd",
".",
"Name",
")",
"\n",
"gvk",
":=",
"schema",
".",
"GroupVersionKind",
"{",
"Group",
":",
"crd",
".",
"Spec",
".",
"Group",
",",
"Version",
":",
"crd",
".",
"Spec",
".",
"Versions",
"[",
"0",
"]",
".",
"Name",
",",
"Kind",
":",
"crd",
".",
"Spec",
".",
"Names",
".",
"Kind",
",",
"}",
"\n",
"h",
".",
"controller",
".",
"Store",
".",
"RemoveInformer",
"(",
"gvk",
")",
"\n",
"return",
"true",
"\n",
"}"
] |
// ensureNoWatch ensures there is no watch for CRs of a CRD.
// Returns true if a watch was found and terminated and false if there was no watch already.
|
[
"ensureNoWatch",
"ensures",
"there",
"is",
"no",
"watch",
"for",
"CRs",
"of",
"a",
"CRD",
".",
"Returns",
"true",
"if",
"a",
"watch",
"was",
"found",
"and",
"terminated",
"and",
"false",
"if",
"there",
"was",
"no",
"watch",
"already",
"."
] |
e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438
|
https://github.com/atlassian/smith/blob/e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438/pkg/controller/bundlec/controller_crd_event_handler.go#L148-L164
|
18,253 |
atlassian/smith
|
pkg/apis/smith/v1/zz_generated.deepcopy.go
|
DeepCopy
|
func (in *Bundle) DeepCopy() *Bundle {
if in == nil {
return nil
}
out := new(Bundle)
in.DeepCopyInto(out)
return out
}
|
go
|
func (in *Bundle) DeepCopy() *Bundle {
if in == nil {
return nil
}
out := new(Bundle)
in.DeepCopyInto(out)
return out
}
|
[
"func",
"(",
"in",
"*",
"Bundle",
")",
"DeepCopy",
"(",
")",
"*",
"Bundle",
"{",
"if",
"in",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"out",
":=",
"new",
"(",
"Bundle",
")",
"\n",
"in",
".",
"DeepCopyInto",
"(",
"out",
")",
"\n",
"return",
"out",
"\n",
"}"
] |
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Bundle.
|
[
"DeepCopy",
"is",
"an",
"autogenerated",
"deepcopy",
"function",
"copying",
"the",
"receiver",
"creating",
"a",
"new",
"Bundle",
"."
] |
e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438
|
https://github.com/atlassian/smith/blob/e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438/pkg/apis/smith/v1/zz_generated.deepcopy.go#L25-L32
|
18,254 |
atlassian/smith
|
pkg/apis/smith/v1/zz_generated.deepcopy.go
|
DeepCopy
|
func (in *BundleList) DeepCopy() *BundleList {
if in == nil {
return nil
}
out := new(BundleList)
in.DeepCopyInto(out)
return out
}
|
go
|
func (in *BundleList) DeepCopy() *BundleList {
if in == nil {
return nil
}
out := new(BundleList)
in.DeepCopyInto(out)
return out
}
|
[
"func",
"(",
"in",
"*",
"BundleList",
")",
"DeepCopy",
"(",
")",
"*",
"BundleList",
"{",
"if",
"in",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"out",
":=",
"new",
"(",
"BundleList",
")",
"\n",
"in",
".",
"DeepCopyInto",
"(",
"out",
")",
"\n",
"return",
"out",
"\n",
"}"
] |
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BundleList.
|
[
"DeepCopy",
"is",
"an",
"autogenerated",
"deepcopy",
"function",
"copying",
"the",
"receiver",
"creating",
"a",
"new",
"BundleList",
"."
] |
e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438
|
https://github.com/atlassian/smith/blob/e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438/pkg/apis/smith/v1/zz_generated.deepcopy.go#L58-L65
|
18,255 |
atlassian/smith
|
pkg/apis/smith/v1/zz_generated.deepcopy.go
|
DeepCopy
|
func (in *BundleSpec) DeepCopy() *BundleSpec {
if in == nil {
return nil
}
out := new(BundleSpec)
in.DeepCopyInto(out)
return out
}
|
go
|
func (in *BundleSpec) DeepCopy() *BundleSpec {
if in == nil {
return nil
}
out := new(BundleSpec)
in.DeepCopyInto(out)
return out
}
|
[
"func",
"(",
"in",
"*",
"BundleSpec",
")",
"DeepCopy",
"(",
")",
"*",
"BundleSpec",
"{",
"if",
"in",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"out",
":=",
"new",
"(",
"BundleSpec",
")",
"\n",
"in",
".",
"DeepCopyInto",
"(",
"out",
")",
"\n",
"return",
"out",
"\n",
"}"
] |
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BundleSpec.
|
[
"DeepCopy",
"is",
"an",
"autogenerated",
"deepcopy",
"function",
"copying",
"the",
"receiver",
"creating",
"a",
"new",
"BundleSpec",
"."
] |
e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438
|
https://github.com/atlassian/smith/blob/e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438/pkg/apis/smith/v1/zz_generated.deepcopy.go#L89-L96
|
18,256 |
atlassian/smith
|
pkg/apis/smith/v1/zz_generated.deepcopy.go
|
DeepCopy
|
func (in *BundleStatus) DeepCopy() *BundleStatus {
if in == nil {
return nil
}
out := new(BundleStatus)
in.DeepCopyInto(out)
return out
}
|
go
|
func (in *BundleStatus) DeepCopy() *BundleStatus {
if in == nil {
return nil
}
out := new(BundleStatus)
in.DeepCopyInto(out)
return out
}
|
[
"func",
"(",
"in",
"*",
"BundleStatus",
")",
"DeepCopy",
"(",
")",
"*",
"BundleStatus",
"{",
"if",
"in",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"out",
":=",
"new",
"(",
"BundleStatus",
")",
"\n",
"in",
".",
"DeepCopyInto",
"(",
"out",
")",
"\n",
"return",
"out",
"\n",
"}"
] |
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BundleStatus.
|
[
"DeepCopy",
"is",
"an",
"autogenerated",
"deepcopy",
"function",
"copying",
"the",
"receiver",
"creating",
"a",
"new",
"BundleStatus",
"."
] |
e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438
|
https://github.com/atlassian/smith/blob/e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438/pkg/apis/smith/v1/zz_generated.deepcopy.go#L129-L136
|
18,257 |
atlassian/smith
|
pkg/apis/smith/v1/zz_generated.deepcopy.go
|
DeepCopy
|
func (in *PluginSpec) DeepCopy() *PluginSpec {
if in == nil {
return nil
}
out := new(PluginSpec)
in.DeepCopyInto(out)
return out
}
|
go
|
func (in *PluginSpec) DeepCopy() *PluginSpec {
if in == nil {
return nil
}
out := new(PluginSpec)
in.DeepCopyInto(out)
return out
}
|
[
"func",
"(",
"in",
"*",
"PluginSpec",
")",
"DeepCopy",
"(",
")",
"*",
"PluginSpec",
"{",
"if",
"in",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"out",
":=",
"new",
"(",
"PluginSpec",
")",
"\n",
"in",
".",
"DeepCopyInto",
"(",
"out",
")",
"\n",
"return",
"out",
"\n",
"}"
] |
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PluginSpec.
|
[
"DeepCopy",
"is",
"an",
"autogenerated",
"deepcopy",
"function",
"copying",
"the",
"receiver",
"creating",
"a",
"new",
"PluginSpec",
"."
] |
e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438
|
https://github.com/atlassian/smith/blob/e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438/pkg/apis/smith/v1/zz_generated.deepcopy.go#L139-L146
|
18,258 |
atlassian/smith
|
pkg/apis/smith/v1/zz_generated.deepcopy.go
|
DeepCopy
|
func (in *Reference) DeepCopy() *Reference {
if in == nil {
return nil
}
out := new(Reference)
in.DeepCopyInto(out)
return out
}
|
go
|
func (in *Reference) DeepCopy() *Reference {
if in == nil {
return nil
}
out := new(Reference)
in.DeepCopyInto(out)
return out
}
|
[
"func",
"(",
"in",
"*",
"Reference",
")",
"DeepCopy",
"(",
")",
"*",
"Reference",
"{",
"if",
"in",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"out",
":=",
"new",
"(",
"Reference",
")",
"\n",
"in",
".",
"DeepCopyInto",
"(",
"out",
")",
"\n",
"return",
"out",
"\n",
"}"
] |
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Reference.
|
[
"DeepCopy",
"is",
"an",
"autogenerated",
"deepcopy",
"function",
"copying",
"the",
"receiver",
"creating",
"a",
"new",
"Reference",
"."
] |
e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438
|
https://github.com/atlassian/smith/blob/e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438/pkg/apis/smith/v1/zz_generated.deepcopy.go#L149-L156
|
18,259 |
atlassian/smith
|
pkg/apis/smith/v1/zz_generated.deepcopy.go
|
DeepCopy
|
func (in *Resource) DeepCopy() *Resource {
if in == nil {
return nil
}
out := new(Resource)
in.DeepCopyInto(out)
return out
}
|
go
|
func (in *Resource) DeepCopy() *Resource {
if in == nil {
return nil
}
out := new(Resource)
in.DeepCopyInto(out)
return out
}
|
[
"func",
"(",
"in",
"*",
"Resource",
")",
"DeepCopy",
"(",
")",
"*",
"Resource",
"{",
"if",
"in",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"out",
":=",
"new",
"(",
"Resource",
")",
"\n",
"in",
".",
"DeepCopyInto",
"(",
"out",
")",
"\n",
"return",
"out",
"\n",
"}"
] |
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Resource.
|
[
"DeepCopy",
"is",
"an",
"autogenerated",
"deepcopy",
"function",
"copying",
"the",
"receiver",
"creating",
"a",
"new",
"Resource",
"."
] |
e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438
|
https://github.com/atlassian/smith/blob/e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438/pkg/apis/smith/v1/zz_generated.deepcopy.go#L173-L180
|
18,260 |
atlassian/smith
|
pkg/apis/smith/v1/zz_generated.deepcopy.go
|
DeepCopy
|
func (in *ResourceSpec) DeepCopy() *ResourceSpec {
if in == nil {
return nil
}
out := new(ResourceSpec)
in.DeepCopyInto(out)
return out
}
|
go
|
func (in *ResourceSpec) DeepCopy() *ResourceSpec {
if in == nil {
return nil
}
out := new(ResourceSpec)
in.DeepCopyInto(out)
return out
}
|
[
"func",
"(",
"in",
"*",
"ResourceSpec",
")",
"DeepCopy",
"(",
")",
"*",
"ResourceSpec",
"{",
"if",
"in",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"out",
":=",
"new",
"(",
"ResourceSpec",
")",
"\n",
"in",
".",
"DeepCopyInto",
"(",
"out",
")",
"\n",
"return",
"out",
"\n",
"}"
] |
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ResourceSpec.
|
[
"DeepCopy",
"is",
"an",
"autogenerated",
"deepcopy",
"function",
"copying",
"the",
"receiver",
"creating",
"a",
"new",
"ResourceSpec",
"."
] |
e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438
|
https://github.com/atlassian/smith/blob/e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438/pkg/apis/smith/v1/zz_generated.deepcopy.go#L196-L203
|
18,261 |
atlassian/smith
|
pkg/apis/smith/v1/zz_generated.deepcopy.go
|
DeepCopy
|
func (in *ResourceStatusData) DeepCopy() *ResourceStatusData {
if in == nil {
return nil
}
out := new(ResourceStatusData)
in.DeepCopyInto(out)
return out
}
|
go
|
func (in *ResourceStatusData) DeepCopy() *ResourceStatusData {
if in == nil {
return nil
}
out := new(ResourceStatusData)
in.DeepCopyInto(out)
return out
}
|
[
"func",
"(",
"in",
"*",
"ResourceStatusData",
")",
"DeepCopy",
"(",
")",
"*",
"ResourceStatusData",
"{",
"if",
"in",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"out",
":=",
"new",
"(",
"ResourceStatusData",
")",
"\n",
"in",
".",
"DeepCopyInto",
"(",
"out",
")",
"\n",
"return",
"out",
"\n",
"}"
] |
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ResourceStatusData.
|
[
"DeepCopy",
"is",
"an",
"autogenerated",
"deepcopy",
"function",
"copying",
"the",
"receiver",
"creating",
"a",
"new",
"ResourceStatusData",
"."
] |
e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438
|
https://github.com/atlassian/smith/blob/e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438/pkg/apis/smith/v1/zz_generated.deepcopy.go#L236-L243
|
18,262 |
atlassian/smith
|
pkg/controller/bundlec/controller_worker.go
|
ProcessBundle
|
func (c *Controller) ProcessBundle(logger *zap.Logger, bundle *smith_v1.Bundle) (bool /*external*/, bool /*retriable*/, error) {
st := bundleSyncTask{
logger: logger,
bundleClient: c.BundleClient,
smartClient: c.SmartClient,
checker: c.Rc,
store: c.Store,
specChecker: c.SpecChecker,
bundle: bundle,
pluginContainers: c.PluginContainers,
scheme: c.Scheme,
catalog: c.Catalog,
bundleTransitionCounter: c.BundleTransitionCounter,
bundleResourceTransitionCounter: c.BundleResourceTransitionCounter,
recorder: c.Recorder,
}
var external bool
var retriable bool
var err error
if st.bundle.DeletionTimestamp != nil {
external, retriable, err = st.processDeleted()
} else {
external, retriable, err = st.processNormal()
}
if err != nil {
cause := errors.Cause(err)
// short circuit on conflicts
if api_errors.IsConflict(cause) {
return external, retriable, err
}
// proceed to handleProcessResult() for all other errors
}
// Updates bundle status
handleProcessRetriable, handleProcessErr := st.handleProcessResult(retriable, err)
// Inspect the resources for failures. They can fail for many different reasons.
// The priority of errors to bubble up to the ctrl layer are:
// 1. processDeleted/processNormal errors
// 2. Internal resource processing errors are raised first
// 3. External resource processing errors are raised last
// 4. handleProcessResult errors of any sort.
// Handle the errors from processDeleted/processNormal, taking precedence
// over the handleProcessErr if any.
if err != nil {
if handleProcessErr != nil {
st.logger.Error("Error processing Bundle", zap.Error(handleProcessErr))
}
return external, retriable || handleProcessRetriable, err
}
// Inspect resources, returning an error if necessary
allExternalErrors := true
hasRetriableResourceErr := false
var failedResources []string
for resName, resInfo := range st.processedResources {
resErr := resInfo.fetchError()
if resErr != nil {
allExternalErrors = allExternalErrors && resErr.isExternalError
hasRetriableResourceErr = hasRetriableResourceErr || resErr.isRetriableError
failedResources = append(failedResources, string(resName))
}
}
if len(failedResources) > 0 {
if handleProcessErr != nil {
st.logger.Error("Error processing Bundle", zap.Error(handleProcessErr))
}
// stable output
sort.Strings(failedResources)
err := errors.Errorf("error processing resource(s): %q", failedResources)
return allExternalErrors, hasRetriableResourceErr || handleProcessRetriable, err
}
// Otherwise, return the result from handleProcessResult
return false, handleProcessRetriable, handleProcessErr
}
|
go
|
func (c *Controller) ProcessBundle(logger *zap.Logger, bundle *smith_v1.Bundle) (bool /*external*/, bool /*retriable*/, error) {
st := bundleSyncTask{
logger: logger,
bundleClient: c.BundleClient,
smartClient: c.SmartClient,
checker: c.Rc,
store: c.Store,
specChecker: c.SpecChecker,
bundle: bundle,
pluginContainers: c.PluginContainers,
scheme: c.Scheme,
catalog: c.Catalog,
bundleTransitionCounter: c.BundleTransitionCounter,
bundleResourceTransitionCounter: c.BundleResourceTransitionCounter,
recorder: c.Recorder,
}
var external bool
var retriable bool
var err error
if st.bundle.DeletionTimestamp != nil {
external, retriable, err = st.processDeleted()
} else {
external, retriable, err = st.processNormal()
}
if err != nil {
cause := errors.Cause(err)
// short circuit on conflicts
if api_errors.IsConflict(cause) {
return external, retriable, err
}
// proceed to handleProcessResult() for all other errors
}
// Updates bundle status
handleProcessRetriable, handleProcessErr := st.handleProcessResult(retriable, err)
// Inspect the resources for failures. They can fail for many different reasons.
// The priority of errors to bubble up to the ctrl layer are:
// 1. processDeleted/processNormal errors
// 2. Internal resource processing errors are raised first
// 3. External resource processing errors are raised last
// 4. handleProcessResult errors of any sort.
// Handle the errors from processDeleted/processNormal, taking precedence
// over the handleProcessErr if any.
if err != nil {
if handleProcessErr != nil {
st.logger.Error("Error processing Bundle", zap.Error(handleProcessErr))
}
return external, retriable || handleProcessRetriable, err
}
// Inspect resources, returning an error if necessary
allExternalErrors := true
hasRetriableResourceErr := false
var failedResources []string
for resName, resInfo := range st.processedResources {
resErr := resInfo.fetchError()
if resErr != nil {
allExternalErrors = allExternalErrors && resErr.isExternalError
hasRetriableResourceErr = hasRetriableResourceErr || resErr.isRetriableError
failedResources = append(failedResources, string(resName))
}
}
if len(failedResources) > 0 {
if handleProcessErr != nil {
st.logger.Error("Error processing Bundle", zap.Error(handleProcessErr))
}
// stable output
sort.Strings(failedResources)
err := errors.Errorf("error processing resource(s): %q", failedResources)
return allExternalErrors, hasRetriableResourceErr || handleProcessRetriable, err
}
// Otherwise, return the result from handleProcessResult
return false, handleProcessRetriable, handleProcessErr
}
|
[
"func",
"(",
"c",
"*",
"Controller",
")",
"ProcessBundle",
"(",
"logger",
"*",
"zap",
".",
"Logger",
",",
"bundle",
"*",
"smith_v1",
".",
"Bundle",
")",
"(",
"bool",
"/*external*/",
",",
"bool",
"/*retriable*/",
",",
"error",
")",
"{",
"st",
":=",
"bundleSyncTask",
"{",
"logger",
":",
"logger",
",",
"bundleClient",
":",
"c",
".",
"BundleClient",
",",
"smartClient",
":",
"c",
".",
"SmartClient",
",",
"checker",
":",
"c",
".",
"Rc",
",",
"store",
":",
"c",
".",
"Store",
",",
"specChecker",
":",
"c",
".",
"SpecChecker",
",",
"bundle",
":",
"bundle",
",",
"pluginContainers",
":",
"c",
".",
"PluginContainers",
",",
"scheme",
":",
"c",
".",
"Scheme",
",",
"catalog",
":",
"c",
".",
"Catalog",
",",
"bundleTransitionCounter",
":",
"c",
".",
"BundleTransitionCounter",
",",
"bundleResourceTransitionCounter",
":",
"c",
".",
"BundleResourceTransitionCounter",
",",
"recorder",
":",
"c",
".",
"Recorder",
",",
"}",
"\n\n",
"var",
"external",
"bool",
"\n",
"var",
"retriable",
"bool",
"\n",
"var",
"err",
"error",
"\n",
"if",
"st",
".",
"bundle",
".",
"DeletionTimestamp",
"!=",
"nil",
"{",
"external",
",",
"retriable",
",",
"err",
"=",
"st",
".",
"processDeleted",
"(",
")",
"\n",
"}",
"else",
"{",
"external",
",",
"retriable",
",",
"err",
"=",
"st",
".",
"processNormal",
"(",
")",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"cause",
":=",
"errors",
".",
"Cause",
"(",
"err",
")",
"\n",
"// short circuit on conflicts",
"if",
"api_errors",
".",
"IsConflict",
"(",
"cause",
")",
"{",
"return",
"external",
",",
"retriable",
",",
"err",
"\n",
"}",
"\n",
"// proceed to handleProcessResult() for all other errors",
"}",
"\n\n",
"// Updates bundle status",
"handleProcessRetriable",
",",
"handleProcessErr",
":=",
"st",
".",
"handleProcessResult",
"(",
"retriable",
",",
"err",
")",
"\n\n",
"// Inspect the resources for failures. They can fail for many different reasons.",
"// The priority of errors to bubble up to the ctrl layer are:",
"// 1. processDeleted/processNormal errors",
"// 2. Internal resource processing errors are raised first",
"// 3. External resource processing errors are raised last",
"// 4. handleProcessResult errors of any sort.",
"// Handle the errors from processDeleted/processNormal, taking precedence",
"// over the handleProcessErr if any.",
"if",
"err",
"!=",
"nil",
"{",
"if",
"handleProcessErr",
"!=",
"nil",
"{",
"st",
".",
"logger",
".",
"Error",
"(",
"\"",
"\"",
",",
"zap",
".",
"Error",
"(",
"handleProcessErr",
")",
")",
"\n",
"}",
"\n\n",
"return",
"external",
",",
"retriable",
"||",
"handleProcessRetriable",
",",
"err",
"\n",
"}",
"\n\n",
"// Inspect resources, returning an error if necessary",
"allExternalErrors",
":=",
"true",
"\n",
"hasRetriableResourceErr",
":=",
"false",
"\n",
"var",
"failedResources",
"[",
"]",
"string",
"\n",
"for",
"resName",
",",
"resInfo",
":=",
"range",
"st",
".",
"processedResources",
"{",
"resErr",
":=",
"resInfo",
".",
"fetchError",
"(",
")",
"\n\n",
"if",
"resErr",
"!=",
"nil",
"{",
"allExternalErrors",
"=",
"allExternalErrors",
"&&",
"resErr",
".",
"isExternalError",
"\n",
"hasRetriableResourceErr",
"=",
"hasRetriableResourceErr",
"||",
"resErr",
".",
"isRetriableError",
"\n",
"failedResources",
"=",
"append",
"(",
"failedResources",
",",
"string",
"(",
"resName",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"len",
"(",
"failedResources",
")",
">",
"0",
"{",
"if",
"handleProcessErr",
"!=",
"nil",
"{",
"st",
".",
"logger",
".",
"Error",
"(",
"\"",
"\"",
",",
"zap",
".",
"Error",
"(",
"handleProcessErr",
")",
")",
"\n",
"}",
"\n",
"// stable output",
"sort",
".",
"Strings",
"(",
"failedResources",
")",
"\n",
"err",
":=",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"failedResources",
")",
"\n",
"return",
"allExternalErrors",
",",
"hasRetriableResourceErr",
"||",
"handleProcessRetriable",
",",
"err",
"\n",
"}",
"\n\n",
"// Otherwise, return the result from handleProcessResult",
"return",
"false",
",",
"handleProcessRetriable",
",",
"handleProcessErr",
"\n",
"}"
] |
// ProcessBundle is only visible for testing purposes. Should not be called directly.
|
[
"ProcessBundle",
"is",
"only",
"visible",
"for",
"testing",
"purposes",
".",
"Should",
"not",
"be",
"called",
"directly",
"."
] |
e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438
|
https://github.com/atlassian/smith/blob/e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438/pkg/controller/bundlec/controller_worker.go#L18-L97
|
18,263 |
atlassian/smith
|
pkg/controller/bundlec/bundle_sync_task.go
|
findObjectsToDelete
|
func (st *bundleSyncTask) findObjectsToDelete() (bool /*external*/, bool /*retriable*/, error) {
objs, err := st.store.ObjectsControlledBy(st.bundle.Namespace, st.bundle.UID)
if err != nil {
return false, false, err
}
st.objectsToDelete = make(map[objectRef]runtime.Object, len(objs))
for _, obj := range objs {
m := obj.(meta_v1.Object)
ref := objectRef{
GroupVersionKind: obj.GetObjectKind().GroupVersionKind(),
Name: m.GetName(),
}
st.objectsToDelete[ref] = obj
}
for _, res := range st.bundle.Spec.Resources {
var gvk schema.GroupVersionKind
var name string
switch {
case res.Spec.Object != nil:
gvk = res.Spec.Object.GetObjectKind().GroupVersionKind()
name = res.Spec.Object.(meta_v1.Object).GetName()
case res.Spec.Plugin != nil:
// Any prevalidation during resource processing is applicable here as the cleanup step
// always happens regardless of if processing failed or not. Thus it makes more sense
// to abort the cleanup in case of an invalid spec.
plugin, ok := st.pluginContainers[res.Spec.Plugin.Name]
if !ok {
return true, false, errors.Errorf("plugin %q is not a valid plugin", res.Spec.Plugin.Name)
}
gvk = plugin.Plugin.Describe().GVK
name = res.Spec.Plugin.ObjectName
default:
// neither "object" nor "plugin" field is specified. This shouldn't really happen (schema), so we
// should abort the deletion as a defensive mechanism for safety.
return true, false, errors.New("resource is neither object nor plugin")
}
delete(st.objectsToDelete, objectRef{
GroupVersionKind: gvk,
Name: name,
})
}
return false, false, nil
}
|
go
|
func (st *bundleSyncTask) findObjectsToDelete() (bool /*external*/, bool /*retriable*/, error) {
objs, err := st.store.ObjectsControlledBy(st.bundle.Namespace, st.bundle.UID)
if err != nil {
return false, false, err
}
st.objectsToDelete = make(map[objectRef]runtime.Object, len(objs))
for _, obj := range objs {
m := obj.(meta_v1.Object)
ref := objectRef{
GroupVersionKind: obj.GetObjectKind().GroupVersionKind(),
Name: m.GetName(),
}
st.objectsToDelete[ref] = obj
}
for _, res := range st.bundle.Spec.Resources {
var gvk schema.GroupVersionKind
var name string
switch {
case res.Spec.Object != nil:
gvk = res.Spec.Object.GetObjectKind().GroupVersionKind()
name = res.Spec.Object.(meta_v1.Object).GetName()
case res.Spec.Plugin != nil:
// Any prevalidation during resource processing is applicable here as the cleanup step
// always happens regardless of if processing failed or not. Thus it makes more sense
// to abort the cleanup in case of an invalid spec.
plugin, ok := st.pluginContainers[res.Spec.Plugin.Name]
if !ok {
return true, false, errors.Errorf("plugin %q is not a valid plugin", res.Spec.Plugin.Name)
}
gvk = plugin.Plugin.Describe().GVK
name = res.Spec.Plugin.ObjectName
default:
// neither "object" nor "plugin" field is specified. This shouldn't really happen (schema), so we
// should abort the deletion as a defensive mechanism for safety.
return true, false, errors.New("resource is neither object nor plugin")
}
delete(st.objectsToDelete, objectRef{
GroupVersionKind: gvk,
Name: name,
})
}
return false, false, nil
}
|
[
"func",
"(",
"st",
"*",
"bundleSyncTask",
")",
"findObjectsToDelete",
"(",
")",
"(",
"bool",
"/*external*/",
",",
"bool",
"/*retriable*/",
",",
"error",
")",
"{",
"objs",
",",
"err",
":=",
"st",
".",
"store",
".",
"ObjectsControlledBy",
"(",
"st",
".",
"bundle",
".",
"Namespace",
",",
"st",
".",
"bundle",
".",
"UID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"false",
",",
"err",
"\n",
"}",
"\n",
"st",
".",
"objectsToDelete",
"=",
"make",
"(",
"map",
"[",
"objectRef",
"]",
"runtime",
".",
"Object",
",",
"len",
"(",
"objs",
")",
")",
"\n",
"for",
"_",
",",
"obj",
":=",
"range",
"objs",
"{",
"m",
":=",
"obj",
".",
"(",
"meta_v1",
".",
"Object",
")",
"\n",
"ref",
":=",
"objectRef",
"{",
"GroupVersionKind",
":",
"obj",
".",
"GetObjectKind",
"(",
")",
".",
"GroupVersionKind",
"(",
")",
",",
"Name",
":",
"m",
".",
"GetName",
"(",
")",
",",
"}",
"\n",
"st",
".",
"objectsToDelete",
"[",
"ref",
"]",
"=",
"obj",
"\n",
"}",
"\n",
"for",
"_",
",",
"res",
":=",
"range",
"st",
".",
"bundle",
".",
"Spec",
".",
"Resources",
"{",
"var",
"gvk",
"schema",
".",
"GroupVersionKind",
"\n",
"var",
"name",
"string",
"\n\n",
"switch",
"{",
"case",
"res",
".",
"Spec",
".",
"Object",
"!=",
"nil",
":",
"gvk",
"=",
"res",
".",
"Spec",
".",
"Object",
".",
"GetObjectKind",
"(",
")",
".",
"GroupVersionKind",
"(",
")",
"\n",
"name",
"=",
"res",
".",
"Spec",
".",
"Object",
".",
"(",
"meta_v1",
".",
"Object",
")",
".",
"GetName",
"(",
")",
"\n\n",
"case",
"res",
".",
"Spec",
".",
"Plugin",
"!=",
"nil",
":",
"// Any prevalidation during resource processing is applicable here as the cleanup step",
"// always happens regardless of if processing failed or not. Thus it makes more sense",
"// to abort the cleanup in case of an invalid spec.",
"plugin",
",",
"ok",
":=",
"st",
".",
"pluginContainers",
"[",
"res",
".",
"Spec",
".",
"Plugin",
".",
"Name",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"true",
",",
"false",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"res",
".",
"Spec",
".",
"Plugin",
".",
"Name",
")",
"\n",
"}",
"\n",
"gvk",
"=",
"plugin",
".",
"Plugin",
".",
"Describe",
"(",
")",
".",
"GVK",
"\n",
"name",
"=",
"res",
".",
"Spec",
".",
"Plugin",
".",
"ObjectName",
"\n",
"default",
":",
"// neither \"object\" nor \"plugin\" field is specified. This shouldn't really happen (schema), so we",
"// should abort the deletion as a defensive mechanism for safety.",
"return",
"true",
",",
"false",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"delete",
"(",
"st",
".",
"objectsToDelete",
",",
"objectRef",
"{",
"GroupVersionKind",
":",
"gvk",
",",
"Name",
":",
"name",
",",
"}",
")",
"\n",
"}",
"\n",
"return",
"false",
",",
"false",
",",
"nil",
"\n",
"}"
] |
// findObjectsToDelete initializes objectsToDelete field with objects that have controller owner references to
// the Bundle being processed but are not defined in it.
|
[
"findObjectsToDelete",
"initializes",
"objectsToDelete",
"field",
"with",
"objects",
"that",
"have",
"controller",
"owner",
"references",
"to",
"the",
"Bundle",
"being",
"processed",
"but",
"are",
"not",
"defined",
"in",
"it",
"."
] |
e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438
|
https://github.com/atlassian/smith/blob/e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438/pkg/controller/bundlec/bundle_sync_task.go#L234-L280
|
18,264 |
atlassian/smith
|
pkg/controller/bundlec/bundle_sync_task.go
|
pluginStatuses
|
func (st *bundleSyncTask) pluginStatuses() []smith_v1.PluginStatus {
// Plugin statuses
name2status := make(map[smith_v1.PluginName]struct{})
// most likely will be of the same size as before
pluginStatuses := make([]smith_v1.PluginStatus, 0, len(st.bundle.Status.PluginStatuses))
for _, res := range st.bundle.Spec.Resources { // Deterministic iteration order
if res.Spec.Plugin == nil {
continue // Not a plugin
}
pluginName := res.Spec.Plugin.Name
if _, ok := name2status[pluginName]; ok {
continue // Already reported
}
name2status[pluginName] = struct{}{}
var pluginStatus smith_v1.PluginStatus
pluginContainer, ok := st.pluginContainers[pluginName]
if ok {
describe := pluginContainer.Plugin.Describe()
pluginStatus = smith_v1.PluginStatus{
Name: pluginName,
Group: describe.GVK.Group,
Version: describe.GVK.Version,
Kind: describe.GVK.Kind,
Status: smith_v1.PluginStatusOk,
}
} else {
pluginStatus = smith_v1.PluginStatus{
Name: pluginName,
Status: smith_v1.PluginStatusNoSuchPlugin,
}
}
pluginStatuses = append(pluginStatuses, pluginStatus)
}
return pluginStatuses
}
|
go
|
func (st *bundleSyncTask) pluginStatuses() []smith_v1.PluginStatus {
// Plugin statuses
name2status := make(map[smith_v1.PluginName]struct{})
// most likely will be of the same size as before
pluginStatuses := make([]smith_v1.PluginStatus, 0, len(st.bundle.Status.PluginStatuses))
for _, res := range st.bundle.Spec.Resources { // Deterministic iteration order
if res.Spec.Plugin == nil {
continue // Not a plugin
}
pluginName := res.Spec.Plugin.Name
if _, ok := name2status[pluginName]; ok {
continue // Already reported
}
name2status[pluginName] = struct{}{}
var pluginStatus smith_v1.PluginStatus
pluginContainer, ok := st.pluginContainers[pluginName]
if ok {
describe := pluginContainer.Plugin.Describe()
pluginStatus = smith_v1.PluginStatus{
Name: pluginName,
Group: describe.GVK.Group,
Version: describe.GVK.Version,
Kind: describe.GVK.Kind,
Status: smith_v1.PluginStatusOk,
}
} else {
pluginStatus = smith_v1.PluginStatus{
Name: pluginName,
Status: smith_v1.PluginStatusNoSuchPlugin,
}
}
pluginStatuses = append(pluginStatuses, pluginStatus)
}
return pluginStatuses
}
|
[
"func",
"(",
"st",
"*",
"bundleSyncTask",
")",
"pluginStatuses",
"(",
")",
"[",
"]",
"smith_v1",
".",
"PluginStatus",
"{",
"// Plugin statuses",
"name2status",
":=",
"make",
"(",
"map",
"[",
"smith_v1",
".",
"PluginName",
"]",
"struct",
"{",
"}",
")",
"\n",
"// most likely will be of the same size as before",
"pluginStatuses",
":=",
"make",
"(",
"[",
"]",
"smith_v1",
".",
"PluginStatus",
",",
"0",
",",
"len",
"(",
"st",
".",
"bundle",
".",
"Status",
".",
"PluginStatuses",
")",
")",
"\n",
"for",
"_",
",",
"res",
":=",
"range",
"st",
".",
"bundle",
".",
"Spec",
".",
"Resources",
"{",
"// Deterministic iteration order",
"if",
"res",
".",
"Spec",
".",
"Plugin",
"==",
"nil",
"{",
"continue",
"// Not a plugin",
"\n",
"}",
"\n",
"pluginName",
":=",
"res",
".",
"Spec",
".",
"Plugin",
".",
"Name",
"\n",
"if",
"_",
",",
"ok",
":=",
"name2status",
"[",
"pluginName",
"]",
";",
"ok",
"{",
"continue",
"// Already reported",
"\n",
"}",
"\n",
"name2status",
"[",
"pluginName",
"]",
"=",
"struct",
"{",
"}",
"{",
"}",
"\n",
"var",
"pluginStatus",
"smith_v1",
".",
"PluginStatus",
"\n",
"pluginContainer",
",",
"ok",
":=",
"st",
".",
"pluginContainers",
"[",
"pluginName",
"]",
"\n",
"if",
"ok",
"{",
"describe",
":=",
"pluginContainer",
".",
"Plugin",
".",
"Describe",
"(",
")",
"\n",
"pluginStatus",
"=",
"smith_v1",
".",
"PluginStatus",
"{",
"Name",
":",
"pluginName",
",",
"Group",
":",
"describe",
".",
"GVK",
".",
"Group",
",",
"Version",
":",
"describe",
".",
"GVK",
".",
"Version",
",",
"Kind",
":",
"describe",
".",
"GVK",
".",
"Kind",
",",
"Status",
":",
"smith_v1",
".",
"PluginStatusOk",
",",
"}",
"\n",
"}",
"else",
"{",
"pluginStatus",
"=",
"smith_v1",
".",
"PluginStatus",
"{",
"Name",
":",
"pluginName",
",",
"Status",
":",
"smith_v1",
".",
"PluginStatusNoSuchPlugin",
",",
"}",
"\n",
"}",
"\n",
"pluginStatuses",
"=",
"append",
"(",
"pluginStatuses",
",",
"pluginStatus",
")",
"\n",
"}",
"\n",
"return",
"pluginStatuses",
"\n",
"}"
] |
// pluginStatuses visits each valid Plugin just once, collecting its PluginStatus.
|
[
"pluginStatuses",
"visits",
"each",
"valid",
"Plugin",
"just",
"once",
"collecting",
"its",
"PluginStatus",
"."
] |
e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438
|
https://github.com/atlassian/smith/blob/e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438/pkg/controller/bundlec/bundle_sync_task.go#L599-L633
|
18,265 |
atlassian/smith
|
pkg/controller/bundlec/bundle_sync_task.go
|
resourceConditions
|
func (st *bundleSyncTask) resourceConditions(res smith_v1.Resource) (
cond_v1.Condition, /* blockedCond */
cond_v1.Condition, /* inProgressCond */
cond_v1.Condition, /* readyCond */
cond_v1.Condition, /* errorCond */
) {
blockedCond := cond_v1.Condition{Type: smith_v1.ResourceBlocked, Status: cond_v1.ConditionFalse}
inProgressCond := cond_v1.Condition{Type: smith_v1.ResourceInProgress, Status: cond_v1.ConditionFalse}
readyCond := cond_v1.Condition{Type: smith_v1.ResourceReady, Status: cond_v1.ConditionFalse}
errorCond := cond_v1.Condition{Type: smith_v1.ResourceError, Status: cond_v1.ConditionFalse}
if resInfo, ok := st.processedResources[res.Name]; ok {
// Resource was processed
switch resStatus := resInfo.status.(type) {
case resourceStatusDependenciesNotReady:
blockedCond.Status = cond_v1.ConditionTrue
blockedCond.Reason = smith_v1.ResourceReasonDependenciesNotReady
blockedCond.Message = fmt.Sprintf("Not ready: %q", resStatus.dependencies)
case resourceStatusInProgress:
inProgressCond.Status = cond_v1.ConditionTrue
inProgressCond.Message = resStatus.message
case resourceStatusReady:
readyCond.Status = cond_v1.ConditionTrue
readyCond.Message = resStatus.message
case resourceStatusError:
errorCond.Status = cond_v1.ConditionTrue
errorCond.Message = resStatus.err.Error()
if resStatus.isRetriableError {
errorCond.Reason = smith_v1.ResourceReasonRetriableError
inProgressCond.Status = cond_v1.ConditionTrue
} else {
errorCond.Reason = smith_v1.ResourceReasonTerminalError
}
default:
blockedCond.Status = cond_v1.ConditionUnknown
inProgressCond.Status = cond_v1.ConditionUnknown
readyCond.Status = cond_v1.ConditionUnknown
errorCond.Status = cond_v1.ConditionTrue
errorCond.Reason = smith_v1.ResourceReasonTerminalError
errorCond.Message = fmt.Sprintf("internal error - unknown resource status type %T", resInfo.status)
}
} else {
// Resource was not processed
blockedCond.Status = cond_v1.ConditionUnknown
inProgressCond.Status = cond_v1.ConditionUnknown
readyCond.Status = cond_v1.ConditionUnknown
errorCond.Status = cond_v1.ConditionUnknown
}
return blockedCond, inProgressCond, readyCond, errorCond
}
|
go
|
func (st *bundleSyncTask) resourceConditions(res smith_v1.Resource) (
cond_v1.Condition, /* blockedCond */
cond_v1.Condition, /* inProgressCond */
cond_v1.Condition, /* readyCond */
cond_v1.Condition, /* errorCond */
) {
blockedCond := cond_v1.Condition{Type: smith_v1.ResourceBlocked, Status: cond_v1.ConditionFalse}
inProgressCond := cond_v1.Condition{Type: smith_v1.ResourceInProgress, Status: cond_v1.ConditionFalse}
readyCond := cond_v1.Condition{Type: smith_v1.ResourceReady, Status: cond_v1.ConditionFalse}
errorCond := cond_v1.Condition{Type: smith_v1.ResourceError, Status: cond_v1.ConditionFalse}
if resInfo, ok := st.processedResources[res.Name]; ok {
// Resource was processed
switch resStatus := resInfo.status.(type) {
case resourceStatusDependenciesNotReady:
blockedCond.Status = cond_v1.ConditionTrue
blockedCond.Reason = smith_v1.ResourceReasonDependenciesNotReady
blockedCond.Message = fmt.Sprintf("Not ready: %q", resStatus.dependencies)
case resourceStatusInProgress:
inProgressCond.Status = cond_v1.ConditionTrue
inProgressCond.Message = resStatus.message
case resourceStatusReady:
readyCond.Status = cond_v1.ConditionTrue
readyCond.Message = resStatus.message
case resourceStatusError:
errorCond.Status = cond_v1.ConditionTrue
errorCond.Message = resStatus.err.Error()
if resStatus.isRetriableError {
errorCond.Reason = smith_v1.ResourceReasonRetriableError
inProgressCond.Status = cond_v1.ConditionTrue
} else {
errorCond.Reason = smith_v1.ResourceReasonTerminalError
}
default:
blockedCond.Status = cond_v1.ConditionUnknown
inProgressCond.Status = cond_v1.ConditionUnknown
readyCond.Status = cond_v1.ConditionUnknown
errorCond.Status = cond_v1.ConditionTrue
errorCond.Reason = smith_v1.ResourceReasonTerminalError
errorCond.Message = fmt.Sprintf("internal error - unknown resource status type %T", resInfo.status)
}
} else {
// Resource was not processed
blockedCond.Status = cond_v1.ConditionUnknown
inProgressCond.Status = cond_v1.ConditionUnknown
readyCond.Status = cond_v1.ConditionUnknown
errorCond.Status = cond_v1.ConditionUnknown
}
return blockedCond, inProgressCond, readyCond, errorCond
}
|
[
"func",
"(",
"st",
"*",
"bundleSyncTask",
")",
"resourceConditions",
"(",
"res",
"smith_v1",
".",
"Resource",
")",
"(",
"cond_v1",
".",
"Condition",
",",
"/* blockedCond */",
"cond_v1",
".",
"Condition",
",",
"/* inProgressCond */",
"cond_v1",
".",
"Condition",
",",
"/* readyCond */",
"cond_v1",
".",
"Condition",
",",
"/* errorCond */",
")",
"{",
"blockedCond",
":=",
"cond_v1",
".",
"Condition",
"{",
"Type",
":",
"smith_v1",
".",
"ResourceBlocked",
",",
"Status",
":",
"cond_v1",
".",
"ConditionFalse",
"}",
"\n",
"inProgressCond",
":=",
"cond_v1",
".",
"Condition",
"{",
"Type",
":",
"smith_v1",
".",
"ResourceInProgress",
",",
"Status",
":",
"cond_v1",
".",
"ConditionFalse",
"}",
"\n",
"readyCond",
":=",
"cond_v1",
".",
"Condition",
"{",
"Type",
":",
"smith_v1",
".",
"ResourceReady",
",",
"Status",
":",
"cond_v1",
".",
"ConditionFalse",
"}",
"\n",
"errorCond",
":=",
"cond_v1",
".",
"Condition",
"{",
"Type",
":",
"smith_v1",
".",
"ResourceError",
",",
"Status",
":",
"cond_v1",
".",
"ConditionFalse",
"}",
"\n\n",
"if",
"resInfo",
",",
"ok",
":=",
"st",
".",
"processedResources",
"[",
"res",
".",
"Name",
"]",
";",
"ok",
"{",
"// Resource was processed",
"switch",
"resStatus",
":=",
"resInfo",
".",
"status",
".",
"(",
"type",
")",
"{",
"case",
"resourceStatusDependenciesNotReady",
":",
"blockedCond",
".",
"Status",
"=",
"cond_v1",
".",
"ConditionTrue",
"\n",
"blockedCond",
".",
"Reason",
"=",
"smith_v1",
".",
"ResourceReasonDependenciesNotReady",
"\n",
"blockedCond",
".",
"Message",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"resStatus",
".",
"dependencies",
")",
"\n",
"case",
"resourceStatusInProgress",
":",
"inProgressCond",
".",
"Status",
"=",
"cond_v1",
".",
"ConditionTrue",
"\n",
"inProgressCond",
".",
"Message",
"=",
"resStatus",
".",
"message",
"\n",
"case",
"resourceStatusReady",
":",
"readyCond",
".",
"Status",
"=",
"cond_v1",
".",
"ConditionTrue",
"\n",
"readyCond",
".",
"Message",
"=",
"resStatus",
".",
"message",
"\n",
"case",
"resourceStatusError",
":",
"errorCond",
".",
"Status",
"=",
"cond_v1",
".",
"ConditionTrue",
"\n",
"errorCond",
".",
"Message",
"=",
"resStatus",
".",
"err",
".",
"Error",
"(",
")",
"\n",
"if",
"resStatus",
".",
"isRetriableError",
"{",
"errorCond",
".",
"Reason",
"=",
"smith_v1",
".",
"ResourceReasonRetriableError",
"\n",
"inProgressCond",
".",
"Status",
"=",
"cond_v1",
".",
"ConditionTrue",
"\n",
"}",
"else",
"{",
"errorCond",
".",
"Reason",
"=",
"smith_v1",
".",
"ResourceReasonTerminalError",
"\n",
"}",
"\n",
"default",
":",
"blockedCond",
".",
"Status",
"=",
"cond_v1",
".",
"ConditionUnknown",
"\n",
"inProgressCond",
".",
"Status",
"=",
"cond_v1",
".",
"ConditionUnknown",
"\n",
"readyCond",
".",
"Status",
"=",
"cond_v1",
".",
"ConditionUnknown",
"\n",
"errorCond",
".",
"Status",
"=",
"cond_v1",
".",
"ConditionTrue",
"\n",
"errorCond",
".",
"Reason",
"=",
"smith_v1",
".",
"ResourceReasonTerminalError",
"\n",
"errorCond",
".",
"Message",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"resInfo",
".",
"status",
")",
"\n",
"}",
"\n",
"}",
"else",
"{",
"// Resource was not processed",
"blockedCond",
".",
"Status",
"=",
"cond_v1",
".",
"ConditionUnknown",
"\n",
"inProgressCond",
".",
"Status",
"=",
"cond_v1",
".",
"ConditionUnknown",
"\n",
"readyCond",
".",
"Status",
"=",
"cond_v1",
".",
"ConditionUnknown",
"\n",
"errorCond",
".",
"Status",
"=",
"cond_v1",
".",
"ConditionUnknown",
"\n",
"}",
"\n\n",
"return",
"blockedCond",
",",
"inProgressCond",
",",
"readyCond",
",",
"errorCond",
"\n",
"}"
] |
// resourceConditions calculates conditions for a given Resource,
// which can be useful when determining whether to retry or not.
|
[
"resourceConditions",
"calculates",
"conditions",
"for",
"a",
"given",
"Resource",
"which",
"can",
"be",
"useful",
"when",
"determining",
"whether",
"to",
"retry",
"or",
"not",
"."
] |
e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438
|
https://github.com/atlassian/smith/blob/e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438/pkg/controller/bundlec/bundle_sync_task.go#L637-L687
|
18,266 |
atlassian/smith
|
pkg/controller/bundlec/bundle_sync_task.go
|
checkBundleConditionNeedsUpdate
|
func (st *bundleSyncTask) checkBundleConditionNeedsUpdate(condition *cond_v1.Condition) bool {
now := meta_v1.Now()
condition.LastTransitionTime = now
needsUpdate := cond_v1.PrepareCondition(st.bundle.Status.Conditions, condition)
if needsUpdate && condition.Status == cond_v1.ConditionTrue {
st.bundleTransitionCounter.
WithLabelValues(st.bundle.GetNamespace(), st.bundle.GetName(), string(condition.Type), condition.Reason).
Inc()
eventAnnotations := map[string]string{
smith.EventAnnotationReason: condition.Reason,
}
var eventType string
var reason string
switch condition.Type {
case smith_v1.BundleError:
eventType = core_v1.EventTypeWarning
reason = smith.EventReasonBundleError
case smith_v1.BundleInProgress:
eventType = core_v1.EventTypeNormal
reason = smith.EventReasonBundleInProgress
case smith_v1.BundleReady:
eventType = core_v1.EventTypeNormal
reason = smith.EventReasonBundleReady
default:
st.logger.Sugar().Errorf("Unexpected bundle condition type %q", condition.Type)
eventType = core_v1.EventTypeWarning
reason = smith.EventReasonUnknown
}
st.recorder.AnnotatedEventf(st.bundle, eventAnnotations, eventType, reason, condition.Message)
}
// Return true if one of the fields have changed.
return needsUpdate
}
|
go
|
func (st *bundleSyncTask) checkBundleConditionNeedsUpdate(condition *cond_v1.Condition) bool {
now := meta_v1.Now()
condition.LastTransitionTime = now
needsUpdate := cond_v1.PrepareCondition(st.bundle.Status.Conditions, condition)
if needsUpdate && condition.Status == cond_v1.ConditionTrue {
st.bundleTransitionCounter.
WithLabelValues(st.bundle.GetNamespace(), st.bundle.GetName(), string(condition.Type), condition.Reason).
Inc()
eventAnnotations := map[string]string{
smith.EventAnnotationReason: condition.Reason,
}
var eventType string
var reason string
switch condition.Type {
case smith_v1.BundleError:
eventType = core_v1.EventTypeWarning
reason = smith.EventReasonBundleError
case smith_v1.BundleInProgress:
eventType = core_v1.EventTypeNormal
reason = smith.EventReasonBundleInProgress
case smith_v1.BundleReady:
eventType = core_v1.EventTypeNormal
reason = smith.EventReasonBundleReady
default:
st.logger.Sugar().Errorf("Unexpected bundle condition type %q", condition.Type)
eventType = core_v1.EventTypeWarning
reason = smith.EventReasonUnknown
}
st.recorder.AnnotatedEventf(st.bundle, eventAnnotations, eventType, reason, condition.Message)
}
// Return true if one of the fields have changed.
return needsUpdate
}
|
[
"func",
"(",
"st",
"*",
"bundleSyncTask",
")",
"checkBundleConditionNeedsUpdate",
"(",
"condition",
"*",
"cond_v1",
".",
"Condition",
")",
"bool",
"{",
"now",
":=",
"meta_v1",
".",
"Now",
"(",
")",
"\n",
"condition",
".",
"LastTransitionTime",
"=",
"now",
"\n\n",
"needsUpdate",
":=",
"cond_v1",
".",
"PrepareCondition",
"(",
"st",
".",
"bundle",
".",
"Status",
".",
"Conditions",
",",
"condition",
")",
"\n\n",
"if",
"needsUpdate",
"&&",
"condition",
".",
"Status",
"==",
"cond_v1",
".",
"ConditionTrue",
"{",
"st",
".",
"bundleTransitionCounter",
".",
"WithLabelValues",
"(",
"st",
".",
"bundle",
".",
"GetNamespace",
"(",
")",
",",
"st",
".",
"bundle",
".",
"GetName",
"(",
")",
",",
"string",
"(",
"condition",
".",
"Type",
")",
",",
"condition",
".",
"Reason",
")",
".",
"Inc",
"(",
")",
"\n\n",
"eventAnnotations",
":=",
"map",
"[",
"string",
"]",
"string",
"{",
"smith",
".",
"EventAnnotationReason",
":",
"condition",
".",
"Reason",
",",
"}",
"\n",
"var",
"eventType",
"string",
"\n",
"var",
"reason",
"string",
"\n",
"switch",
"condition",
".",
"Type",
"{",
"case",
"smith_v1",
".",
"BundleError",
":",
"eventType",
"=",
"core_v1",
".",
"EventTypeWarning",
"\n",
"reason",
"=",
"smith",
".",
"EventReasonBundleError",
"\n",
"case",
"smith_v1",
".",
"BundleInProgress",
":",
"eventType",
"=",
"core_v1",
".",
"EventTypeNormal",
"\n",
"reason",
"=",
"smith",
".",
"EventReasonBundleInProgress",
"\n",
"case",
"smith_v1",
".",
"BundleReady",
":",
"eventType",
"=",
"core_v1",
".",
"EventTypeNormal",
"\n",
"reason",
"=",
"smith",
".",
"EventReasonBundleReady",
"\n",
"default",
":",
"st",
".",
"logger",
".",
"Sugar",
"(",
")",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"condition",
".",
"Type",
")",
"\n",
"eventType",
"=",
"core_v1",
".",
"EventTypeWarning",
"\n",
"reason",
"=",
"smith",
".",
"EventReasonUnknown",
"\n",
"}",
"\n",
"st",
".",
"recorder",
".",
"AnnotatedEventf",
"(",
"st",
".",
"bundle",
",",
"eventAnnotations",
",",
"eventType",
",",
"reason",
",",
"condition",
".",
"Message",
")",
"\n",
"}",
"\n\n",
"// Return true if one of the fields have changed.",
"return",
"needsUpdate",
"\n",
"}"
] |
// checkBundleConditionNeedsUpdate updates passed condition by fetching information from an existing resource condition if present.
// Sets LastTransitionTime to now if the status has changed.
// Returns true if resource condition in the bundle does not match and needs to be updated.
|
[
"checkBundleConditionNeedsUpdate",
"updates",
"passed",
"condition",
"by",
"fetching",
"information",
"from",
"an",
"existing",
"resource",
"condition",
"if",
"present",
".",
"Sets",
"LastTransitionTime",
"to",
"now",
"if",
"the",
"status",
"has",
"changed",
".",
"Returns",
"true",
"if",
"resource",
"condition",
"in",
"the",
"bundle",
"does",
"not",
"match",
"and",
"needs",
"to",
"be",
"updated",
"."
] |
e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438
|
https://github.com/atlassian/smith/blob/e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438/pkg/controller/bundlec/bundle_sync_task.go#L692-L728
|
18,267 |
atlassian/smith
|
pkg/controller/bundlec/bundle_sync_task.go
|
checkResourceConditionNeedsUpdate
|
func (st *bundleSyncTask) checkResourceConditionNeedsUpdate(resName smith_v1.ResourceName, condition *cond_v1.Condition) bool {
now := meta_v1.Now()
condition.LastTransitionTime = now
needsUpdate := true
// Try to find this resource status
_, status := st.bundle.Status.GetResourceStatus(resName)
if status != nil {
needsUpdate = cond_v1.PrepareCondition(status.Conditions, condition)
}
// Otherwise, no status for this resource, hence it's a new resource condition
if needsUpdate && condition.Status == cond_v1.ConditionTrue {
st.bundleResourceTransitionCounter.
WithLabelValues(st.bundle.GetNamespace(), st.bundle.GetName(), string(resName), string(condition.Type), condition.Reason).
Inc()
// blocked events are ignored because it's too spammy
if condition.Type != smith_v1.ResourceBlocked {
eventAnnotations := map[string]string{
smith.EventAnnotationResourceName: string(resName),
smith.EventAnnotationReason: condition.Reason,
}
var reason string
var eventType string
switch condition.Type {
case smith_v1.ResourceError:
eventType = core_v1.EventTypeWarning
reason = smith.EventReasonResourceError
case smith_v1.ResourceInProgress:
eventType = core_v1.EventTypeNormal
reason = smith.EventReasonResourceInProgress
case smith_v1.ResourceReady:
eventType = core_v1.EventTypeNormal
reason = smith.EventReasonResourceReady
default:
st.logger.Sugar().Errorf("Unexpected resource condition type %q", condition.Type)
eventType = core_v1.EventTypeWarning
reason = smith.EventReasonUnknown
}
st.recorder.AnnotatedEventf(st.bundle, eventAnnotations, eventType, reason, condition.Message)
}
}
// Return true if one of the fields have changed.
return needsUpdate
}
|
go
|
func (st *bundleSyncTask) checkResourceConditionNeedsUpdate(resName smith_v1.ResourceName, condition *cond_v1.Condition) bool {
now := meta_v1.Now()
condition.LastTransitionTime = now
needsUpdate := true
// Try to find this resource status
_, status := st.bundle.Status.GetResourceStatus(resName)
if status != nil {
needsUpdate = cond_v1.PrepareCondition(status.Conditions, condition)
}
// Otherwise, no status for this resource, hence it's a new resource condition
if needsUpdate && condition.Status == cond_v1.ConditionTrue {
st.bundleResourceTransitionCounter.
WithLabelValues(st.bundle.GetNamespace(), st.bundle.GetName(), string(resName), string(condition.Type), condition.Reason).
Inc()
// blocked events are ignored because it's too spammy
if condition.Type != smith_v1.ResourceBlocked {
eventAnnotations := map[string]string{
smith.EventAnnotationResourceName: string(resName),
smith.EventAnnotationReason: condition.Reason,
}
var reason string
var eventType string
switch condition.Type {
case smith_v1.ResourceError:
eventType = core_v1.EventTypeWarning
reason = smith.EventReasonResourceError
case smith_v1.ResourceInProgress:
eventType = core_v1.EventTypeNormal
reason = smith.EventReasonResourceInProgress
case smith_v1.ResourceReady:
eventType = core_v1.EventTypeNormal
reason = smith.EventReasonResourceReady
default:
st.logger.Sugar().Errorf("Unexpected resource condition type %q", condition.Type)
eventType = core_v1.EventTypeWarning
reason = smith.EventReasonUnknown
}
st.recorder.AnnotatedEventf(st.bundle, eventAnnotations, eventType, reason, condition.Message)
}
}
// Return true if one of the fields have changed.
return needsUpdate
}
|
[
"func",
"(",
"st",
"*",
"bundleSyncTask",
")",
"checkResourceConditionNeedsUpdate",
"(",
"resName",
"smith_v1",
".",
"ResourceName",
",",
"condition",
"*",
"cond_v1",
".",
"Condition",
")",
"bool",
"{",
"now",
":=",
"meta_v1",
".",
"Now",
"(",
")",
"\n",
"condition",
".",
"LastTransitionTime",
"=",
"now",
"\n\n",
"needsUpdate",
":=",
"true",
"\n\n",
"// Try to find this resource status",
"_",
",",
"status",
":=",
"st",
".",
"bundle",
".",
"Status",
".",
"GetResourceStatus",
"(",
"resName",
")",
"\n\n",
"if",
"status",
"!=",
"nil",
"{",
"needsUpdate",
"=",
"cond_v1",
".",
"PrepareCondition",
"(",
"status",
".",
"Conditions",
",",
"condition",
")",
"\n",
"}",
"\n\n",
"// Otherwise, no status for this resource, hence it's a new resource condition",
"if",
"needsUpdate",
"&&",
"condition",
".",
"Status",
"==",
"cond_v1",
".",
"ConditionTrue",
"{",
"st",
".",
"bundleResourceTransitionCounter",
".",
"WithLabelValues",
"(",
"st",
".",
"bundle",
".",
"GetNamespace",
"(",
")",
",",
"st",
".",
"bundle",
".",
"GetName",
"(",
")",
",",
"string",
"(",
"resName",
")",
",",
"string",
"(",
"condition",
".",
"Type",
")",
",",
"condition",
".",
"Reason",
")",
".",
"Inc",
"(",
")",
"\n\n",
"// blocked events are ignored because it's too spammy",
"if",
"condition",
".",
"Type",
"!=",
"smith_v1",
".",
"ResourceBlocked",
"{",
"eventAnnotations",
":=",
"map",
"[",
"string",
"]",
"string",
"{",
"smith",
".",
"EventAnnotationResourceName",
":",
"string",
"(",
"resName",
")",
",",
"smith",
".",
"EventAnnotationReason",
":",
"condition",
".",
"Reason",
",",
"}",
"\n",
"var",
"reason",
"string",
"\n",
"var",
"eventType",
"string",
"\n",
"switch",
"condition",
".",
"Type",
"{",
"case",
"smith_v1",
".",
"ResourceError",
":",
"eventType",
"=",
"core_v1",
".",
"EventTypeWarning",
"\n",
"reason",
"=",
"smith",
".",
"EventReasonResourceError",
"\n",
"case",
"smith_v1",
".",
"ResourceInProgress",
":",
"eventType",
"=",
"core_v1",
".",
"EventTypeNormal",
"\n",
"reason",
"=",
"smith",
".",
"EventReasonResourceInProgress",
"\n",
"case",
"smith_v1",
".",
"ResourceReady",
":",
"eventType",
"=",
"core_v1",
".",
"EventTypeNormal",
"\n",
"reason",
"=",
"smith",
".",
"EventReasonResourceReady",
"\n",
"default",
":",
"st",
".",
"logger",
".",
"Sugar",
"(",
")",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"condition",
".",
"Type",
")",
"\n",
"eventType",
"=",
"core_v1",
".",
"EventTypeWarning",
"\n",
"reason",
"=",
"smith",
".",
"EventReasonUnknown",
"\n",
"}",
"\n",
"st",
".",
"recorder",
".",
"AnnotatedEventf",
"(",
"st",
".",
"bundle",
",",
"eventAnnotations",
",",
"eventType",
",",
"reason",
",",
"condition",
".",
"Message",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Return true if one of the fields have changed.",
"return",
"needsUpdate",
"\n",
"}"
] |
// checkResourceConditionNeedsUpdate updates passed condition by fetching information from an existing resource condition if present.
// Sets LastTransitionTime to now if the status has changed.
// Returns true if resource condition in the bundle does not match and needs to be updated.
|
[
"checkResourceConditionNeedsUpdate",
"updates",
"passed",
"condition",
"by",
"fetching",
"information",
"from",
"an",
"existing",
"resource",
"condition",
"if",
"present",
".",
"Sets",
"LastTransitionTime",
"to",
"now",
"if",
"the",
"status",
"has",
"changed",
".",
"Returns",
"true",
"if",
"resource",
"condition",
"in",
"the",
"bundle",
"does",
"not",
"match",
"and",
"needs",
"to",
"be",
"updated",
"."
] |
e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438
|
https://github.com/atlassian/smith/blob/e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438/pkg/controller/bundlec/bundle_sync_task.go#L733-L782
|
18,268 |
atlassian/smith
|
pkg/util/util.go
|
ConvertType
|
func ConvertType(scheme *runtime.Scheme, in, out runtime.Object) error {
in = in.DeepCopyObject()
if err := scheme.Convert(in, out, nil); err != nil {
return err
}
gvkOut := out.GetObjectKind().GroupVersionKind()
if gvkOut.Kind == "" || gvkOut.Version == "" { // Group can be empty
// API machinery discards TypeMeta for typed objects. This is annoying.
gvks, _, err := scheme.ObjectKinds(in)
if err != nil {
return err
}
out.GetObjectKind().SetGroupVersionKind(gvks[0])
}
return nil
}
|
go
|
func ConvertType(scheme *runtime.Scheme, in, out runtime.Object) error {
in = in.DeepCopyObject()
if err := scheme.Convert(in, out, nil); err != nil {
return err
}
gvkOut := out.GetObjectKind().GroupVersionKind()
if gvkOut.Kind == "" || gvkOut.Version == "" { // Group can be empty
// API machinery discards TypeMeta for typed objects. This is annoying.
gvks, _, err := scheme.ObjectKinds(in)
if err != nil {
return err
}
out.GetObjectKind().SetGroupVersionKind(gvks[0])
}
return nil
}
|
[
"func",
"ConvertType",
"(",
"scheme",
"*",
"runtime",
".",
"Scheme",
",",
"in",
",",
"out",
"runtime",
".",
"Object",
")",
"error",
"{",
"in",
"=",
"in",
".",
"DeepCopyObject",
"(",
")",
"\n",
"if",
"err",
":=",
"scheme",
".",
"Convert",
"(",
"in",
",",
"out",
",",
"nil",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"gvkOut",
":=",
"out",
".",
"GetObjectKind",
"(",
")",
".",
"GroupVersionKind",
"(",
")",
"\n",
"if",
"gvkOut",
".",
"Kind",
"==",
"\"",
"\"",
"||",
"gvkOut",
".",
"Version",
"==",
"\"",
"\"",
"{",
"// Group can be empty",
"// API machinery discards TypeMeta for typed objects. This is annoying.",
"gvks",
",",
"_",
",",
"err",
":=",
"scheme",
".",
"ObjectKinds",
"(",
"in",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"out",
".",
"GetObjectKind",
"(",
")",
".",
"SetGroupVersionKind",
"(",
"gvks",
"[",
"0",
"]",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// ConvertType should be used to convert to typed objects.
// If the in object is unstructured then it must have GVK set otherwise it must be
// recognizable by scheme or have the GVK set.
|
[
"ConvertType",
"should",
"be",
"used",
"to",
"convert",
"to",
"typed",
"objects",
".",
"If",
"the",
"in",
"object",
"is",
"unstructured",
"then",
"it",
"must",
"have",
"GVK",
"set",
"otherwise",
"it",
"must",
"be",
"recognizable",
"by",
"scheme",
"or",
"have",
"the",
"GVK",
"set",
"."
] |
e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438
|
https://github.com/atlassian/smith/blob/e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438/pkg/util/util.go#L27-L42
|
18,269 |
atlassian/smith
|
pkg/util/util.go
|
RuntimeToUnstructured
|
func RuntimeToUnstructured(obj runtime.Object) (*unstructured.Unstructured, error) {
gvk := obj.GetObjectKind().GroupVersionKind()
if gvk.Kind == "" || gvk.Version == "" { // Group can be empty
return nil, errors.Errorf("cannot convert %T to Unstructured: object Kind and/or object Version is empty", obj)
}
u, err := runtime.DefaultUnstructuredConverter.ToUnstructured(obj.DeepCopyObject())
if err != nil {
return nil, errors.WithStack(err)
}
return &unstructured.Unstructured{
Object: u,
}, nil
}
|
go
|
func RuntimeToUnstructured(obj runtime.Object) (*unstructured.Unstructured, error) {
gvk := obj.GetObjectKind().GroupVersionKind()
if gvk.Kind == "" || gvk.Version == "" { // Group can be empty
return nil, errors.Errorf("cannot convert %T to Unstructured: object Kind and/or object Version is empty", obj)
}
u, err := runtime.DefaultUnstructuredConverter.ToUnstructured(obj.DeepCopyObject())
if err != nil {
return nil, errors.WithStack(err)
}
return &unstructured.Unstructured{
Object: u,
}, nil
}
|
[
"func",
"RuntimeToUnstructured",
"(",
"obj",
"runtime",
".",
"Object",
")",
"(",
"*",
"unstructured",
".",
"Unstructured",
",",
"error",
")",
"{",
"gvk",
":=",
"obj",
".",
"GetObjectKind",
"(",
")",
".",
"GroupVersionKind",
"(",
")",
"\n",
"if",
"gvk",
".",
"Kind",
"==",
"\"",
"\"",
"||",
"gvk",
".",
"Version",
"==",
"\"",
"\"",
"{",
"// Group can be empty",
"return",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"obj",
")",
"\n",
"}",
"\n",
"u",
",",
"err",
":=",
"runtime",
".",
"DefaultUnstructuredConverter",
".",
"ToUnstructured",
"(",
"obj",
".",
"DeepCopyObject",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"WithStack",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"&",
"unstructured",
".",
"Unstructured",
"{",
"Object",
":",
"u",
",",
"}",
",",
"nil",
"\n",
"}"
] |
// RuntimeToUnstructured can be used to convert any typed or unstructured object into
// an unstructured object. The obj must have GVK set.
|
[
"RuntimeToUnstructured",
"can",
"be",
"used",
"to",
"convert",
"any",
"typed",
"or",
"unstructured",
"object",
"into",
"an",
"unstructured",
"object",
".",
"The",
"obj",
"must",
"have",
"GVK",
"set",
"."
] |
e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438
|
https://github.com/atlassian/smith/blob/e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438/pkg/util/util.go#L46-L58
|
18,270 |
atlassian/smith
|
pkg/controller/bundlec/resource_sync_task.go
|
evalPluginSpec
|
func (st *resourceSyncTask) evalPluginSpec(res *smith_v1.Resource, actual runtime.Object) (*unstructured.Unstructured, resourceStatus) {
pluginContainer, ok := st.pluginContainers[res.Spec.Plugin.Name]
if !ok {
return nil, resourceStatusError{
err: errors.Errorf("no such plugin %q", res.Spec.Plugin.Name),
isExternalError: true,
}
}
validationResult, err := pluginContainer.ValidateSpec(res.Spec.Plugin.Spec)
if err != nil {
return nil, resourceStatusError{err: err}
}
if len(validationResult.Errors) > 0 {
return nil, resourceStatusError{
err: errors.Wrap(k8s_errors.NewAggregate(validationResult.Errors), "spec failed validation against schema"),
isExternalError: true,
}
}
// validate above should guarantee that our plugin is there
dependencies, err := st.prepareDependencies(res.References)
if err != nil {
// there should be no error in processing dependencies. If there is, this
// is an internal issue.
return nil, resourceStatusError{
err: err,
}
}
result := pluginContainer.Plugin.Process(res.Spec.Plugin.Spec, &plugin.Context{
Namespace: st.bundle.Namespace,
Actual: actual,
Dependencies: dependencies,
})
var pluginObj runtime.Object
switch res := result.(type) {
case *plugin.ProcessResultSuccess:
pluginObj = res.Object
case *plugin.ProcessResultFailure:
return nil, resourceStatusError{
err: res.Error,
isRetriableError: res.IsRetriableError,
isExternalError: res.IsExternalError,
}
default:
return nil, resourceStatusError{
err: errors.Errorf("unexpected plugin result type %q", res.StatusType()),
}
}
// Make sure plugin is returning us something that obeys the PluginSpec.
object, err := util.RuntimeToUnstructured(pluginObj)
if err != nil {
return nil, resourceStatusError{
err: errors.Wrap(err, "plugin output cannot be converted from runtime.Object"),
}
}
expectedGVK := pluginContainer.Plugin.Describe().GVK
if object.GroupVersionKind() != expectedGVK {
return nil, resourceStatusError{
err: errors.Errorf("unexpected GVK from plugin (wanted %s, got %s)", expectedGVK, object.GroupVersionKind()),
}
}
// We are in charge of naming.
object.SetName(res.Spec.Plugin.ObjectName)
return object, nil
}
|
go
|
func (st *resourceSyncTask) evalPluginSpec(res *smith_v1.Resource, actual runtime.Object) (*unstructured.Unstructured, resourceStatus) {
pluginContainer, ok := st.pluginContainers[res.Spec.Plugin.Name]
if !ok {
return nil, resourceStatusError{
err: errors.Errorf("no such plugin %q", res.Spec.Plugin.Name),
isExternalError: true,
}
}
validationResult, err := pluginContainer.ValidateSpec(res.Spec.Plugin.Spec)
if err != nil {
return nil, resourceStatusError{err: err}
}
if len(validationResult.Errors) > 0 {
return nil, resourceStatusError{
err: errors.Wrap(k8s_errors.NewAggregate(validationResult.Errors), "spec failed validation against schema"),
isExternalError: true,
}
}
// validate above should guarantee that our plugin is there
dependencies, err := st.prepareDependencies(res.References)
if err != nil {
// there should be no error in processing dependencies. If there is, this
// is an internal issue.
return nil, resourceStatusError{
err: err,
}
}
result := pluginContainer.Plugin.Process(res.Spec.Plugin.Spec, &plugin.Context{
Namespace: st.bundle.Namespace,
Actual: actual,
Dependencies: dependencies,
})
var pluginObj runtime.Object
switch res := result.(type) {
case *plugin.ProcessResultSuccess:
pluginObj = res.Object
case *plugin.ProcessResultFailure:
return nil, resourceStatusError{
err: res.Error,
isRetriableError: res.IsRetriableError,
isExternalError: res.IsExternalError,
}
default:
return nil, resourceStatusError{
err: errors.Errorf("unexpected plugin result type %q", res.StatusType()),
}
}
// Make sure plugin is returning us something that obeys the PluginSpec.
object, err := util.RuntimeToUnstructured(pluginObj)
if err != nil {
return nil, resourceStatusError{
err: errors.Wrap(err, "plugin output cannot be converted from runtime.Object"),
}
}
expectedGVK := pluginContainer.Plugin.Describe().GVK
if object.GroupVersionKind() != expectedGVK {
return nil, resourceStatusError{
err: errors.Errorf("unexpected GVK from plugin (wanted %s, got %s)", expectedGVK, object.GroupVersionKind()),
}
}
// We are in charge of naming.
object.SetName(res.Spec.Plugin.ObjectName)
return object, nil
}
|
[
"func",
"(",
"st",
"*",
"resourceSyncTask",
")",
"evalPluginSpec",
"(",
"res",
"*",
"smith_v1",
".",
"Resource",
",",
"actual",
"runtime",
".",
"Object",
")",
"(",
"*",
"unstructured",
".",
"Unstructured",
",",
"resourceStatus",
")",
"{",
"pluginContainer",
",",
"ok",
":=",
"st",
".",
"pluginContainers",
"[",
"res",
".",
"Spec",
".",
"Plugin",
".",
"Name",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"resourceStatusError",
"{",
"err",
":",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"res",
".",
"Spec",
".",
"Plugin",
".",
"Name",
")",
",",
"isExternalError",
":",
"true",
",",
"}",
"\n",
"}",
"\n",
"validationResult",
",",
"err",
":=",
"pluginContainer",
".",
"ValidateSpec",
"(",
"res",
".",
"Spec",
".",
"Plugin",
".",
"Spec",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"resourceStatusError",
"{",
"err",
":",
"err",
"}",
"\n",
"}",
"\n",
"if",
"len",
"(",
"validationResult",
".",
"Errors",
")",
">",
"0",
"{",
"return",
"nil",
",",
"resourceStatusError",
"{",
"err",
":",
"errors",
".",
"Wrap",
"(",
"k8s_errors",
".",
"NewAggregate",
"(",
"validationResult",
".",
"Errors",
")",
",",
"\"",
"\"",
")",
",",
"isExternalError",
":",
"true",
",",
"}",
"\n",
"}",
"\n\n",
"// validate above should guarantee that our plugin is there",
"dependencies",
",",
"err",
":=",
"st",
".",
"prepareDependencies",
"(",
"res",
".",
"References",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"// there should be no error in processing dependencies. If there is, this",
"// is an internal issue.",
"return",
"nil",
",",
"resourceStatusError",
"{",
"err",
":",
"err",
",",
"}",
"\n",
"}",
"\n\n",
"result",
":=",
"pluginContainer",
".",
"Plugin",
".",
"Process",
"(",
"res",
".",
"Spec",
".",
"Plugin",
".",
"Spec",
",",
"&",
"plugin",
".",
"Context",
"{",
"Namespace",
":",
"st",
".",
"bundle",
".",
"Namespace",
",",
"Actual",
":",
"actual",
",",
"Dependencies",
":",
"dependencies",
",",
"}",
")",
"\n",
"var",
"pluginObj",
"runtime",
".",
"Object",
"\n",
"switch",
"res",
":=",
"result",
".",
"(",
"type",
")",
"{",
"case",
"*",
"plugin",
".",
"ProcessResultSuccess",
":",
"pluginObj",
"=",
"res",
".",
"Object",
"\n",
"case",
"*",
"plugin",
".",
"ProcessResultFailure",
":",
"return",
"nil",
",",
"resourceStatusError",
"{",
"err",
":",
"res",
".",
"Error",
",",
"isRetriableError",
":",
"res",
".",
"IsRetriableError",
",",
"isExternalError",
":",
"res",
".",
"IsExternalError",
",",
"}",
"\n",
"default",
":",
"return",
"nil",
",",
"resourceStatusError",
"{",
"err",
":",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"res",
".",
"StatusType",
"(",
")",
")",
",",
"}",
"\n",
"}",
"\n\n",
"// Make sure plugin is returning us something that obeys the PluginSpec.",
"object",
",",
"err",
":=",
"util",
".",
"RuntimeToUnstructured",
"(",
"pluginObj",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"resourceStatusError",
"{",
"err",
":",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
",",
"}",
"\n",
"}",
"\n",
"expectedGVK",
":=",
"pluginContainer",
".",
"Plugin",
".",
"Describe",
"(",
")",
".",
"GVK",
"\n",
"if",
"object",
".",
"GroupVersionKind",
"(",
")",
"!=",
"expectedGVK",
"{",
"return",
"nil",
",",
"resourceStatusError",
"{",
"err",
":",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"expectedGVK",
",",
"object",
".",
"GroupVersionKind",
"(",
")",
")",
",",
"}",
"\n",
"}",
"\n",
"// We are in charge of naming.",
"object",
".",
"SetName",
"(",
"res",
".",
"Spec",
".",
"Plugin",
".",
"ObjectName",
")",
"\n\n",
"return",
"object",
",",
"nil",
"\n",
"}"
] |
// evalPluginSpec evaluates the plugin resource specification and returns the result.
|
[
"evalPluginSpec",
"evaluates",
"the",
"plugin",
"resource",
"specification",
"and",
"returns",
"the",
"result",
"."
] |
e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438
|
https://github.com/atlassian/smith/blob/e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438/pkg/controller/bundlec/resource_sync_task.go#L652-L719
|
18,271 |
atlassian/smith
|
pkg/controller/bundlec/resource_sync_task.go
|
createOrUpdate
|
func (st *resourceSyncTask) createOrUpdate(spec *unstructured.Unstructured, actual runtime.Object) (actualRet *unstructured.Unstructured, retriableRet bool, e error) {
// Prepare client
gvk := spec.GroupVersionKind()
resClient, err := st.smartClient.ForGVK(gvk, st.bundle.Namespace)
if err != nil {
return nil, false, errors.Wrapf(err, "failed to get the client for %s", gvk)
}
switch actual {
case nil:
return st.createResource(resClient, spec)
default:
return st.updateResource(resClient, spec, actual)
}
}
|
go
|
func (st *resourceSyncTask) createOrUpdate(spec *unstructured.Unstructured, actual runtime.Object) (actualRet *unstructured.Unstructured, retriableRet bool, e error) {
// Prepare client
gvk := spec.GroupVersionKind()
resClient, err := st.smartClient.ForGVK(gvk, st.bundle.Namespace)
if err != nil {
return nil, false, errors.Wrapf(err, "failed to get the client for %s", gvk)
}
switch actual {
case nil:
return st.createResource(resClient, spec)
default:
return st.updateResource(resClient, spec, actual)
}
}
|
[
"func",
"(",
"st",
"*",
"resourceSyncTask",
")",
"createOrUpdate",
"(",
"spec",
"*",
"unstructured",
".",
"Unstructured",
",",
"actual",
"runtime",
".",
"Object",
")",
"(",
"actualRet",
"*",
"unstructured",
".",
"Unstructured",
",",
"retriableRet",
"bool",
",",
"e",
"error",
")",
"{",
"// Prepare client",
"gvk",
":=",
"spec",
".",
"GroupVersionKind",
"(",
")",
"\n",
"resClient",
",",
"err",
":=",
"st",
".",
"smartClient",
".",
"ForGVK",
"(",
"gvk",
",",
"st",
".",
"bundle",
".",
"Namespace",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"false",
",",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
",",
"gvk",
")",
"\n",
"}",
"\n",
"switch",
"actual",
"{",
"case",
"nil",
":",
"return",
"st",
".",
"createResource",
"(",
"resClient",
",",
"spec",
")",
"\n",
"default",
":",
"return",
"st",
".",
"updateResource",
"(",
"resClient",
",",
"spec",
",",
"actual",
")",
"\n",
"}",
"\n",
"}"
] |
// createOrUpdate creates or updates a resources.
|
[
"createOrUpdate",
"creates",
"or",
"updates",
"a",
"resources",
"."
] |
e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438
|
https://github.com/atlassian/smith/blob/e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438/pkg/controller/bundlec/resource_sync_task.go#L778-L791
|
18,272 |
atlassian/smith
|
pkg/controller/bundlec/resource_sync_task.go
|
updateResource
|
func (st *resourceSyncTask) updateResource(resClient dynamic.ResourceInterface, spec *unstructured.Unstructured, actual runtime.Object) (actualRet *unstructured.Unstructured, retriableError bool, e error) {
st.logger.Debug("Object found, checking spec", ctrlLogz.ObjectGk(spec.GroupVersionKind().GroupKind()), ctrlLogz.Object(spec))
// Compare spec and existing resource
updated, match, difference, err := st.specChecker.CompareActualVsSpec(st.logger, spec, actual)
if err != nil {
return nil, false, errors.Wrap(err, "specification check failed")
}
// Delete the DeletionTimestamp annotation if it is present
annotations := updated.GetAnnotations()
if _, ok := annotations[smith.DeletionTimestampAnnotation]; ok {
delete(annotations, smith.DeletionTimestampAnnotation)
updated.SetAnnotations(annotations)
match = false
}
if match {
st.logger.Debug("Object has correct spec", ctrlLogz.Object(spec))
return updated, false, nil
}
st.logger.Sugar().Infof("Objects are different (`a` is specification and `b` is the actual object): %s", difference)
// Update if different
updated, err = resClient.Update(updated, meta_v1.UpdateOptions{})
if err != nil {
if api_errors.IsConflict(err) {
// We let the next processKey() iteration, triggered by someone else updating the resource, finish the work.
return nil, false, errors.Wrap(err, "object update resulted in conflict (will re-process)")
}
// Unexpected error, will retry
apiStatusErr, ok := err.(api_errors.APIStatus)
if ok {
apiStatus := apiStatusErr.Status()
return nil, true, errors.Wrapf(err, "unexpected APIStatus (code %v, reason %q) while creating resource", apiStatus.Code, apiStatus.Reason)
}
return nil, true, errors.WithStack(err)
}
st.logger.Info("Object updated", ctrlLogz.Object(spec))
return updated, false, nil
}
|
go
|
func (st *resourceSyncTask) updateResource(resClient dynamic.ResourceInterface, spec *unstructured.Unstructured, actual runtime.Object) (actualRet *unstructured.Unstructured, retriableError bool, e error) {
st.logger.Debug("Object found, checking spec", ctrlLogz.ObjectGk(spec.GroupVersionKind().GroupKind()), ctrlLogz.Object(spec))
// Compare spec and existing resource
updated, match, difference, err := st.specChecker.CompareActualVsSpec(st.logger, spec, actual)
if err != nil {
return nil, false, errors.Wrap(err, "specification check failed")
}
// Delete the DeletionTimestamp annotation if it is present
annotations := updated.GetAnnotations()
if _, ok := annotations[smith.DeletionTimestampAnnotation]; ok {
delete(annotations, smith.DeletionTimestampAnnotation)
updated.SetAnnotations(annotations)
match = false
}
if match {
st.logger.Debug("Object has correct spec", ctrlLogz.Object(spec))
return updated, false, nil
}
st.logger.Sugar().Infof("Objects are different (`a` is specification and `b` is the actual object): %s", difference)
// Update if different
updated, err = resClient.Update(updated, meta_v1.UpdateOptions{})
if err != nil {
if api_errors.IsConflict(err) {
// We let the next processKey() iteration, triggered by someone else updating the resource, finish the work.
return nil, false, errors.Wrap(err, "object update resulted in conflict (will re-process)")
}
// Unexpected error, will retry
apiStatusErr, ok := err.(api_errors.APIStatus)
if ok {
apiStatus := apiStatusErr.Status()
return nil, true, errors.Wrapf(err, "unexpected APIStatus (code %v, reason %q) while creating resource", apiStatus.Code, apiStatus.Reason)
}
return nil, true, errors.WithStack(err)
}
st.logger.Info("Object updated", ctrlLogz.Object(spec))
return updated, false, nil
}
|
[
"func",
"(",
"st",
"*",
"resourceSyncTask",
")",
"updateResource",
"(",
"resClient",
"dynamic",
".",
"ResourceInterface",
",",
"spec",
"*",
"unstructured",
".",
"Unstructured",
",",
"actual",
"runtime",
".",
"Object",
")",
"(",
"actualRet",
"*",
"unstructured",
".",
"Unstructured",
",",
"retriableError",
"bool",
",",
"e",
"error",
")",
"{",
"st",
".",
"logger",
".",
"Debug",
"(",
"\"",
"\"",
",",
"ctrlLogz",
".",
"ObjectGk",
"(",
"spec",
".",
"GroupVersionKind",
"(",
")",
".",
"GroupKind",
"(",
")",
")",
",",
"ctrlLogz",
".",
"Object",
"(",
"spec",
")",
")",
"\n",
"// Compare spec and existing resource",
"updated",
",",
"match",
",",
"difference",
",",
"err",
":=",
"st",
".",
"specChecker",
".",
"CompareActualVsSpec",
"(",
"st",
".",
"logger",
",",
"spec",
",",
"actual",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"false",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Delete the DeletionTimestamp annotation if it is present",
"annotations",
":=",
"updated",
".",
"GetAnnotations",
"(",
")",
"\n",
"if",
"_",
",",
"ok",
":=",
"annotations",
"[",
"smith",
".",
"DeletionTimestampAnnotation",
"]",
";",
"ok",
"{",
"delete",
"(",
"annotations",
",",
"smith",
".",
"DeletionTimestampAnnotation",
")",
"\n",
"updated",
".",
"SetAnnotations",
"(",
"annotations",
")",
"\n",
"match",
"=",
"false",
"\n",
"}",
"\n\n",
"if",
"match",
"{",
"st",
".",
"logger",
".",
"Debug",
"(",
"\"",
"\"",
",",
"ctrlLogz",
".",
"Object",
"(",
"spec",
")",
")",
"\n",
"return",
"updated",
",",
"false",
",",
"nil",
"\n",
"}",
"\n",
"st",
".",
"logger",
".",
"Sugar",
"(",
")",
".",
"Infof",
"(",
"\"",
"\"",
",",
"difference",
")",
"\n\n",
"// Update if different",
"updated",
",",
"err",
"=",
"resClient",
".",
"Update",
"(",
"updated",
",",
"meta_v1",
".",
"UpdateOptions",
"{",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"api_errors",
".",
"IsConflict",
"(",
"err",
")",
"{",
"// We let the next processKey() iteration, triggered by someone else updating the resource, finish the work.",
"return",
"nil",
",",
"false",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"// Unexpected error, will retry",
"apiStatusErr",
",",
"ok",
":=",
"err",
".",
"(",
"api_errors",
".",
"APIStatus",
")",
"\n",
"if",
"ok",
"{",
"apiStatus",
":=",
"apiStatusErr",
".",
"Status",
"(",
")",
"\n",
"return",
"nil",
",",
"true",
",",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
",",
"apiStatus",
".",
"Code",
",",
"apiStatus",
".",
"Reason",
")",
"\n",
"}",
"\n",
"return",
"nil",
",",
"true",
",",
"errors",
".",
"WithStack",
"(",
"err",
")",
"\n",
"}",
"\n",
"st",
".",
"logger",
".",
"Info",
"(",
"\"",
"\"",
",",
"ctrlLogz",
".",
"Object",
"(",
"spec",
")",
")",
"\n",
"return",
"updated",
",",
"false",
",",
"nil",
"\n",
"}"
] |
// Mutates spec and actual.
|
[
"Mutates",
"spec",
"and",
"actual",
"."
] |
e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438
|
https://github.com/atlassian/smith/blob/e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438/pkg/controller/bundlec/resource_sync_task.go#L820-L859
|
18,273 |
atlassian/smith
|
pkg/resources/objects.go
|
GetJSONPathString
|
func GetJSONPathString(obj interface{}, path string) (string, error) {
j := jsonpath.New("GetJSONPathString")
// If the key is missing, return an empty string without errors
j.AllowMissingKeys(true)
err := j.Parse(path)
if err != nil {
return "", errors.Wrapf(err, "JsonPath parse %s error", path)
}
var buf bytes.Buffer
err = j.Execute(&buf, obj)
if err != nil {
return "", errors.Wrap(err, "JsonPath execute error")
}
return buf.String(), nil
}
|
go
|
func GetJSONPathString(obj interface{}, path string) (string, error) {
j := jsonpath.New("GetJSONPathString")
// If the key is missing, return an empty string without errors
j.AllowMissingKeys(true)
err := j.Parse(path)
if err != nil {
return "", errors.Wrapf(err, "JsonPath parse %s error", path)
}
var buf bytes.Buffer
err = j.Execute(&buf, obj)
if err != nil {
return "", errors.Wrap(err, "JsonPath execute error")
}
return buf.String(), nil
}
|
[
"func",
"GetJSONPathString",
"(",
"obj",
"interface",
"{",
"}",
",",
"path",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"j",
":=",
"jsonpath",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"// If the key is missing, return an empty string without errors",
"j",
".",
"AllowMissingKeys",
"(",
"true",
")",
"\n",
"err",
":=",
"j",
".",
"Parse",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
",",
"path",
")",
"\n",
"}",
"\n",
"var",
"buf",
"bytes",
".",
"Buffer",
"\n",
"err",
"=",
"j",
".",
"Execute",
"(",
"&",
"buf",
",",
"obj",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"buf",
".",
"String",
"(",
")",
",",
"nil",
"\n",
"}"
] |
// GetJSONPathString extracts the value from the object using given JsonPath template, in a string format
|
[
"GetJSONPathString",
"extracts",
"the",
"value",
"from",
"the",
"object",
"using",
"given",
"JsonPath",
"template",
"in",
"a",
"string",
"format"
] |
e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438
|
https://github.com/atlassian/smith/blob/e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438/pkg/resources/objects.go#L12-L26
|
18,274 |
atlassian/smith
|
pkg/resources/objects.go
|
GetJSONPathValue
|
func GetJSONPathValue(obj interface{}, path string, allowMissingKeys bool) (interface{}, error) {
j := jsonpath.New("GetJSONPathValue")
// If the key is missing, return an empty string without errors
j.AllowMissingKeys(allowMissingKeys)
err := j.Parse(path)
if err != nil {
return "", errors.Wrapf(err, "JsonPath parse %s error", path)
}
values, err := j.FindResults(obj)
if err != nil {
return "", errors.Wrap(err, "JsonPath execute error")
}
if len(values) == 0 {
return nil, nil
}
if len(values) > 1 {
return nil, errors.Errorf("single result expected, got %d", len(values))
}
if values[0] == nil || len(values[0]) == 0 || values[0][0].IsNil() {
return nil, nil
}
return values[0][0].Interface(), nil
}
|
go
|
func GetJSONPathValue(obj interface{}, path string, allowMissingKeys bool) (interface{}, error) {
j := jsonpath.New("GetJSONPathValue")
// If the key is missing, return an empty string without errors
j.AllowMissingKeys(allowMissingKeys)
err := j.Parse(path)
if err != nil {
return "", errors.Wrapf(err, "JsonPath parse %s error", path)
}
values, err := j.FindResults(obj)
if err != nil {
return "", errors.Wrap(err, "JsonPath execute error")
}
if len(values) == 0 {
return nil, nil
}
if len(values) > 1 {
return nil, errors.Errorf("single result expected, got %d", len(values))
}
if values[0] == nil || len(values[0]) == 0 || values[0][0].IsNil() {
return nil, nil
}
return values[0][0].Interface(), nil
}
|
[
"func",
"GetJSONPathValue",
"(",
"obj",
"interface",
"{",
"}",
",",
"path",
"string",
",",
"allowMissingKeys",
"bool",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"j",
":=",
"jsonpath",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"// If the key is missing, return an empty string without errors",
"j",
".",
"AllowMissingKeys",
"(",
"allowMissingKeys",
")",
"\n",
"err",
":=",
"j",
".",
"Parse",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
",",
"path",
")",
"\n",
"}",
"\n",
"values",
",",
"err",
":=",
"j",
".",
"FindResults",
"(",
"obj",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"values",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"if",
"len",
"(",
"values",
")",
">",
"1",
"{",
"return",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"len",
"(",
"values",
")",
")",
"\n",
"}",
"\n",
"if",
"values",
"[",
"0",
"]",
"==",
"nil",
"||",
"len",
"(",
"values",
"[",
"0",
"]",
")",
"==",
"0",
"||",
"values",
"[",
"0",
"]",
"[",
"0",
"]",
".",
"IsNil",
"(",
")",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"return",
"values",
"[",
"0",
"]",
"[",
"0",
"]",
".",
"Interface",
"(",
")",
",",
"nil",
"\n",
"}"
] |
// GetJSONPathValue extracts the value from the object using given JsonPath template
|
[
"GetJSONPathValue",
"extracts",
"the",
"value",
"from",
"the",
"object",
"using",
"given",
"JsonPath",
"template"
] |
e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438
|
https://github.com/atlassian/smith/blob/e4fa63e5dcb5b4dc532a3dcb7b93ca4a5ad19438/pkg/resources/objects.go#L29-L51
|
18,275 |
smallnest/goreq
|
goreq.go
|
New
|
func New() *GoReq {
gr := &GoReq{
Data: make(map[string]interface{}),
Header: make(map[string]string),
FormData: url.Values{},
QueryData: url.Values{},
Client: nil,
Transport: &http.Transport{},
Cookies: make([]*http.Cookie, 0),
Errors: nil,
BasicAuth: struct{ Username, Password string }{},
Debug: false,
CurlCommand: false,
logger: log.New(os.Stderr, "[goreq]", log.LstdFlags),
retry: &RetryConfig{RetryCount: 0, RetryTimeout: 0, RetryOnHTTPStatus: nil},
bindResponseBody: nil,
}
return gr
}
|
go
|
func New() *GoReq {
gr := &GoReq{
Data: make(map[string]interface{}),
Header: make(map[string]string),
FormData: url.Values{},
QueryData: url.Values{},
Client: nil,
Transport: &http.Transport{},
Cookies: make([]*http.Cookie, 0),
Errors: nil,
BasicAuth: struct{ Username, Password string }{},
Debug: false,
CurlCommand: false,
logger: log.New(os.Stderr, "[goreq]", log.LstdFlags),
retry: &RetryConfig{RetryCount: 0, RetryTimeout: 0, RetryOnHTTPStatus: nil},
bindResponseBody: nil,
}
return gr
}
|
[
"func",
"New",
"(",
")",
"*",
"GoReq",
"{",
"gr",
":=",
"&",
"GoReq",
"{",
"Data",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
",",
"Header",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
",",
"FormData",
":",
"url",
".",
"Values",
"{",
"}",
",",
"QueryData",
":",
"url",
".",
"Values",
"{",
"}",
",",
"Client",
":",
"nil",
",",
"Transport",
":",
"&",
"http",
".",
"Transport",
"{",
"}",
",",
"Cookies",
":",
"make",
"(",
"[",
"]",
"*",
"http",
".",
"Cookie",
",",
"0",
")",
",",
"Errors",
":",
"nil",
",",
"BasicAuth",
":",
"struct",
"{",
"Username",
",",
"Password",
"string",
"}",
"{",
"}",
",",
"Debug",
":",
"false",
",",
"CurlCommand",
":",
"false",
",",
"logger",
":",
"log",
".",
"New",
"(",
"os",
".",
"Stderr",
",",
"\"",
"\"",
",",
"log",
".",
"LstdFlags",
")",
",",
"retry",
":",
"&",
"RetryConfig",
"{",
"RetryCount",
":",
"0",
",",
"RetryTimeout",
":",
"0",
",",
"RetryOnHTTPStatus",
":",
"nil",
"}",
",",
"bindResponseBody",
":",
"nil",
",",
"}",
"\n",
"return",
"gr",
"\n",
"}"
] |
// New returns a new GoReq object.
|
[
"New",
"returns",
"a",
"new",
"GoReq",
"object",
"."
] |
2e3372c80388e4b95c699c950eb2c9faba6c32e0
|
https://github.com/smallnest/goreq/blob/2e3372c80388e4b95c699c950eb2c9faba6c32e0/goreq.go#L100-L118
|
18,276 |
smallnest/goreq
|
goreq.go
|
SetCurlCommand
|
func (gr *GoReq) SetCurlCommand(enable bool) *GoReq {
gr.CurlCommand = enable
return gr
}
|
go
|
func (gr *GoReq) SetCurlCommand(enable bool) *GoReq {
gr.CurlCommand = enable
return gr
}
|
[
"func",
"(",
"gr",
"*",
"GoReq",
")",
"SetCurlCommand",
"(",
"enable",
"bool",
")",
"*",
"GoReq",
"{",
"gr",
".",
"CurlCommand",
"=",
"enable",
"\n",
"return",
"gr",
"\n",
"}"
] |
// SetCurlCommand enables the curlcommand mode which display a CURL command line
|
[
"SetCurlCommand",
"enables",
"the",
"curlcommand",
"mode",
"which",
"display",
"a",
"CURL",
"command",
"line"
] |
2e3372c80388e4b95c699c950eb2c9faba6c32e0
|
https://github.com/smallnest/goreq/blob/2e3372c80388e4b95c699c950eb2c9faba6c32e0/goreq.go#L127-L130
|
18,277 |
smallnest/goreq
|
goreq.go
|
SetLogger
|
func (gr *GoReq) SetLogger(logger *log.Logger) *GoReq {
gr.logger = logger
return gr
}
|
go
|
func (gr *GoReq) SetLogger(logger *log.Logger) *GoReq {
gr.logger = logger
return gr
}
|
[
"func",
"(",
"gr",
"*",
"GoReq",
")",
"SetLogger",
"(",
"logger",
"*",
"log",
".",
"Logger",
")",
"*",
"GoReq",
"{",
"gr",
".",
"logger",
"=",
"logger",
"\n",
"return",
"gr",
"\n",
"}"
] |
// SetLogger is used to set a Logger
|
[
"SetLogger",
"is",
"used",
"to",
"set",
"a",
"Logger"
] |
2e3372c80388e4b95c699c950eb2c9faba6c32e0
|
https://github.com/smallnest/goreq/blob/2e3372c80388e4b95c699c950eb2c9faba6c32e0/goreq.go#L133-L136
|
18,278 |
smallnest/goreq
|
goreq.go
|
SetClient
|
func (gr *GoReq) SetClient(client *http.Client) *GoReq {
gr.Client = client
return gr
}
|
go
|
func (gr *GoReq) SetClient(client *http.Client) *GoReq {
gr.Client = client
return gr
}
|
[
"func",
"(",
"gr",
"*",
"GoReq",
")",
"SetClient",
"(",
"client",
"*",
"http",
".",
"Client",
")",
"*",
"GoReq",
"{",
"gr",
".",
"Client",
"=",
"client",
"\n",
"return",
"gr",
"\n",
"}"
] |
// SetClient ise used to set a shared http.Client
|
[
"SetClient",
"ise",
"used",
"to",
"set",
"a",
"shared",
"http",
".",
"Client"
] |
2e3372c80388e4b95c699c950eb2c9faba6c32e0
|
https://github.com/smallnest/goreq/blob/2e3372c80388e4b95c699c950eb2c9faba6c32e0/goreq.go#L139-L142
|
18,279 |
smallnest/goreq
|
goreq.go
|
Reset
|
func (gr *GoReq) Reset() *GoReq {
gr.URL = ""
gr.Method = ""
gr.Header = make(map[string]string)
gr.Data = make(map[string]interface{})
gr.FormData = url.Values{}
gr.QueryData = url.Values{}
gr.RawStringData = ""
gr.RawBytesData = make([]byte, 0)
gr.FilePath = ""
gr.FileParam = ""
gr.Cookies = make([]*http.Cookie, 0)
gr.Errors = nil
gr.retry = &RetryConfig{RetryCount: 0, RetryTimeout: 0, RetryOnHTTPStatus: nil}
gr.bindResponseBody = nil
return gr
}
|
go
|
func (gr *GoReq) Reset() *GoReq {
gr.URL = ""
gr.Method = ""
gr.Header = make(map[string]string)
gr.Data = make(map[string]interface{})
gr.FormData = url.Values{}
gr.QueryData = url.Values{}
gr.RawStringData = ""
gr.RawBytesData = make([]byte, 0)
gr.FilePath = ""
gr.FileParam = ""
gr.Cookies = make([]*http.Cookie, 0)
gr.Errors = nil
gr.retry = &RetryConfig{RetryCount: 0, RetryTimeout: 0, RetryOnHTTPStatus: nil}
gr.bindResponseBody = nil
return gr
}
|
[
"func",
"(",
"gr",
"*",
"GoReq",
")",
"Reset",
"(",
")",
"*",
"GoReq",
"{",
"gr",
".",
"URL",
"=",
"\"",
"\"",
"\n",
"gr",
".",
"Method",
"=",
"\"",
"\"",
"\n",
"gr",
".",
"Header",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"\n",
"gr",
".",
"Data",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n",
"gr",
".",
"FormData",
"=",
"url",
".",
"Values",
"{",
"}",
"\n",
"gr",
".",
"QueryData",
"=",
"url",
".",
"Values",
"{",
"}",
"\n",
"gr",
".",
"RawStringData",
"=",
"\"",
"\"",
"\n",
"gr",
".",
"RawBytesData",
"=",
"make",
"(",
"[",
"]",
"byte",
",",
"0",
")",
"\n",
"gr",
".",
"FilePath",
"=",
"\"",
"\"",
"\n",
"gr",
".",
"FileParam",
"=",
"\"",
"\"",
"\n",
"gr",
".",
"Cookies",
"=",
"make",
"(",
"[",
"]",
"*",
"http",
".",
"Cookie",
",",
"0",
")",
"\n",
"gr",
".",
"Errors",
"=",
"nil",
"\n",
"gr",
".",
"retry",
"=",
"&",
"RetryConfig",
"{",
"RetryCount",
":",
"0",
",",
"RetryTimeout",
":",
"0",
",",
"RetryOnHTTPStatus",
":",
"nil",
"}",
"\n",
"gr",
".",
"bindResponseBody",
"=",
"nil",
"\n",
"return",
"gr",
"\n",
"}"
] |
// Reset is used to clear GoReq data for another new request only keep client and logger.
|
[
"Reset",
"is",
"used",
"to",
"clear",
"GoReq",
"data",
"for",
"another",
"new",
"request",
"only",
"keep",
"client",
"and",
"logger",
"."
] |
2e3372c80388e4b95c699c950eb2c9faba6c32e0
|
https://github.com/smallnest/goreq/blob/2e3372c80388e4b95c699c950eb2c9faba6c32e0/goreq.go#L155-L171
|
18,280 |
smallnest/goreq
|
goreq.go
|
Get
|
func (gr *GoReq) Get(targetURL string) *GoReq {
//gr.Reset()
gr.Method = GET
gr.URL = targetURL
gr.Errors = nil
return gr
}
|
go
|
func (gr *GoReq) Get(targetURL string) *GoReq {
//gr.Reset()
gr.Method = GET
gr.URL = targetURL
gr.Errors = nil
return gr
}
|
[
"func",
"(",
"gr",
"*",
"GoReq",
")",
"Get",
"(",
"targetURL",
"string",
")",
"*",
"GoReq",
"{",
"//gr.Reset()",
"gr",
".",
"Method",
"=",
"GET",
"\n",
"gr",
".",
"URL",
"=",
"targetURL",
"\n",
"gr",
".",
"Errors",
"=",
"nil",
"\n",
"return",
"gr",
"\n",
"}"
] |
// Get is used to set GET HttpMethod with a url.
|
[
"Get",
"is",
"used",
"to",
"set",
"GET",
"HttpMethod",
"with",
"a",
"url",
"."
] |
2e3372c80388e4b95c699c950eb2c9faba6c32e0
|
https://github.com/smallnest/goreq/blob/2e3372c80388e4b95c699c950eb2c9faba6c32e0/goreq.go#L174-L180
|
18,281 |
smallnest/goreq
|
goreq.go
|
Post
|
func (gr *GoReq) Post(targetURL string) *GoReq {
//gr.Reset()
gr.Method = POST
gr.URL = targetURL
gr.Errors = nil
return gr
}
|
go
|
func (gr *GoReq) Post(targetURL string) *GoReq {
//gr.Reset()
gr.Method = POST
gr.URL = targetURL
gr.Errors = nil
return gr
}
|
[
"func",
"(",
"gr",
"*",
"GoReq",
")",
"Post",
"(",
"targetURL",
"string",
")",
"*",
"GoReq",
"{",
"//gr.Reset()",
"gr",
".",
"Method",
"=",
"POST",
"\n",
"gr",
".",
"URL",
"=",
"targetURL",
"\n",
"gr",
".",
"Errors",
"=",
"nil",
"\n",
"return",
"gr",
"\n",
"}"
] |
// Post is used to set POST HttpMethod with a url.
|
[
"Post",
"is",
"used",
"to",
"set",
"POST",
"HttpMethod",
"with",
"a",
"url",
"."
] |
2e3372c80388e4b95c699c950eb2c9faba6c32e0
|
https://github.com/smallnest/goreq/blob/2e3372c80388e4b95c699c950eb2c9faba6c32e0/goreq.go#L183-L189
|
18,282 |
smallnest/goreq
|
goreq.go
|
Head
|
func (gr *GoReq) Head(targetURL string) *GoReq {
//gr.Reset()
gr.Method = HEAD
gr.URL = targetURL
gr.Errors = nil
return gr
}
|
go
|
func (gr *GoReq) Head(targetURL string) *GoReq {
//gr.Reset()
gr.Method = HEAD
gr.URL = targetURL
gr.Errors = nil
return gr
}
|
[
"func",
"(",
"gr",
"*",
"GoReq",
")",
"Head",
"(",
"targetURL",
"string",
")",
"*",
"GoReq",
"{",
"//gr.Reset()",
"gr",
".",
"Method",
"=",
"HEAD",
"\n",
"gr",
".",
"URL",
"=",
"targetURL",
"\n",
"gr",
".",
"Errors",
"=",
"nil",
"\n",
"return",
"gr",
"\n",
"}"
] |
// Head is used to set HEAD HttpMethod with a url.
|
[
"Head",
"is",
"used",
"to",
"set",
"HEAD",
"HttpMethod",
"with",
"a",
"url",
"."
] |
2e3372c80388e4b95c699c950eb2c9faba6c32e0
|
https://github.com/smallnest/goreq/blob/2e3372c80388e4b95c699c950eb2c9faba6c32e0/goreq.go#L192-L198
|
18,283 |
smallnest/goreq
|
goreq.go
|
Put
|
func (gr *GoReq) Put(targetURL string) *GoReq {
//gr.Reset()
gr.Method = PUT
gr.URL = targetURL
gr.Errors = nil
return gr
}
|
go
|
func (gr *GoReq) Put(targetURL string) *GoReq {
//gr.Reset()
gr.Method = PUT
gr.URL = targetURL
gr.Errors = nil
return gr
}
|
[
"func",
"(",
"gr",
"*",
"GoReq",
")",
"Put",
"(",
"targetURL",
"string",
")",
"*",
"GoReq",
"{",
"//gr.Reset()",
"gr",
".",
"Method",
"=",
"PUT",
"\n",
"gr",
".",
"URL",
"=",
"targetURL",
"\n",
"gr",
".",
"Errors",
"=",
"nil",
"\n",
"return",
"gr",
"\n",
"}"
] |
// Put is used to set PUT HttpMethod with a url.
|
[
"Put",
"is",
"used",
"to",
"set",
"PUT",
"HttpMethod",
"with",
"a",
"url",
"."
] |
2e3372c80388e4b95c699c950eb2c9faba6c32e0
|
https://github.com/smallnest/goreq/blob/2e3372c80388e4b95c699c950eb2c9faba6c32e0/goreq.go#L201-L207
|
18,284 |
smallnest/goreq
|
goreq.go
|
Delete
|
func (gr *GoReq) Delete(targetURL string) *GoReq {
//gr.Reset()
gr.Method = DELETE
gr.URL = targetURL
gr.Errors = nil
return gr
}
|
go
|
func (gr *GoReq) Delete(targetURL string) *GoReq {
//gr.Reset()
gr.Method = DELETE
gr.URL = targetURL
gr.Errors = nil
return gr
}
|
[
"func",
"(",
"gr",
"*",
"GoReq",
")",
"Delete",
"(",
"targetURL",
"string",
")",
"*",
"GoReq",
"{",
"//gr.Reset()",
"gr",
".",
"Method",
"=",
"DELETE",
"\n",
"gr",
".",
"URL",
"=",
"targetURL",
"\n",
"gr",
".",
"Errors",
"=",
"nil",
"\n",
"return",
"gr",
"\n",
"}"
] |
// Delete is used to set DELETE HttpMethod with a url.
|
[
"Delete",
"is",
"used",
"to",
"set",
"DELETE",
"HttpMethod",
"with",
"a",
"url",
"."
] |
2e3372c80388e4b95c699c950eb2c9faba6c32e0
|
https://github.com/smallnest/goreq/blob/2e3372c80388e4b95c699c950eb2c9faba6c32e0/goreq.go#L210-L216
|
18,285 |
smallnest/goreq
|
goreq.go
|
Patch
|
func (gr *GoReq) Patch(targetURL string) *GoReq {
//gr.Reset()
gr.Method = PATCH
gr.URL = targetURL
gr.Errors = nil
return gr
}
|
go
|
func (gr *GoReq) Patch(targetURL string) *GoReq {
//gr.Reset()
gr.Method = PATCH
gr.URL = targetURL
gr.Errors = nil
return gr
}
|
[
"func",
"(",
"gr",
"*",
"GoReq",
")",
"Patch",
"(",
"targetURL",
"string",
")",
"*",
"GoReq",
"{",
"//gr.Reset()",
"gr",
".",
"Method",
"=",
"PATCH",
"\n",
"gr",
".",
"URL",
"=",
"targetURL",
"\n",
"gr",
".",
"Errors",
"=",
"nil",
"\n",
"return",
"gr",
"\n",
"}"
] |
// Patch is used to set PATCH HttpMethod with a url.
|
[
"Patch",
"is",
"used",
"to",
"set",
"PATCH",
"HttpMethod",
"with",
"a",
"url",
"."
] |
2e3372c80388e4b95c699c950eb2c9faba6c32e0
|
https://github.com/smallnest/goreq/blob/2e3372c80388e4b95c699c950eb2c9faba6c32e0/goreq.go#L219-L225
|
18,286 |
smallnest/goreq
|
goreq.go
|
Options
|
func (gr *GoReq) Options(targetURL string) *GoReq {
//gr.Reset()
gr.Method = OPTIONS
gr.URL = targetURL
gr.Errors = nil
return gr
}
|
go
|
func (gr *GoReq) Options(targetURL string) *GoReq {
//gr.Reset()
gr.Method = OPTIONS
gr.URL = targetURL
gr.Errors = nil
return gr
}
|
[
"func",
"(",
"gr",
"*",
"GoReq",
")",
"Options",
"(",
"targetURL",
"string",
")",
"*",
"GoReq",
"{",
"//gr.Reset()",
"gr",
".",
"Method",
"=",
"OPTIONS",
"\n",
"gr",
".",
"URL",
"=",
"targetURL",
"\n",
"gr",
".",
"Errors",
"=",
"nil",
"\n",
"return",
"gr",
"\n",
"}"
] |
// Options is used to set OPTIONS HttpMethod with a url.
|
[
"Options",
"is",
"used",
"to",
"set",
"OPTIONS",
"HttpMethod",
"with",
"a",
"url",
"."
] |
2e3372c80388e4b95c699c950eb2c9faba6c32e0
|
https://github.com/smallnest/goreq/blob/2e3372c80388e4b95c699c950eb2c9faba6c32e0/goreq.go#L228-L234
|
18,287 |
smallnest/goreq
|
goreq.go
|
queryStruct
|
func (gr *GoReq) queryStruct(content interface{}) *GoReq {
if marshalContent, err := json.Marshal(content); err != nil {
gr.Errors = append(gr.Errors, err)
} else {
var val map[string]interface{}
if err := json.Unmarshal(marshalContent, &val); err != nil {
gr.Errors = append(gr.Errors, err)
} else {
for k, v := range val {
gr.QueryData.Add(k, v.(string))
}
}
}
return gr
}
|
go
|
func (gr *GoReq) queryStruct(content interface{}) *GoReq {
if marshalContent, err := json.Marshal(content); err != nil {
gr.Errors = append(gr.Errors, err)
} else {
var val map[string]interface{}
if err := json.Unmarshal(marshalContent, &val); err != nil {
gr.Errors = append(gr.Errors, err)
} else {
for k, v := range val {
gr.QueryData.Add(k, v.(string))
}
}
}
return gr
}
|
[
"func",
"(",
"gr",
"*",
"GoReq",
")",
"queryStruct",
"(",
"content",
"interface",
"{",
"}",
")",
"*",
"GoReq",
"{",
"if",
"marshalContent",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"content",
")",
";",
"err",
"!=",
"nil",
"{",
"gr",
".",
"Errors",
"=",
"append",
"(",
"gr",
".",
"Errors",
",",
"err",
")",
"\n",
"}",
"else",
"{",
"var",
"val",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"marshalContent",
",",
"&",
"val",
")",
";",
"err",
"!=",
"nil",
"{",
"gr",
".",
"Errors",
"=",
"append",
"(",
"gr",
".",
"Errors",
",",
"err",
")",
"\n",
"}",
"else",
"{",
"for",
"k",
",",
"v",
":=",
"range",
"val",
"{",
"gr",
".",
"QueryData",
".",
"Add",
"(",
"k",
",",
"v",
".",
"(",
"string",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"gr",
"\n",
"}"
] |
//create queryData by parsing structs.
|
[
"create",
"queryData",
"by",
"parsing",
"structs",
"."
] |
2e3372c80388e4b95c699c950eb2c9faba6c32e0
|
https://github.com/smallnest/goreq/blob/2e3372c80388e4b95c699c950eb2c9faba6c32e0/goreq.go#L416-L430
|
18,288 |
smallnest/goreq
|
goreq.go
|
Timeout
|
func (gr *GoReq) Timeout(timeout time.Duration) *GoReq {
gr.Transport.Dial = func(network, addr string) (net.Conn, error) {
conn, err := net.DialTimeout(network, addr, timeout)
if err != nil {
gr.Errors = append(gr.Errors, err)
return nil, err
}
conn.SetDeadline(time.Now().Add(timeout))
return conn, nil
}
return gr
}
|
go
|
func (gr *GoReq) Timeout(timeout time.Duration) *GoReq {
gr.Transport.Dial = func(network, addr string) (net.Conn, error) {
conn, err := net.DialTimeout(network, addr, timeout)
if err != nil {
gr.Errors = append(gr.Errors, err)
return nil, err
}
conn.SetDeadline(time.Now().Add(timeout))
return conn, nil
}
return gr
}
|
[
"func",
"(",
"gr",
"*",
"GoReq",
")",
"Timeout",
"(",
"timeout",
"time",
".",
"Duration",
")",
"*",
"GoReq",
"{",
"gr",
".",
"Transport",
".",
"Dial",
"=",
"func",
"(",
"network",
",",
"addr",
"string",
")",
"(",
"net",
".",
"Conn",
",",
"error",
")",
"{",
"conn",
",",
"err",
":=",
"net",
".",
"DialTimeout",
"(",
"network",
",",
"addr",
",",
"timeout",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"gr",
".",
"Errors",
"=",
"append",
"(",
"gr",
".",
"Errors",
",",
"err",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"conn",
".",
"SetDeadline",
"(",
"time",
".",
"Now",
"(",
")",
".",
"Add",
"(",
"timeout",
")",
")",
"\n",
"return",
"conn",
",",
"nil",
"\n",
"}",
"\n",
"return",
"gr",
"\n",
"}"
] |
// Timeout is used to set timeout for connections.
|
[
"Timeout",
"is",
"used",
"to",
"set",
"timeout",
"for",
"connections",
"."
] |
2e3372c80388e4b95c699c950eb2c9faba6c32e0
|
https://github.com/smallnest/goreq/blob/2e3372c80388e4b95c699c950eb2c9faba6c32e0/goreq.go#L480-L491
|
18,289 |
smallnest/goreq
|
goreq.go
|
RedirectPolicy
|
func (gr *GoReq) RedirectPolicy(policy func(req Request, via []Request) error) *GoReq {
gr.CheckRedirect = func(r *http.Request, v []*http.Request) error {
vv := make([]Request, len(v))
for i, r := range v {
vv[i] = Request(r)
}
return policy(Request(r), vv)
}
if gr.Client != nil {
gr.Client.CheckRedirect = gr.CheckRedirect
}
return gr
}
|
go
|
func (gr *GoReq) RedirectPolicy(policy func(req Request, via []Request) error) *GoReq {
gr.CheckRedirect = func(r *http.Request, v []*http.Request) error {
vv := make([]Request, len(v))
for i, r := range v {
vv[i] = Request(r)
}
return policy(Request(r), vv)
}
if gr.Client != nil {
gr.Client.CheckRedirect = gr.CheckRedirect
}
return gr
}
|
[
"func",
"(",
"gr",
"*",
"GoReq",
")",
"RedirectPolicy",
"(",
"policy",
"func",
"(",
"req",
"Request",
",",
"via",
"[",
"]",
"Request",
")",
"error",
")",
"*",
"GoReq",
"{",
"gr",
".",
"CheckRedirect",
"=",
"func",
"(",
"r",
"*",
"http",
".",
"Request",
",",
"v",
"[",
"]",
"*",
"http",
".",
"Request",
")",
"error",
"{",
"vv",
":=",
"make",
"(",
"[",
"]",
"Request",
",",
"len",
"(",
"v",
")",
")",
"\n",
"for",
"i",
",",
"r",
":=",
"range",
"v",
"{",
"vv",
"[",
"i",
"]",
"=",
"Request",
"(",
"r",
")",
"\n",
"}",
"\n",
"return",
"policy",
"(",
"Request",
"(",
"r",
")",
",",
"vv",
")",
"\n",
"}",
"\n",
"if",
"gr",
".",
"Client",
"!=",
"nil",
"{",
"gr",
".",
"Client",
".",
"CheckRedirect",
"=",
"gr",
".",
"CheckRedirect",
"\n",
"}",
"\n",
"return",
"gr",
"\n",
"}"
] |
// RedirectPolicy is used to set redirect policy.
|
[
"RedirectPolicy",
"is",
"used",
"to",
"set",
"redirect",
"policy",
"."
] |
2e3372c80388e4b95c699c950eb2c9faba6c32e0
|
https://github.com/smallnest/goreq/blob/2e3372c80388e4b95c699c950eb2c9faba6c32e0/goreq.go#L534-L546
|
18,290 |
smallnest/goreq
|
goreq.go
|
SendFile
|
func (gr *GoReq) SendFile(paramName, filePath string) *GoReq {
gr.FileParam = paramName
gr.FilePath = filePath
return gr
}
|
go
|
func (gr *GoReq) SendFile(paramName, filePath string) *GoReq {
gr.FileParam = paramName
gr.FilePath = filePath
return gr
}
|
[
"func",
"(",
"gr",
"*",
"GoReq",
")",
"SendFile",
"(",
"paramName",
",",
"filePath",
"string",
")",
"*",
"GoReq",
"{",
"gr",
".",
"FileParam",
"=",
"paramName",
"\n",
"gr",
".",
"FilePath",
"=",
"filePath",
"\n",
"return",
"gr",
"\n",
"}"
] |
// SendFile posts a file to server.
|
[
"SendFile",
"posts",
"a",
"file",
"to",
"server",
"."
] |
2e3372c80388e4b95c699c950eb2c9faba6c32e0
|
https://github.com/smallnest/goreq/blob/2e3372c80388e4b95c699c950eb2c9faba6c32e0/goreq.go#L662-L666
|
18,291 |
yosida95/golang-jenkins
|
jenkins.go
|
checkCrumb
|
func (jenkins *Jenkins) checkCrumb(req *http.Request) (*http.Request, error) {
// api - store jenkins api useCrumbs response
api := struct {
UseCrumbs bool `json:"useCrumbs"`
}{}
err := jenkins.get("/api/json", url.Values{"tree": []string{"useCrumbs"}}, &api)
if err != nil {
return req, err
}
if !api.UseCrumbs {
// CSRF Protection is not enabled
return req, nil
}
// get crumb field and value
crumb := struct {
Crumb string `json:"crumb"`
CrumbRequestField string `json:"crumbRequestField"`
}{}
err = jenkins.get("/crumbIssuer", nil, &crumb)
if err != nil {
return req, err
}
// update header
req.Header.Set(crumb.CrumbRequestField, crumb.Crumb)
return req, nil
}
|
go
|
func (jenkins *Jenkins) checkCrumb(req *http.Request) (*http.Request, error) {
// api - store jenkins api useCrumbs response
api := struct {
UseCrumbs bool `json:"useCrumbs"`
}{}
err := jenkins.get("/api/json", url.Values{"tree": []string{"useCrumbs"}}, &api)
if err != nil {
return req, err
}
if !api.UseCrumbs {
// CSRF Protection is not enabled
return req, nil
}
// get crumb field and value
crumb := struct {
Crumb string `json:"crumb"`
CrumbRequestField string `json:"crumbRequestField"`
}{}
err = jenkins.get("/crumbIssuer", nil, &crumb)
if err != nil {
return req, err
}
// update header
req.Header.Set(crumb.CrumbRequestField, crumb.Crumb)
return req, nil
}
|
[
"func",
"(",
"jenkins",
"*",
"Jenkins",
")",
"checkCrumb",
"(",
"req",
"*",
"http",
".",
"Request",
")",
"(",
"*",
"http",
".",
"Request",
",",
"error",
")",
"{",
"// api - store jenkins api useCrumbs response",
"api",
":=",
"struct",
"{",
"UseCrumbs",
"bool",
"`json:\"useCrumbs\"`",
"\n",
"}",
"{",
"}",
"\n\n",
"err",
":=",
"jenkins",
".",
"get",
"(",
"\"",
"\"",
",",
"url",
".",
"Values",
"{",
"\"",
"\"",
":",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
"}",
",",
"&",
"api",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"req",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"!",
"api",
".",
"UseCrumbs",
"{",
"// CSRF Protection is not enabled",
"return",
"req",
",",
"nil",
"\n",
"}",
"\n\n",
"// get crumb field and value",
"crumb",
":=",
"struct",
"{",
"Crumb",
"string",
"`json:\"crumb\"`",
"\n",
"CrumbRequestField",
"string",
"`json:\"crumbRequestField\"`",
"\n",
"}",
"{",
"}",
"\n\n",
"err",
"=",
"jenkins",
".",
"get",
"(",
"\"",
"\"",
",",
"nil",
",",
"&",
"crumb",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"req",
",",
"err",
"\n",
"}",
"\n\n",
"// update header",
"req",
".",
"Header",
".",
"Set",
"(",
"crumb",
".",
"CrumbRequestField",
",",
"crumb",
".",
"Crumb",
")",
"\n\n",
"return",
"req",
",",
"nil",
"\n",
"}"
] |
// checkCrumb - checks if `useCrumb` is enabled and if so, retrieves crumb field and value and updates request header
|
[
"checkCrumb",
"-",
"checks",
"if",
"useCrumb",
"is",
"enabled",
"and",
"if",
"so",
"retrieves",
"crumb",
"field",
"and",
"value",
"and",
"updates",
"request",
"header"
] |
4772716c47ca769dea7f92bc28dc607eeb16d8a8
|
https://github.com/yosida95/golang-jenkins/blob/4772716c47ca769dea7f92bc28dc607eeb16d8a8/jenkins.go#L52-L84
|
18,292 |
yosida95/golang-jenkins
|
jenkins.go
|
GetJobs
|
func (jenkins *Jenkins) GetJobs() ([]Job, error) {
var payload = struct {
Jobs []Job `json:"jobs"`
}{}
err := jenkins.get("", nil, &payload)
return payload.Jobs, err
}
|
go
|
func (jenkins *Jenkins) GetJobs() ([]Job, error) {
var payload = struct {
Jobs []Job `json:"jobs"`
}{}
err := jenkins.get("", nil, &payload)
return payload.Jobs, err
}
|
[
"func",
"(",
"jenkins",
"*",
"Jenkins",
")",
"GetJobs",
"(",
")",
"(",
"[",
"]",
"Job",
",",
"error",
")",
"{",
"var",
"payload",
"=",
"struct",
"{",
"Jobs",
"[",
"]",
"Job",
"`json:\"jobs\"`",
"\n",
"}",
"{",
"}",
"\n",
"err",
":=",
"jenkins",
".",
"get",
"(",
"\"",
"\"",
",",
"nil",
",",
"&",
"payload",
")",
"\n",
"return",
"payload",
".",
"Jobs",
",",
"err",
"\n",
"}"
] |
// GetJobs returns all jobs you can read.
|
[
"GetJobs",
"returns",
"all",
"jobs",
"you",
"can",
"read",
"."
] |
4772716c47ca769dea7f92bc28dc607eeb16d8a8
|
https://github.com/yosida95/golang-jenkins/blob/4772716c47ca769dea7f92bc28dc607eeb16d8a8/jenkins.go#L203-L209
|
18,293 |
yosida95/golang-jenkins
|
jenkins.go
|
GetJob
|
func (jenkins *Jenkins) GetJob(name string) (job Job, err error) {
err = jenkins.get(fmt.Sprintf("/job/%s", name), nil, &job)
return
}
|
go
|
func (jenkins *Jenkins) GetJob(name string) (job Job, err error) {
err = jenkins.get(fmt.Sprintf("/job/%s", name), nil, &job)
return
}
|
[
"func",
"(",
"jenkins",
"*",
"Jenkins",
")",
"GetJob",
"(",
"name",
"string",
")",
"(",
"job",
"Job",
",",
"err",
"error",
")",
"{",
"err",
"=",
"jenkins",
".",
"get",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"name",
")",
",",
"nil",
",",
"&",
"job",
")",
"\n",
"return",
"\n",
"}"
] |
// GetJob returns a job which has specified name.
|
[
"GetJob",
"returns",
"a",
"job",
"which",
"has",
"specified",
"name",
"."
] |
4772716c47ca769dea7f92bc28dc607eeb16d8a8
|
https://github.com/yosida95/golang-jenkins/blob/4772716c47ca769dea7f92bc28dc607eeb16d8a8/jenkins.go#L212-L215
|
18,294 |
yosida95/golang-jenkins
|
jenkins.go
|
GetJobConfig
|
func (jenkins *Jenkins) GetJobConfig(name string) (job MavenJobItem, err error) {
err = jenkins.getXml(fmt.Sprintf("/job/%s/config.xml", name), nil, &job)
return
}
|
go
|
func (jenkins *Jenkins) GetJobConfig(name string) (job MavenJobItem, err error) {
err = jenkins.getXml(fmt.Sprintf("/job/%s/config.xml", name), nil, &job)
return
}
|
[
"func",
"(",
"jenkins",
"*",
"Jenkins",
")",
"GetJobConfig",
"(",
"name",
"string",
")",
"(",
"job",
"MavenJobItem",
",",
"err",
"error",
")",
"{",
"err",
"=",
"jenkins",
".",
"getXml",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"name",
")",
",",
"nil",
",",
"&",
"job",
")",
"\n",
"return",
"\n",
"}"
] |
//GetJobConfig returns a maven job, has the one used to create Maven job
|
[
"GetJobConfig",
"returns",
"a",
"maven",
"job",
"has",
"the",
"one",
"used",
"to",
"create",
"Maven",
"job"
] |
4772716c47ca769dea7f92bc28dc607eeb16d8a8
|
https://github.com/yosida95/golang-jenkins/blob/4772716c47ca769dea7f92bc28dc607eeb16d8a8/jenkins.go#L218-L221
|
18,295 |
yosida95/golang-jenkins
|
jenkins.go
|
GetBuild
|
func (jenkins *Jenkins) GetBuild(job Job, number int) (build Build, err error) {
err = jenkins.get(fmt.Sprintf("/job/%s/%d", job.Name, number), nil, &build)
return
}
|
go
|
func (jenkins *Jenkins) GetBuild(job Job, number int) (build Build, err error) {
err = jenkins.get(fmt.Sprintf("/job/%s/%d", job.Name, number), nil, &build)
return
}
|
[
"func",
"(",
"jenkins",
"*",
"Jenkins",
")",
"GetBuild",
"(",
"job",
"Job",
",",
"number",
"int",
")",
"(",
"build",
"Build",
",",
"err",
"error",
")",
"{",
"err",
"=",
"jenkins",
".",
"get",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"job",
".",
"Name",
",",
"number",
")",
",",
"nil",
",",
"&",
"build",
")",
"\n",
"return",
"\n",
"}"
] |
// GetBuild returns a number-th build result of specified job.
|
[
"GetBuild",
"returns",
"a",
"number",
"-",
"th",
"build",
"result",
"of",
"specified",
"job",
"."
] |
4772716c47ca769dea7f92bc28dc607eeb16d8a8
|
https://github.com/yosida95/golang-jenkins/blob/4772716c47ca769dea7f92bc28dc607eeb16d8a8/jenkins.go#L224-L227
|
18,296 |
yosida95/golang-jenkins
|
jenkins.go
|
GetLastBuild
|
func (jenkins *Jenkins) GetLastBuild(job Job) (build Build, err error) {
err = jenkins.get(fmt.Sprintf("/job/%s/lastBuild", job.Name), nil, &build)
return
}
|
go
|
func (jenkins *Jenkins) GetLastBuild(job Job) (build Build, err error) {
err = jenkins.get(fmt.Sprintf("/job/%s/lastBuild", job.Name), nil, &build)
return
}
|
[
"func",
"(",
"jenkins",
"*",
"Jenkins",
")",
"GetLastBuild",
"(",
"job",
"Job",
")",
"(",
"build",
"Build",
",",
"err",
"error",
")",
"{",
"err",
"=",
"jenkins",
".",
"get",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"job",
".",
"Name",
")",
",",
"nil",
",",
"&",
"build",
")",
"\n",
"return",
"\n",
"}"
] |
// GetLastBuild returns the last build of specified job.
|
[
"GetLastBuild",
"returns",
"the",
"last",
"build",
"of",
"specified",
"job",
"."
] |
4772716c47ca769dea7f92bc28dc607eeb16d8a8
|
https://github.com/yosida95/golang-jenkins/blob/4772716c47ca769dea7f92bc28dc607eeb16d8a8/jenkins.go#L230-L233
|
18,297 |
yosida95/golang-jenkins
|
jenkins.go
|
CreateJob
|
func (jenkins *Jenkins) CreateJob(mavenJobItem MavenJobItem, jobName string) error {
mavenJobItemXml, _ := xml.Marshal(mavenJobItem)
reader := bytes.NewReader(mavenJobItemXml)
params := url.Values{"name": []string{jobName}}
return jenkins.postXml("/createItem", params, reader, nil)
}
|
go
|
func (jenkins *Jenkins) CreateJob(mavenJobItem MavenJobItem, jobName string) error {
mavenJobItemXml, _ := xml.Marshal(mavenJobItem)
reader := bytes.NewReader(mavenJobItemXml)
params := url.Values{"name": []string{jobName}}
return jenkins.postXml("/createItem", params, reader, nil)
}
|
[
"func",
"(",
"jenkins",
"*",
"Jenkins",
")",
"CreateJob",
"(",
"mavenJobItem",
"MavenJobItem",
",",
"jobName",
"string",
")",
"error",
"{",
"mavenJobItemXml",
",",
"_",
":=",
"xml",
".",
"Marshal",
"(",
"mavenJobItem",
")",
"\n",
"reader",
":=",
"bytes",
".",
"NewReader",
"(",
"mavenJobItemXml",
")",
"\n",
"params",
":=",
"url",
".",
"Values",
"{",
"\"",
"\"",
":",
"[",
"]",
"string",
"{",
"jobName",
"}",
"}",
"\n\n",
"return",
"jenkins",
".",
"postXml",
"(",
"\"",
"\"",
",",
"params",
",",
"reader",
",",
"nil",
")",
"\n",
"}"
] |
// Create a new job
|
[
"Create",
"a",
"new",
"job"
] |
4772716c47ca769dea7f92bc28dc607eeb16d8a8
|
https://github.com/yosida95/golang-jenkins/blob/4772716c47ca769dea7f92bc28dc607eeb16d8a8/jenkins.go#L236-L242
|
18,298 |
yosida95/golang-jenkins
|
jenkins.go
|
DeleteJob
|
func (jenkins *Jenkins) DeleteJob(job Job) error {
return jenkins.post(fmt.Sprintf("/job/%s/doDelete", job.Name), nil, nil)
}
|
go
|
func (jenkins *Jenkins) DeleteJob(job Job) error {
return jenkins.post(fmt.Sprintf("/job/%s/doDelete", job.Name), nil, nil)
}
|
[
"func",
"(",
"jenkins",
"*",
"Jenkins",
")",
"DeleteJob",
"(",
"job",
"Job",
")",
"error",
"{",
"return",
"jenkins",
".",
"post",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"job",
".",
"Name",
")",
",",
"nil",
",",
"nil",
")",
"\n",
"}"
] |
// Delete a job
|
[
"Delete",
"a",
"job"
] |
4772716c47ca769dea7f92bc28dc607eeb16d8a8
|
https://github.com/yosida95/golang-jenkins/blob/4772716c47ca769dea7f92bc28dc607eeb16d8a8/jenkins.go#L245-L247
|
18,299 |
yosida95/golang-jenkins
|
jenkins.go
|
AddJobToView
|
func (jenkins *Jenkins) AddJobToView(viewName string, job Job) error {
params := url.Values{"name": []string{job.Name}}
return jenkins.post(fmt.Sprintf("/view/%s/addJobToView", viewName), params, nil)
}
|
go
|
func (jenkins *Jenkins) AddJobToView(viewName string, job Job) error {
params := url.Values{"name": []string{job.Name}}
return jenkins.post(fmt.Sprintf("/view/%s/addJobToView", viewName), params, nil)
}
|
[
"func",
"(",
"jenkins",
"*",
"Jenkins",
")",
"AddJobToView",
"(",
"viewName",
"string",
",",
"job",
"Job",
")",
"error",
"{",
"params",
":=",
"url",
".",
"Values",
"{",
"\"",
"\"",
":",
"[",
"]",
"string",
"{",
"job",
".",
"Name",
"}",
"}",
"\n",
"return",
"jenkins",
".",
"post",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"viewName",
")",
",",
"params",
",",
"nil",
")",
"\n",
"}"
] |
// Add job to view
|
[
"Add",
"job",
"to",
"view"
] |
4772716c47ca769dea7f92bc28dc607eeb16d8a8
|
https://github.com/yosida95/golang-jenkins/blob/4772716c47ca769dea7f92bc28dc607eeb16d8a8/jenkins.go#L250-L253
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.